Expose certifications and per-country release dates
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
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
TMDb's release_dates/content_ratings blocks were already fetched via append_to_response but discarded at normalization -- every downstream layer (ingestion write, repository read, schema, service) was unbuilt. Adds the full pipeline: NormalizedReleaseDate + get_or_create_certification, a shared polymorphic sync/read (movie and series both use it), and MovieDetailOut/SeriesDetailOut certification + release_dates fields. Series content_ratings has no date of its own, so each rating is anchored to the show's first_air_date with release_type="tv". Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
340cadd99d
commit
e1a36ce227
@@ -89,6 +89,39 @@ FAKE_MOVIE = {
|
||||
"alternative_titles": {"titles": [{"title": "Matrix", "iso_3166_1": "US"}]},
|
||||
"external_ids": {"imdb_id": "tt0133093"},
|
||||
"recommendations": {"results": [{"id": 604}]},
|
||||
"release_dates": {
|
||||
"results": [
|
||||
{
|
||||
"iso_3166_1": "US",
|
||||
"release_dates": [
|
||||
{
|
||||
"certification": "R",
|
||||
"release_date": "1999-03-31T00:00:00.000Z",
|
||||
"type": 3,
|
||||
"note": "",
|
||||
},
|
||||
{
|
||||
"certification": "",
|
||||
"release_date": "1999-03-01T00:00:00.000Z",
|
||||
"type": 1,
|
||||
"note": "Premiere",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"iso_3166_1": "GB",
|
||||
"release_dates": [
|
||||
{"certification": "15", "release_date": "1999-06-11T00:00:00.000Z", "type": 3}
|
||||
],
|
||||
},
|
||||
{
|
||||
"iso_3166_1": "MX",
|
||||
"release_dates": [
|
||||
{"certification": "B", "release_date": "1999-04-02T00:00:00.000Z", "type": 3}
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
FAKE_PERSON = {
|
||||
@@ -192,6 +225,40 @@ def test_normalize_movie_maps_collection_and_recommendations():
|
||||
assert movie.recommendation_external_ids == ["604"]
|
||||
|
||||
|
||||
def test_normalize_movie_maps_release_dates_and_certification():
|
||||
movie = normalize_movie(FAKE_MOVIE)
|
||||
assert len(movie.release_dates) == 4
|
||||
|
||||
us_theatrical = next(
|
||||
rd for rd in movie.release_dates if rd.country_code == "US" and rd.release_type == "theatrical"
|
||||
)
|
||||
assert us_theatrical.release_date == date(1999, 3, 31)
|
||||
assert us_theatrical.certification == ("MPA", "R")
|
||||
|
||||
us_premiere = next(rd for rd in movie.release_dates if rd.release_type == "premiere")
|
||||
assert us_premiere.certification is None
|
||||
assert us_premiere.note == "Premiere"
|
||||
|
||||
gb_entry = next(rd for rd in movie.release_dates if rd.country_code == "GB")
|
||||
assert gb_entry.certification == ("BBFC", "15")
|
||||
|
||||
mx_entry = next(rd for rd in movie.release_dates if rd.country_code == "MX")
|
||||
# MX has no entry in the small known certification-system map -- falls
|
||||
# back to the country code itself rather than fabricating a body name.
|
||||
assert mx_entry.certification == ("MX", "B")
|
||||
|
||||
|
||||
def test_normalize_movie_release_dates_skip_entries_without_a_date():
|
||||
minimal = {
|
||||
**FAKE_MOVIE,
|
||||
"release_dates": {
|
||||
"results": [{"iso_3166_1": "US", "release_dates": [{"certification": "R", "release_date": ""}]}]
|
||||
},
|
||||
}
|
||||
movie = normalize_movie(minimal)
|
||||
assert movie.release_dates == []
|
||||
|
||||
|
||||
def test_normalize_movie_handles_missing_optional_sections():
|
||||
minimal = {"id": 1, "title": "Minimal Movie"}
|
||||
movie = normalize_movie(minimal)
|
||||
@@ -264,6 +331,9 @@ FAKE_SERIES = {
|
||||
"keywords": {"results": [{"id": 1, "name": "drug dealer"}]},
|
||||
"alternative_titles": {"results": [{"title": "Breaking Bad", "iso_3166_1": "US"}]},
|
||||
"external_ids": {"imdb_id": "tt0903747", "tvdb_id": 81189},
|
||||
"content_ratings": {
|
||||
"results": [{"iso_3166_1": "US", "rating": "TV-MA"}, {"iso_3166_1": "GB", "rating": "15"}]
|
||||
},
|
||||
"seasons": [
|
||||
{
|
||||
"season_number": 1,
|
||||
@@ -376,6 +446,24 @@ def test_normalize_series_external_ids_include_tvdb():
|
||||
assert series.external_ids["tvdb"] == "81189"
|
||||
|
||||
|
||||
def test_normalize_series_anchors_content_ratings_to_first_air_date():
|
||||
# TMDb's /tv content_ratings carries no date of its own -- each rating
|
||||
# is anchored to the show's first_air_date (release_type="tv") rather
|
||||
# than left with no release_date at all.
|
||||
series = normalize_series(FAKE_SERIES)
|
||||
assert len(series.release_dates) == 2
|
||||
us = next(rd for rd in series.release_dates if rd.country_code == "US")
|
||||
assert us.release_date == date(2008, 1, 20)
|
||||
assert us.release_type == "tv"
|
||||
assert us.certification == ("MPA", "TV-MA")
|
||||
|
||||
|
||||
def test_normalize_series_content_ratings_skipped_without_first_air_date():
|
||||
no_air_date = {**FAKE_SERIES, "first_air_date": None}
|
||||
series = normalize_series(no_air_date)
|
||||
assert series.release_dates == []
|
||||
|
||||
|
||||
def test_normalize_season_maps_episodes():
|
||||
season = normalize_season(FAKE_SEASON)
|
||||
assert season.season_number == 1
|
||||
|
||||
Reference in New Issue
Block a user