Files
Aurora-Core/tests/integration/test_company_browse.py
T
NixReaperandClaude Sonnet 5 92b0f4e077
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Add GET /companies browse/discover endpoint
Completes the browse/discover set across all four entity types.
Companies have no popularity or date field, so unlike movies/series/
people there's no sort_by choice -- always alphabetical by name.
Filters are company_type (validated against the enum) and country
(a plain ISO 3166-1 code comparison, nothing to validate).

build_company_summary refactored to share row-to-summary logic with
the new list path, same pattern used for movies/series/people.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-05 19:08:14 -05:00

115 lines
3.9 KiB
Python

"""Integration tests for GET /api/v1/companies (browse/discover, section 17
-- additive beyond the spec's minimum endpoint list): filtering and
pagination against real PostgreSQL, exercised through
company_service.list_companies directly. Mirrors test_movie_browse.py;
companies have no popularity/date field, so unlike movies/series/people
there's no sort_by choice -- always alphabetical by name."""
from __future__ import annotations
import pytest
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.enums import CompanyType
from app.repositories.provider_repository import get_or_create_provider
from app.repositories.reference_repository import get_or_create_company
from app.services import company_service
_COMPANIES = [
("2001", "Zeta Studios", CompanyType.PRODUCTION_COMPANY, "US"),
("2002", "Alpha Network", CompanyType.NETWORK, "US"),
("2003", "Mid Distributors", CompanyType.DISTRIBUTOR, "GB"),
("2004", "Beta Pictures", CompanyType.PRODUCTION_COMPANY, "GB"),
]
async def _seed_companies(db_session: AsyncSession) -> None:
provider = await get_or_create_provider(db_session, "tmdb", "TMDB")
for external_id, name, company_type, country in _COMPANIES:
await get_or_create_company(
db_session,
provider_id=provider.id,
external_id=external_id,
name=name,
company_type=company_type,
country_code=country,
)
await db_session.commit()
@pytest.mark.asyncio
async def test_list_companies_defaults_to_alphabetical_by_name(db_session: AsyncSession):
await _seed_companies(db_session)
out = await company_service.list_companies(
db_session, company_type=None, country=None, page=1, page_size=20
)
assert out.total_results == 4
assert [c.name for c in out.results] == [
"Alpha Network",
"Beta Pictures",
"Mid Distributors",
"Zeta Studios",
]
@pytest.mark.asyncio
async def test_list_companies_filters_by_company_type(db_session: AsyncSession):
await _seed_companies(db_session)
out = await company_service.list_companies(
db_session, company_type="production_company", country=None, page=1, page_size=20
)
assert [c.name for c in out.results] == ["Beta Pictures", "Zeta Studios"]
@pytest.mark.asyncio
async def test_list_companies_filters_by_country(db_session: AsyncSession):
await _seed_companies(db_session)
out = await company_service.list_companies(
db_session, company_type=None, country="GB", page=1, page_size=20
)
assert [c.name for c in out.results] == ["Beta Pictures", "Mid Distributors"]
@pytest.mark.asyncio
async def test_list_companies_paginates(db_session: AsyncSession):
await _seed_companies(db_session)
page1 = await company_service.list_companies(
db_session, company_type=None, country=None, page=1, page_size=2
)
page2 = await company_service.list_companies(
db_session, company_type=None, country=None, page=2, page_size=2
)
assert page1.total_results == 4
assert page1.total_pages == 2
assert [c.name for c in page1.results] == ["Alpha Network", "Beta Pictures"]
assert [c.name for c in page2.results] == ["Mid Distributors", "Zeta Studios"]
@pytest.mark.asyncio
async def test_list_companies_rejects_unknown_company_type(db_session: AsyncSession):
with pytest.raises(company_service.InvalidCompanyFilterError):
await company_service.list_companies(
db_session, company_type="not_a_real_type", country=None, page=1, page_size=20
)
@pytest.mark.asyncio
async def test_list_companies_returns_empty_page_when_nothing_matches(db_session: AsyncSession):
await _seed_companies(db_session)
out = await company_service.list_companies(
db_session, company_type=None, country="ZZ", page=1, page_size=20
)
assert out.results == []
assert out.total_results == 0
assert out.total_pages == 0