Files
Aurora-Core/tests/integration/test_genre_browse.py
T
NixReaperandClaude Sonnet 5 340cadd99d
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 /genres directory endpoint
GET /movies and GET /series accept a genre filter (an Aurora genre id),
but nothing exposed what those ids actually are -- genres otherwise
only ever appear embedded in a movie/series response's own genres
list. This is the resolve-by-name-first-then-filter step the frontend
needs to build real genre browsing.

No filter, no sort_by -- always alphabetical by name, same pattern as
collections/companies (genres have no categorical field or popularity/
date to sort by). page_size defaults to 50 (max 200) rather than the
20/50 used elsewhere, since genres are a small, fixed reference set
(TMDb has ~19-20 total) a client typically wants in full for a filter
dropdown, not paginated like a catalog of millions of movies.

Also fixed two stale "behind Traefik" mentions in app/main.py's module
docstring while touching this file, left over from the earlier
cPanel/host-webserver deployment change.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-06 00:05:10 -05:00

62 lines
2.0 KiB
Python

"""Integration tests for GET /api/v1/genres (section 17, additive): a
directory for the `genre` filter GET /movies and GET /series already
accept, which takes an Aurora genre id with no prior way to discover what
those ids are. Mirrors test_collection_browse.py; genres 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.reference_repository import get_or_create_genre
from app.services import genre_service
_GENRES = ["Zeta Fiction", "Alpha Comedy", "Mid Drama", "Beta Horror"]
async def _seed_genres(db_session: AsyncSession) -> None:
for name in _GENRES:
await get_or_create_genre(db_session, name)
await db_session.commit()
@pytest.mark.asyncio
async def test_list_genres_defaults_to_alphabetical_by_name(db_session: AsyncSession):
await _seed_genres(db_session)
out = await genre_service.list_genres(db_session, page=1, page_size=50)
assert out.total_results == 4
assert out.total_pages == 1
assert [g.name for g in out.results] == [
"Alpha Comedy",
"Beta Horror",
"Mid Drama",
"Zeta Fiction",
]
@pytest.mark.asyncio
async def test_list_genres_paginates(db_session: AsyncSession):
await _seed_genres(db_session)
page1 = await genre_service.list_genres(db_session, page=1, page_size=2)
page2 = await genre_service.list_genres(db_session, page=2, page_size=2)
assert page1.total_results == 4
assert page1.total_pages == 2
assert [g.name for g in page1.results] == ["Alpha Comedy", "Beta Horror"]
assert [g.name for g in page2.results] == ["Mid Drama", "Zeta Fiction"]
@pytest.mark.asyncio
async def test_list_genres_returns_empty_page_when_none_exist(db_session: AsyncSession):
out = await genre_service.list_genres(db_session, page=1, page_size=50)
assert out.results == []
assert out.total_results == 0
assert out.total_pages == 0