Files
Aurora-Core/tests/integration/test_collection_browse.py
NixReaperandClaude Sonnet 5 f1ac072794
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 /collections browse endpoint; fix embedded collection poster_path
Completes browse/discover across all five entity types: movies, series,
people, companies, and now collections. No filter (no categorical field
like company_type exists for a collection) -- just page/page_size,
always alphabetical by name.

While adding poster_path to CollectionBriefOut for the browse listing,
found the same class of bug fixed earlier for company logo_path:
movie_service's embedded `collection` field never looked up its poster
artwork either, so it stayed null even after ingest_collection populated
one. Fixed alongside since it's the same schema field this feature was
already touching.

Also removed PageMeta from schemas/common.py -- scaffolding from early
spec work that was never actually wired into any endpoint; all five
browse endpoints shipped this session use a flat page/page_size/
total_results/total_pages shape instead.

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

70 lines
2.4 KiB
Python

"""Integration tests for GET /api/v1/collections (browse/discover, section
17 -- additive beyond the spec's minimum endpoint list): pagination against
real PostgreSQL, exercised through collection_service.list_collections
directly. Mirrors test_company_browse.py; collections have no categorical
field to filter by and no popularity/date field to sort by, so there's no
filter case and always alphabetical-by-name ordering to test."""
from __future__ import annotations
import pytest
from sqlalchemy.ext.asyncio import AsyncSession
from app.repositories.provider_repository import get_or_create_provider
from app.repositories.reference_repository import get_or_create_collection
from app.services import collection_service
_COLLECTIONS = [
("3001", "Zeta Trilogy"),
("3002", "Alpha Saga"),
("3003", "Mid Collection"),
("3004", "Beta Universe"),
]
async def _seed_collections(db_session: AsyncSession) -> None:
provider = await get_or_create_provider(db_session, "tmdb", "TMDB")
for external_id, name in _COLLECTIONS:
await get_or_create_collection(
db_session, provider_id=provider.id, external_id=external_id, name=name
)
await db_session.commit()
@pytest.mark.asyncio
async def test_list_collections_defaults_to_alphabetical_by_name(db_session: AsyncSession):
await _seed_collections(db_session)
out = await collection_service.list_collections(db_session, page=1, page_size=20)
assert out.total_results == 4
assert out.total_pages == 1
assert [c.name for c in out.results] == [
"Alpha Saga",
"Beta Universe",
"Mid Collection",
"Zeta Trilogy",
]
@pytest.mark.asyncio
async def test_list_collections_paginates(db_session: AsyncSession):
await _seed_collections(db_session)
page1 = await collection_service.list_collections(db_session, page=1, page_size=2)
page2 = await collection_service.list_collections(db_session, page=2, page_size=2)
assert page1.total_results == 4
assert page1.total_pages == 2
assert [c.name for c in page1.results] == ["Alpha Saga", "Beta Universe"]
assert [c.name for c in page2.results] == ["Mid Collection", "Zeta Trilogy"]
@pytest.mark.asyncio
async def test_list_collections_returns_empty_page_when_none_exist(db_session: AsyncSession):
out = await collection_service.list_collections(db_session, page=1, page_size=20)
assert out.results == []
assert out.total_results == 0
assert out.total_pages == 0