feat: LinkedIn profile search engine (Django + React + Elasticsearch + ELK)
Full-stack implementation of the Cyberyan full-stack trial task. Backend (Django 5 / DRF) - Normalised PostgreSQL model (Profile, Company, School, Skill, Experience, Education) as the source of truth, with GIN + trigram indexes. - Self-healing CSV reader: the supplied export carries an injected watermark column, missing columns, rows split by broken quoting and a duplicated header. A signature-scored Needleman-Wunsch alignment reconstructs 284 clean records out of 336 physical rows; only 10 rows parse correctly without it. - Pluggable search layer (Strategy): Elasticsearch by default, PostgreSQL full-text search as a fallback selected by a single environment variable. - Keyword search with per-field boosts, fuzziness and phrase boosting, six faceted filters (OR within a filter, AND across filters), an experience range, four sort orders, highlighting and facet aggregations. - JWT auth with rotation + blacklist, three roles, PII masking, scoped rate limits, a single error envelope, OpenAPI schema and health probes. Frontend (React 18 / TypeScript / Vite) - Debounced search with type-ahead, faceted filter panel, result cards, profile drawer, URL-synced search state, automatic token refresh. - Highlight snippets rendered without dangerouslySetInnerHTML. Infrastructure - Hardened multi-stage images (non-root, read-only rootfs, healthchecks). - docker-compose for the full stack plus dev and production overlays. - ELK: structured JSON logs shipped asynchronously to Logstash, routed per event type, with a composable index template and a Kibana setup script. Quality - 61 backend tests (85% coverage), ruff/black/bandit/mypy, ESLint + tsc, GitHub Actions running lint, tests and both image builds. - Persian documentation: README plus architecture, search, API, data, security and operations guides. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GnFo6fNaHCTAkJbfcdkqtG
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
"""Shared pytest fixtures."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from apps.accounts.models import Role, User
|
||||
from apps.profiles.models import Company, Profile, ProfileSkill, Skill
|
||||
|
||||
PASSWORD = "Str0ng-Passw0rd!" # noqa: S105 - test credential only
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_client() -> APIClient:
|
||||
return APIClient()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_user(db): # noqa: ANN001, ANN201
|
||||
def _make(email: str = "user@example.com", role: str = Role.VIEWER, **extra) -> User:
|
||||
return User.objects.create_user(email=email, password=PASSWORD, role=role, **extra)
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def viewer(make_user) -> User: # noqa: ANN001
|
||||
return make_user("viewer@example.com", Role.VIEWER)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def analyst(make_user) -> User: # noqa: ANN001
|
||||
return make_user("analyst@example.com", Role.ANALYST)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_user(make_user) -> User: # noqa: ANN001
|
||||
return make_user("admin@example.com", Role.ADMIN, is_staff=True, is_superuser=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_client(api_client): # noqa: ANN001, ANN201
|
||||
def _login(user: User) -> APIClient:
|
||||
api_client.force_authenticate(user=user)
|
||||
return api_client
|
||||
|
||||
return _login
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_profiles(db) -> list[Profile]: # noqa: ANN001
|
||||
"""Three profiles with enough variety to exercise every filter."""
|
||||
from apps.profiles.importers import ProfileImporter
|
||||
|
||||
acme = Company.objects.create(name="acme corp", industry="software", size="51-200")
|
||||
globex = Company.objects.create(name="globex", industry="banking", size="1001-5000")
|
||||
|
||||
people = [
|
||||
{
|
||||
"full_name": "sara python",
|
||||
"job_title": "senior backend engineer",
|
||||
"job_title_role": "engineering",
|
||||
"seniority_levels": ["senior"],
|
||||
"current_company": acme,
|
||||
"industry": "software",
|
||||
"location_country": "germany",
|
||||
"location_name": "berlin, germany",
|
||||
"years_experience": 9,
|
||||
"summary": "Builds distributed systems with django and postgres.",
|
||||
"skills": ["python", "django", "postgresql"],
|
||||
},
|
||||
{
|
||||
"full_name": "john recruiter",
|
||||
"job_title": "recruiting manager",
|
||||
"job_title_role": "human_resources",
|
||||
"seniority_levels": ["manager"],
|
||||
"current_company": globex,
|
||||
"industry": "banking",
|
||||
"location_country": "united states",
|
||||
"location_name": "denton, texas, united states",
|
||||
"years_experience": 12,
|
||||
"summary": "Talent acquisition and employer branding.",
|
||||
"skills": ["recruiting", "hiring", "leadership"],
|
||||
},
|
||||
{
|
||||
"full_name": "maria frontend",
|
||||
"job_title": "frontend developer",
|
||||
"job_title_role": "engineering",
|
||||
"seniority_levels": [],
|
||||
"current_company": acme,
|
||||
"industry": "software",
|
||||
"location_country": "spain",
|
||||
"location_name": "madrid, spain",
|
||||
"years_experience": 3,
|
||||
"summary": "React and typescript specialist.",
|
||||
"skills": ["react", "typescript", "javascript"],
|
||||
},
|
||||
]
|
||||
|
||||
created: list[Profile] = []
|
||||
for index, payload in enumerate(people, start=1):
|
||||
skills = payload.pop("skills")
|
||||
profile = Profile.objects.create(
|
||||
external_id=str(1000 + index),
|
||||
linkedin_url=f"linkedin.com/in/person-{index}",
|
||||
skills_text=" ".join(skills),
|
||||
companies_text=payload["current_company"].name,
|
||||
**payload,
|
||||
)
|
||||
for position, name in enumerate(skills):
|
||||
skill, _ = Skill.objects.get_or_create(
|
||||
slug=Skill.make_slug(name), defaults={"name": name}
|
||||
)
|
||||
ProfileSkill.objects.create(profile=profile, skill=skill, position=position)
|
||||
created.append(profile)
|
||||
|
||||
ProfileImporter._refresh_skill_counters()
|
||||
ProfileImporter._refresh_search_vectors()
|
||||
return created
|
||||
Reference in New Issue
Block a user