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
/people/{id}/credits only ever looked at entity_type == "movie",
silently dropping the series-level cast/crew and episode-level
guest-star Credit rows that series_ingestion.py has been writing all
along -- a person ingested via a TV show would show an empty or
movie-only filmography no matter how much TV work was actually in the
database.
Regular series credits map straight to a filmography row, same shape
as movies. Guest-star episode credits are aggregated to one row per
(series, department/job/character) with an episode_count, rather than
one row per episode -- a prolific guest actor would otherwise flood
the list with dozens of near-identical entries. Added
tv_repository.get_series_by_ids/get_episodes_by_ids (bulk, mirroring
the existing movie_repository pattern) to support it.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
"""Integration tests for person filmography assembly
|
|
(app/services/person_service.py:get_person_credits) — movies, regular
|
|
series roles, and guest-star episode credits aggregated per series."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
import pytest
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.ids import aurora_id
|
|
from app.models.credit import Credit
|
|
from app.models.movie import Movie
|
|
from app.models.person import Person
|
|
from app.models.tv import Episode, Season, Series
|
|
from app.services.person_service import get_person_credits
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_person_credits_include_movies_series_and_aggregated_guest_spots(
|
|
db_session: AsyncSession,
|
|
):
|
|
person = Person(name="Guest Actor")
|
|
db_session.add(person)
|
|
await db_session.flush()
|
|
|
|
movie = Movie(title="A Movie", sort_title="Movie", primary_release_date=date(2020, 1, 1))
|
|
db_session.add(movie)
|
|
await db_session.flush()
|
|
db_session.add(
|
|
Credit(
|
|
person_id=person.id,
|
|
entity_type="movie",
|
|
entity_id=movie.id,
|
|
department="Acting",
|
|
character="Hero",
|
|
)
|
|
)
|
|
|
|
series = Series(
|
|
title="A Series", sort_title="Series", first_air_date=date(2019, 5, 1)
|
|
)
|
|
db_session.add(series)
|
|
await db_session.flush()
|
|
db_session.add(
|
|
Credit(
|
|
person_id=person.id,
|
|
entity_type="series",
|
|
entity_id=series.id,
|
|
department="Acting",
|
|
character="Regular Character",
|
|
)
|
|
)
|
|
|
|
season = Season(series_id=series.id, season_number=1)
|
|
db_session.add(season)
|
|
await db_session.flush()
|
|
|
|
episode1 = Episode(
|
|
series_id=series.id, season_id=season.id, season_number=1, episode_number=1
|
|
)
|
|
episode2 = Episode(
|
|
series_id=series.id, season_id=season.id, season_number=1, episode_number=2
|
|
)
|
|
db_session.add_all([episode1, episode2])
|
|
await db_session.flush()
|
|
|
|
for episode in (episode1, episode2):
|
|
db_session.add(
|
|
Credit(
|
|
person_id=person.id,
|
|
entity_type="episode",
|
|
entity_id=episode.id,
|
|
department="Acting",
|
|
character="Guest Character",
|
|
is_guest=True,
|
|
)
|
|
)
|
|
await db_session.commit()
|
|
|
|
credits_out = await get_person_credits(db_session, aurora_id("person", str(person.id)))
|
|
|
|
titles = {c.title for c in credits_out.cast}
|
|
assert titles == {"A Movie", "A Series"}
|
|
|
|
movie_credit = next(c for c in credits_out.cast if c.media_type == "movie")
|
|
assert movie_credit.character == "Hero"
|
|
assert movie_credit.episode_count is None
|
|
|
|
# Both the regular-cast series credit and the two guest-star episode
|
|
# credits point at the same series, but must NOT collapse into one
|
|
# entry -- they have different characters/roles.
|
|
series_entries = [c for c in credits_out.cast if c.media_type == "series"]
|
|
assert len(series_entries) == 2
|
|
|
|
regular = next(c for c in series_entries if c.character == "Regular Character")
|
|
assert regular.episode_count is None
|
|
|
|
guest = next(c for c in series_entries if c.character == "Guest Character")
|
|
assert guest.episode_count == 2
|