"""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