Tests Module¶
Contracts¶
Shared fixtures and configuration for Pact consumer-driven contract tests.
Centralizes the Pact mock-server settings and the per-test pact /
pact_movies_api / pact_address fixtures so each contract module only
declares its interactions. Test classes set a consumer_name class
attribute naming the consumer side of the contract; the provider is shared.
- tests.contracts.conftest.pact()[source]¶
Provide a fresh Pact instance per test and write the contract on teardown.
A new Pact is created per test because once
pact.serve()runs and its context manager exits the handle is finalized, so no further interactions can be added. Consumer and provider are the shared identities above; each test’s interactions merge into the same contract file on write.- Yields:
Configured Pact instance ready for interaction definition. Example yield:
Pact("mdb_api_layer", "api_pvd")
- tests.contracts.conftest.pact_address()[source]¶
Return the
(host, port)the Pact mock server should bind to.- Returns:
A
(host, port)tuple; port0lets the OS pick a free port. Example return:("localhost", 0)
- tests.contracts.conftest.pact_movies_api()[source]¶
Provide a fresh MoviesAPI client for a contract test.
Returns the client with its default (real TMDB) base URL. Each test repoints
base_urlat the Pact mock server afterpact.serve()starts, because the mock server’s URL/port aren’t known until then.- Returns:
A fresh
MoviesAPIclient with its default TMDBbase_url. Example return:MoviesAPI() # base_url="https://api.themoviedb.org" until repointed at the mock
Contract tests for the Movies Details API. Module demonstrates consumer-driven contract (CDC) testing.
Contract tests for popular Movies API using Pact.
Data¶
- tests.data.data_loader.load_test_data(file_name: str, section: str | None = None) dict[source]¶
Load test data from a YAML file and apply default values.
Reads a YAML file from the same directory as this module and applies any defined defaults to test case entries. Also processes dynamic placeholders like ‘$random_rating’ by calling the mapped generator functions.
When
sectionis given, only that top-level section is kept (plus the globaldefaults) before defaults and generators are applied, so the generators of unrelated sections (e.g. the disk-reading$random_movie_id) are never executed. The return shape is unchanged —data[section]still works — so callers only add the section name.- Parameters:
file_name – Name of the YAML file containing test data.
section – Optional top-level section to load exclusively (e.g.
'get_movie_details'). IfNone, the whole file is loaded.
- Returns:
Parsed data with defaults merged into each test case and
$placeholdertokens resolved (scoped tosectionif given; thedefaultskeys are consumed, not returned). Example return forload_test_data("test_data.yaml", "get_movie_details"):{ "get_movie_details": { "valid": [ {"movie_id": 27205, "status_code": 200, "reason": "OK", "exp_max_elp_secs": 5, "exp_content_type": "application/json", "exp_get_req_method": "GET"} ], "invalid": [ {"movie_id": 0, "status_code": 404, "reason": "Not Found", "expected_message": "Invalid id: The pre-requisite id is invalid or not found.", "exp_max_elp_secs": 5} ], } }
- Raises:
FileNotFoundError – If the specified file does not exist.
KeyError – If
sectionis given but not present in the file.yaml.YAMLError – If the file contains invalid YAML.
tests/data/test_data.yaml- Test cases for Movies API
defaults:
exp_max_elp_secs: 5 # Applied to ALL valid AND invalid test cases
exp_content_type: 'application/json'
exp_get_req_method: 'GET'
exp_post_req_method: 'POST'
exp_del_req_method: 'DELETE'
exp_put_req_method: 'PUT'
get_movie_details:
defaults:
valid:
status_code: 200 # Only applied to valid cases
reason: 'OK'
invalid:
status_code: 404 # Only applied to invalid cases
reason: 'Not Found'
valid:
- movie_id: "$random_movie_id" # First list item (index 0)
- movie_id: "$random_movie_id" # Second list item (index 1)
- movie_id: "$random_movie_id"
invalid:
- movie_id: 0
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
- movie_id: -1
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
- movie_id: 9999999999
expected_message: "The resource you requested could not be found."
popular_movies:
defaults:
valid:
status_code: 200
reason: 'OK'
exp_page: 1 # client defaults page to 1; cases that send a page override this
invalid:
status_code: 400
reason: 'Bad Request'
valid:
- query_param: { "language": "en-US" }
- query_param: { "page": 2 }
exp_page: 2
invalid:
- query_param: { "page": -1 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
search_movies:
defaults:
valid:
status_code: 200
reason: 'OK'
exp_page: 1 # client defaults page to 1; cases that send a page override this
empty: # Missing/empty/no-match query returns 200 with empty results, not an error
status_code: 200
reason: 'OK'
invalid:
status_code: 400
reason: 'Bad Request'
valid: # One case per supported query param + all combined; page defaults to 1 in the client
# Queries vary per case; the year/primary_release_year cases pair the query
# with that movie's actual release year, and the page-2 case uses a
# franchise with well over one page of matches.
- query_param: { "query": "Superman" }
- query_param: { "query": "Spider-Man", "page": 2 }
exp_page: 2
- query_param: { "query": "Inception", "language": "en-US" }
# include_adult can surface adult-catalog titles, which TMDB returns as sparse
# objects (no genre_ids/popularity/release_date/video/vote_*). The search schema
# tolerates these via SearchMovieListItem (tests/schemas/models.py), but the query
# is still kept clear of them so the case exercises fully-populated movie objects
- query_param: { "query": "Interstellar", "include_adult": "true" }
- query_param: { "query": "Titanic", "region": "US" }
- query_param: { "query": "The Matrix", "year": "1999" }
- query_param: { "query": "Jurassic Park", "primary_release_year": "1993" }
- query_param: { "query": "Terminator", "language": "en-US", "include_adult": "true", "region": "US",
"year": "1984", "primary_release_year": "1984", "page": 1 }
empty:
- query_param: {} # no query at all
- query_param: { "query": "" }
- query_param: { "query": "zzzqqqxyzzy123" } # matches nothing
invalid:
- query_param: { "query": "Avatar", "page": -1 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
- query_param: { "query": "Gladiator", "page": 501 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
discover_movies:
defaults:
valid:
status_code: 200
reason: 'OK'
exp_page: 1 # client defaults page to 1; cases that send a page override this
empty: # Filter combos that match nothing return 200 with empty results, not an error
status_code: 200
reason: 'OK'
invalid:
status_code: 400
reason: 'Bad Request'
valid: # One case per representative filter param + all combined; page defaults to 1 in the client
- query_param: {} # no filters; discover returns results by default
- query_param: { "page": 2 }
exp_page: 2
- query_param: { "language": "en-US" }
- query_param: { "include_adult": "true" }
- query_param: { "include_video": "true" }
- query_param: { "sort_by": "popularity.desc" }
- query_param: { "primary_release_year": "1989" }
- query_param: { "year": "1989" }
- query_param: { "region": "US" }
- query_param: { "with_genres": "28" }
- query_param: { "with_original_language": "en" }
- query_param: { "vote_average.gte": "7" }
- query_param: { "language": "en-US", "include_adult": "true", "include_video": "true",
"sort_by": "popularity.desc", "primary_release_year": "1989", "region": "US",
"with_genres": "28", "with_original_language": "en", "vote_average.gte": "7", "page": 1 }
empty:
- query_param: { "vote_count.gte": "100000000" } # no movie has that many votes
- query_param: { "with_genres": "28", "without_genres": "28" } # self-contradictory filter
invalid:
- query_param: { "page": -1 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
- query_param: { "page": 501 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
trending_movies:
defaults:
valid:
status_code: 200
reason: 'OK'
exp_page: 1 # client defaults page to 1; cases that send a page override this
invalid:
status_code: 400
reason: 'Bad Request'
valid: # time_window is a path segment ('day'/'week'); page defaults to 1 in the client
- time_window: "day"
- time_window: "week"
- time_window: "day"
query_param: { "page": 2 }
exp_page: 2
invalid:
- time_window: "day"
query_param: { "page": -1 }
expected_message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer."
add_rating:
defaults:
valid:
status_code: 201
reason: 'Created'
invalid:
status_code: 400
reason: 'Bad Request'
valid:
- rating_payload: { "value": "$random_rating" }
- rating_payload: { "value": "$random_rating" }
invalid:
- movie_id: "$random_movie_id"
rating_payload: { "value": "$random_invalid_rating" }
expected_message: ['Value too high: Value must be less than, or equal to 10.0.',
'Value too low: Value must be greater than 0.0.',
'Value invalid: Value must be a multiple of 0.50.']
- movie_id: "$random_movie_id"
rating_payload: { "value": "$random_invalid_rating" }
expected_message: ['Value too high: Value must be less than, or equal to 10.0.',
'Value too low: Value must be greater than 0.0.',
'Value invalid: Value must be a multiple of 0.50.']
delete_rating:
defaults:
valid:
status_code: 200
reason: 'OK'
invalid:
status_code: 404
reason: 'Not Found'
valid:
- expected_message: "The item/record was deleted successfully."
invalid:
- movie_id: 9999999999
expected_message: "The resource you requested could not be found."
# An invalid session_id is rejected (401) before the movie id is even looked at
- movie_id: 0
session_id: "$invalid_session_id"
status_code: 401
reason: 'Unauthorized'
expected_message: "Authentication failed: You do not have permissions to access the service."
get_person_details:
defaults:
valid:
status_code: 200
reason: 'OK'
invalid:
status_code: 404
reason: 'Not Found'
valid:
- person_id: "$random_person_id"
invalid:
- person_id: 0
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
- person_id: -1
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
- person_id: 9999999999
expected_message: "The resource you requested could not be found."
get_network_details:
defaults:
valid:
status_code: 200
reason: 'OK'
invalid:
status_code: 404
reason: 'Not Found'
valid:
- network_id: "$random_network_id" # picked from 10 verified well-known networks
invalid:
- network_id: 0
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
- network_id: 99999999
expected_message: "The resource you requested could not be found."
get_review_details:
defaults:
valid:
status_code: 200
reason: 'OK'
invalid:
status_code: 404
reason: 'Not Found'
valid:
- review_id: "$random_review_id" # harvested live from a random movie's reviews
invalid:
- review_id: "0"
expected_message: "The resource you requested could not be found."
- review_id: "deadbeefdeadbeefdeadbeef"
expected_message: "The resource you requested could not be found."
update_list:
defaults:
valid:
exp_max_elp_secs: 15 # Overrides the default 5 seconds
status_code: 201
reason: 'Created'
invalid:
status_code: 404
reason: 'Not Found'
valid:
- list_id: 8637178
payload: { "name": 'French', "description": "$current_timestamp", "public": true }
expected_message: "The item/record was updated successfully."
- list_id: 8637178
payload: { "name": 'Hollywood', "description": "$current_timestamp", "public": true }
expected_message: "The item/record was updated successfully."
invalid:
- list_id: 9999999999
payload: { "name": 'Indian', "description": "$current_timestamp", "public": False }
expected_message: "The resource you requested could not be found."
- list_id: 0
payload: { "name": 'Hollywood', "description": "Some random Description", "public": True }
expected_message: "Invalid id: The pre-requisite id is invalid or not found."
Evals¶
Unit tests for evals.dataset.load_dataset() validation. Covering deterministic logic.
Pure offline tests — no API, no Groq, no GROQ_API_KEY needed. Each case is
written to a temporary YAML file and fed to the loader to exercise its
fail-fast branches (the loader raises ValueError naming the offending case).
- tests.evals.test_dataset.pytestmark = MarkDecorator(mark=Mark(name='unit', args=(), kwargs={}))¶
Mark every test in this module as an offline unit test (not a TMDB API test).
Unit tests for the pure helpers in evals.judge. Covering deterministic logic.
Covers sanitize_diagnosis() and
_output_schema() (plus the two built schema constants).
These are offline, deterministic tests — no Groq call is made, so no
GROQ_API_KEY is required (_call_judge imports groq lazily).
- tests.evals.test_judge.pytestmark = MarkDecorator(mark=Mark(name='unit', args=(), kwargs={}))¶
Mark every test in this module as an offline unit test (not a TMDB API test).
Unit tests for the agentic refine loop in tests.helpers.failure_analyzer.
Covers refine_until_confident(),
_collect_issues(), and
refine(). These are
offline, deterministic tests — the analyzer’s _request_refined_diagnosis (the
refine path’s Groq call) is monkeypatched and the judge is injected as a fake
callable, so no GROQ_API_KEY and no network are required.
- tests.evals.test_failure_refine.analyzer()[source]¶
A force-enabled analyzer whose Groq call is stubbed per test.
- tests.evals.test_failure_refine.pytestmark = MarkDecorator(mark=Mark(name='unit', args=(), kwargs={}))¶
Mark every test in this module as an offline unit test (not a TMDB API test).
Journeys¶
Journey integration test: search a movie, then open its details.
Unlike the single-endpoint suites, this test chains two live TMDB calls the
way a real user (and the perf JourneyUser) does: it searches with
GET /3/search/movie, drills into the top result via GET /3/movie/{id},
and asserts the searched id resolves to the same movie. Each step is still
validated with the shared metadata + Pydantic-schema helpers, so this stays a
thin layer over the existing conventions; its added value is verifying the
contract between the two endpoints.
Seed queries are reused from the search_movies section of ‘test_data.yaml’
(the same known-good set the search suite and perf SEARCH_QUERIES use),
keeping journey, functional and perf coverage single-sourced.
- Usage:
pytest tests/journeys/test_search_to_details.py -v
- tests.journeys.test_search_to_details.DETAILS_DATA = {'get_movie_details': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'movie_id': 0, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'movie_id': -1, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'movie_id': 9999999999, 'reason': 'Not Found', 'status_code': 404}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 44412, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 47245, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 15493, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Helpers¶
Lists¶
- tests.lists.test_update.TEST_DATA = {'update_list': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'list_id': 9999999999, 'payload': {'description': 1788985351, 'name': 'Indian', 'public': False}, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'list_id': 0, 'payload': {'description': 'Some random Description', 'name': 'Hollywood', 'public': True}, 'reason': 'Not Found', 'status_code': 404}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 15, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The item/record was updated successfully.', 'list_id': 8637178, 'payload': {'description': 1788985351, 'name': 'French', 'public': True}, 'reason': 'Created', 'status_code': 201}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 15, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The item/record was updated successfully.', 'list_id': 8637178, 'payload': {'description': 1788985351, 'name': 'Hollywood', 'public': True}, 'reason': 'Created', 'status_code': 201}]}}¶
Module-level test data loaded once at import time for parametrization.
Movie Lists¶
Test suite for the Movies API endpoints.
This module contains integration tests for the MoviesAPI class, validating both successful responses and error handling. Tests are data-driven using external YAML test data files with pytest’s parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid and invalid test cases with expected values and defaults applied.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
MoviesAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/test_popular.py -v
- tests.movie_lists.test_popular.TEST_DATA = {'popular_movies': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': -1}, 'reason': 'Bad Request', 'status_code': 400}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'language': 'en-US'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 2, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'page': 2}, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Pacts¶
{
"consumer": {
"name": "mdb_api_layer"
},
"interactions": [
{
"description": "a request for movie details for movie ID 550",
"pending": false,
"providerStates": [
{
"name": "a movie with ID 550 exists"
}
],
"request": {
"headers": {
"Authorization": [
"Bearer token"
]
},
"matchingRules": {
"header": {
"Authorization": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "GET",
"path": "/3/movie/550"
},
"response": {
"body": {
"content": {
"adult": false,
"genres": [
{
"id": 18,
"name": "Drama"
}
],
"id": 550,
"origin_country": [
"US"
],
"original_language": "en",
"original_title": "Fight Club",
"overview": "A ticking-Loss...",
"popularity": 61.416,
"production_companies": [
{
"id": 508,
"logo_path": "/7PzJdsLGlR7oW4J0J5Xcd0pHGRg.png",
"name": "Regency Enterprises",
"origin_country": "US"
}
],
"release_date": "1999-10-15",
"runtime": 139,
"status": "Released",
"tagline": "Mischief. Mayhem. Soap.",
"title": "Fight Club",
"vote_average": 8.4,
"vote_count": 26280
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"matchingRules": {
"body": {
"$.adult": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.genres": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.genres[*].id": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.genres[*].name": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.id": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.origin_country": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.original_language": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.original_title": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.overview": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.popularity": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.production_companies": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.production_companies[*].id": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.production_companies[*].logo_path": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.production_companies[*].name": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.production_companies[*].origin_country": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.release_date": {
"combine": "AND",
"matchers": [
{
"match": "regex",
"regex": "^\\d{4}-\\d{2}-\\d{2}$"
}
]
},
"$.runtime": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.status": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.tagline": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.title": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.vote_average": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.vote_count": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
},
"status": 200
},
"type": "Synchronous/HTTP"
},
{
"description": "a request for non-existent movie ID 99999999",
"pending": false,
"providerStates": [
{
"name": "movie with ID 99999999 does not exist"
}
],
"request": {
"headers": {
"Authorization": [
"Bearer token"
]
},
"matchingRules": {
"header": {
"Authorization": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "GET",
"path": "/3/movie/99999999"
},
"response": {
"body": {
"content": {
"status_code": 34,
"status_message": "The resource you requested could not be found.",
"success": false
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"matchingRules": {
"body": {
"$.status_code": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.status_message": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.success": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"status": 404
},
"type": "Synchronous/HTTP"
},
{
"description": "a request for popular movies in page 1",
"pending": false,
"providerStates": [
{
"name": "popular movies exist"
}
],
"request": {
"headers": {
"Authorization": [
"Bearer token"
]
},
"matchingRules": {
"header": {
"Authorization": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "GET",
"path": "/3/movie/popular",
"query": {
"page": [
"1"
]
}
},
"response": {
"body": {
"content": {
"page": 1,
"results": [
{
"adult": false,
"backdrop_path": "/path.jpg",
"genre_ids": [
28
],
"id": 123,
"original_language": "en",
"original_title": "Movie Title",
"overview": "Description...",
"popularity": 100.5,
"poster_path": "/poster.jpg",
"release_date": "2024-01-15",
"title": "Movie Title",
"video": false,
"vote_average": 7.5,
"vote_count": 1000
}
],
"total_pages": 500,
"total_results": 10000
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"matchingRules": {
"body": {
"$.page": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.results": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].adult": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].backdrop_path": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].genre_ids": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].id": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.results[*].original_language": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].original_title": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].overview": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].popularity": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].poster_path": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].release_date": {
"combine": "AND",
"matchers": [
{
"match": "regex",
"regex": "^\\d{4}-\\d{2}-\\d{2}$"
}
]
},
"$.results[*].title": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].video": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].vote_average": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.results[*].vote_count": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.total_pages": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.total_results": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
}
}
},
"status": 200
},
"type": "Synchronous/HTTP"
},
{
"description": "a request for popular movies with invalid page",
"pending": false,
"providerStates": [
{
"name": "invalid page parameter"
}
],
"request": {
"headers": {
"Authorization": [
"Bearer token"
]
},
"matchingRules": {
"header": {
"Authorization": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"method": "GET",
"path": "/3/movie/popular",
"query": {
"page": [
"-1"
]
}
},
"response": {
"body": {
"content": {
"status_code": 22,
"status_message": "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.",
"success": false
},
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
]
},
"matchingRules": {
"body": {
"$.status_code": {
"combine": "AND",
"matchers": [
{
"match": "integer"
}
]
},
"$.status_message": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
},
"$.success": {
"combine": "AND",
"matchers": [
{
"match": "type"
}
]
}
}
},
"status": 400
},
"type": "Synchronous/HTTP"
}
],
"metadata": {
"pactRust": {
"ffi": "0.5.4",
"models": "1.3.11"
},
"pactSpecification": {
"version": "4.0"
}
},
"provider": {
"name": "api_pvd"
}
}
Conftest¶
Pytest configuration and shared fixtures for the TMDB API test suite.
This module is automatically loaded by pytest before test collection. It provides:
CLI options:
--loguru-log-level,--log-to-file,--failure-analysis,--judge-diagnosisHooks: Logging setup, AI failure analysis, end-of-run AI diagnosis console summary, Allure/HTML report customization
Fixtures: API client factory, Pydantic schema loader, test data loader
- tests.conftest.discover_api() DiscoverAPI[source]¶
Provide a fresh
DiscoverAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('discover_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for discover endpoints.- Returns:
A configured
DiscoverAPIinstance.
- tests.conftest.lists_api() ListsAPI[source]¶
Provide a fresh
ListsAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('lists_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for list endpoints.- Returns:
A configured
ListsAPIinstance.
- tests.conftest.load_schema()[source]¶
Fixture that provides a Pydantic model loader for response validation.
- Returns:
A callable
_load(name)that maps a registered schema name to its Pydantic model class, raisingValueErrorfor an unknown name. Example use:model = load_schema("movie_schema") # -> <class 'MovieDetails'> model.model_validate(response.data)
- tests.conftest.movies_api() MoviesAPI[source]¶
Provide a fresh
MoviesAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('movies_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for movie endpoints.- Returns:
A configured
MoviesAPIinstance.
- tests.conftest.movies_test_data()[source]¶
Session-scoped fixture that loads movies API test data from YAML.
Loads test data once per test session and shares it across all tests, improving performance by avoiding repeated file reads.
Note: This fixture is currently unused. The test module uses a module-level constant with @pytest.mark.parametrize instead, which is required because parametrize decorators are evaluated at collection time before fixtures are available.
- Returns:
Dictionary containing test data with defaults applied.
- tests.conftest.networks_api() NetworksAPI[source]¶
Provide a fresh
NetworksAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('networks_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for network endpoints.- Returns:
A configured
NetworksAPIinstance.
- tests.conftest.people_api() PeopleAPI[source]¶
Provide a fresh
PeopleAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('people_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for people endpoints.- Returns:
A configured
PeopleAPIinstance.
- tests.conftest.pytest_addoption(parser)[source]¶
Register custom command-line options for pytest.
Adds –loguru-log-level option to control application logging verbosity during test runs. This hook runs during pytest’s startup phase before any tests are collected.
- Parameters:
parser – Pytest’s argument parser instance.
- Usage:
poetry run pytest tests/* –loguru-log-level=DEBUG poetry run pytest tests/* –loguru-log-level=WARNING poetry run pytest tests/* –log-to-file
- Available log levels:
DEBUG, INFO (default), WARNING, ERROR, CRITICAL
- tests.conftest.pytest_configure(config)[source]¶
Configure the test environment before test collection begins.
Sets the LOG_LEVEL environment variable based on the –loguru-log-level CLI option, then reconfigures loguru to use the new level. This ensures logging is properly configured before any test modules are imported.
- Parameters:
config – Pytest’s Config object containing parsed CLI options.
- Note:
This hook runs after pytest_addoption but before test collection. The configure_logging() call is necessary because loguru may have already been initialized with default settings at module import time.
- tests.conftest.pytest_html_report_title(report)[source]¶
Customize the title shown in the pytest-html report header.
- Parameters:
report – The pytest-html report object.
- tests.conftest.pytest_html_results_summary(prefix, summary, postfix)[source]¶
Customize the results summary section of the pytest-html report.
Adds a branded header with run timestamp (Eastern Time), a description of the test scope, and links to external documentation. Called once by pytest-html after all tests have finished.
- Parameters:
prefix – List of HTML strings rendered above the pass/fail counts.
summary – List of HTML strings rendered alongside the counts.
postfix – List of HTML strings rendered below the counts.
- tests.conftest.pytest_runtest_makereport(item, call)[source]¶
Capture test failure details and send to AI analyzer.
Runs after each test phase (setup/call/teardown). On failure during the ‘call’ phase, extracts context from the test and API response, then sends it to the LLM for diagnosis. When judging is enabled (–judge-diagnosis or AI_JUDGE_ENABLED=true), the diagnosis is scored by an LLM judge for groundedness, completeness, and actionability (correctness is not scored live — a failure has no reference). The diagnosis (and, when judged, the quality verdict) are attached to the Allure report as JSON attachments.
- tests.conftest.pytest_sessionfinish(session, exitstatus)[source]¶
Perform cleanup and metadata writing after all tests complete.
Fires once at the end of the test session. Handles two tasks:
Allure metadata (if
--alluredirwas passed): copiestests/allure/categories.jsoninto the allure results dir so Allure can classify failures, and writesenvironment.propertieswith runtime config values (base URL, API version, timeout, log level) for the Allure Environment widget, plus GitHub run context (event, branch, commit, actor, run number) when running in CI.AI analysis report: calls
analyzer.save_results()to write all accumulated LLM diagnoses toai_analysis/failure_analysis.json.
- Parameters:
session – The pytest
Sessionobject.exitstatus – Integer exit code (0 = all passed, 1 = failures, etc.).
- tests.conftest.pytest_terminal_summary(terminalreporter, exitstatus, config)[source]¶
Print all accumulated AI diagnoses as a console section at the end of the run.
Renders after the built-in summary sections so a terminal-only run gets the same triage information as the reports. Keyed off the analyzer’s accumulated results rather than the –failure-analysis flag, so it also covers analysis enabled via AI_ANALYSIS_ENABLED=true in .env; no failures analyzed = no section. This is a triage summary (root cause + fix) — the full diagnosis (explanation, evidence) stays in the Allure attachment and ai_analysis/failure_analysis.json.
- Parameters:
terminalreporter – Pytest’s
TerminalReporterto write the section to.exitstatus – Integer exit code of the test session (unused).
config – Pytest’s
Configobject (unused).
- tests.conftest.reviews_api() ReviewsAPI[source]¶
Provide a fresh
ReviewsAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('reviews_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for review endpoints.- Returns:
A configured
ReviewsAPIinstance.
- tests.conftest.search_api() SearchAPI[source]¶
Provide a fresh
SearchAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('search_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for search endpoints.- Returns:
A configured
SearchAPIinstance.
- tests.conftest.trending_api() TrendingAPI[source]¶
Provide a fresh
TrendingAPIclient for a test.Dedicated, type-annotated alternative to
get_api_instance('trending_api')— the dependency is declared in the test signature, typo-checked at collection time, and gives editor autocomplete for trending endpoints.- Returns:
A configured
TrendingAPIinstance.
Movies¶
- tests.movies.test_add_rating.TEST_DATA = {'add_rating': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': ['Value too high: Value must be less than, or equal to 10.0.', 'Value too low: Value must be greater than 0.0.', 'Value invalid: Value must be a multiple of 0.50.'], 'movie_id': 45051, 'rating_payload': {'value': 18.4}, 'reason': 'Bad Request', 'status_code': 400}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': ['Value too high: Value must be less than, or equal to 10.0.', 'Value too low: Value must be greater than 0.0.', 'Value invalid: Value must be a multiple of 0.50.'], 'movie_id': 26699, 'rating_payload': {'value': 11.6}, 'reason': 'Bad Request', 'status_code': 400}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'rating_payload': {'value': 8.5}, 'reason': 'Created', 'status_code': 201}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'rating_payload': {'value': 10.0}, 'reason': 'Created', 'status_code': 201}]}}¶
Module-level test data loaded once at import time for parametrization.
- tests.movies.test_delete_rating.TEST_DATA = {'delete_rating': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'movie_id': 9999999999, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Authentication failed: You do not have permissions to access the service.', 'movie_id': 0, 'reason': 'Unauthorized', 'session_id': 'a1b2c3d4e5f6g7h8i9j0', 'status_code': 401}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The item/record was deleted successfully.', 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Test suite for the Movies API endpoints.
This module contains integration tests for the MoviesAPI class, validating both successful responses and error handling. Tests are data-driven using external YAML test data files with pytest’s parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid and invalid test cases with expected values and defaults applied.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
MoviesAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/test_popular.py -v
- tests.movies.test_details.TEST_DATA = {'get_movie_details': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'movie_id': 0, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'movie_id': -1, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'movie_id': 9999999999, 'reason': 'Not Found', 'status_code': 404}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 5465, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 50717, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'movie_id': 39026, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Networks¶
Test suite for the Networks API details endpoint.
This module contains integration tests for the NetworksAPI class, validating
both successful responses and error handling for GET /3/network/{network_id}.
Tests are data-driven using external YAML test data files with pytest’s
parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid and invalid test cases with expected values and defaults applied. Valid network IDs are hardcoded, well-known networks (Netflix, HBO, BBC One, NBC) verified against the live API.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
NetworksAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/networks/test_details.py -v
- tests.networks.test_details.TEST_DATA = {'get_network_details': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'network_id': 0, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'network_id': 99999999, 'reason': 'Not Found', 'status_code': 404}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'network_id': 174, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
People¶
- tests.people.test_details.TEST_DATA = {'get_person_details': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'person_id': 0, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid id: The pre-requisite id is invalid or not found.', 'person_id': -1, 'reason': 'Not Found', 'status_code': 404}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'The resource you requested could not be found.', 'person_id': 9999999999, 'reason': 'Not Found', 'status_code': 404}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'person_id': 11, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Search¶
Test suite for the Search API movie endpoint.
This module contains integration tests for the SearchAPI class, validating
both successful responses and error handling for GET /3/search/movie.
Tests are data-driven using external YAML test data files with pytest’s
parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid, empty-result and invalid test cases with expected values and defaults applied.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
SearchAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/search/test_movie.py -v
- tests.search.test_movie.TEST_DATA = {'search_movies': {'empty': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'query': ''}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'query': 'zzzqqqxyzzy123'}, 'reason': 'OK', 'status_code': 200}], 'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': -1, 'query': 'Avatar'}, 'reason': 'Bad Request', 'status_code': 400}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': 501, 'query': 'Gladiator'}, 'reason': 'Bad Request', 'status_code': 400}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'query': 'Superman'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 2, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'page': 2, 'query': 'Spider-Man'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'language': 'en-US', 'query': 'Inception'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'include_adult': 'true', 'query': 'Interstellar'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'query': 'Titanic', 'region': 'US'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'query': 'The Matrix', 'year': '1999'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'primary_release_year': '1993', 'query': 'Jurassic Park'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'include_adult': 'true', 'language': 'en-US', 'page': 1, 'primary_release_year': '1984', 'query': 'Terminator', 'region': 'US', 'year': '1984'}, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Discover¶
Test suite for the Discover API movie endpoint.
This module contains integration tests for the DiscoverAPI class, validating
both successful responses and error handling for GET /3/discover/movie.
Tests are data-driven using external YAML test data files with pytest’s
parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid, empty-result and invalid test cases with expected values and defaults applied.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
DiscoverAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/discover/test_movie.py -v
- tests.discover.test_movie.TEST_DATA = {'discover_movies': {'empty': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'vote_count.gte': '100000000'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'with_genres': '28', 'without_genres': '28'}, 'reason': 'OK', 'status_code': 200}], 'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': -1}, 'reason': 'Bad Request', 'status_code': 400}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': 501}, 'reason': 'Bad Request', 'status_code': 400}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 2, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'page': 2}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'language': 'en-US'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'include_adult': 'true'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'include_video': 'true'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'sort_by': 'popularity.desc'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'primary_release_year': '1989'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'year': '1989'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'region': 'US'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'with_genres': '28'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'with_original_language': 'en'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'vote_average.gte': '7'}, 'reason': 'OK', 'status_code': 200}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'include_adult': 'true', 'include_video': 'true', 'language': 'en-US', 'page': 1, 'primary_release_year': '1989', 'region': 'US', 'sort_by': 'popularity.desc', 'vote_average.gte': '7', 'with_genres': '28', 'with_original_language': 'en'}, 'reason': 'OK', 'status_code': 200}]}}¶
Module-level test data loaded once at import time for parametrization.
Trending¶
Test suite for the Trending API movie endpoint.
This module contains integration tests for the TrendingAPI class, validating
both successful responses and error handling for
GET /3/trending/movie/{time_window}. Tests are data-driven using external
YAML test data files with pytest’s parametrize decorator.
Test data is loaded from ‘test_data.yaml’ which contains valid and invalid test cases with expected values and defaults applied.
- Dependencies:
pytest: Test framework
pydantic: Response structure validation
TrendingAPI: API client under test
load_test_data: YAML test data loader
- Usage:
pytest tests/trending/test_movie.py -v
- tests.trending.test_movie.TEST_DATA = {'trending_movies': {'invalid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'expected_message': 'Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.', 'query_param': {'page': -1}, 'reason': 'Bad Request', 'status_code': 400, 'time_window': 'day'}], 'valid': [{'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'reason': 'OK', 'status_code': 200, 'time_window': 'day'}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 1, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'reason': 'OK', 'status_code': 200, 'time_window': 'week'}, {'exp_content_type': 'application/json', 'exp_del_req_method': 'DELETE', 'exp_get_req_method': 'GET', 'exp_max_elp_secs': 5, 'exp_page': 2, 'exp_post_req_method': 'POST', 'exp_put_req_method': 'PUT', 'query_param': {'page': 2}, 'reason': 'OK', 'status_code': 200, 'time_window': 'day'}]}}¶
Module-level test data loaded once at import time for parametrization.
Reviews¶
Schema¶
Pydantic models for API response validation.
Replaces JSON schema files with type-safe Python models. Each model corresponds to a former .json schema in tests/schemas/.
- class tests.schemas.models.AuthorDetails(*, name: Annotated[str, Strict(strict=True)], username: Annotated[str, MinLen(min_length=1), Strict(strict=True)], avatar_path: str | None = None, rating: Annotated[float | None, Ge(ge=0), Le(le=10)] = None)[source]¶
Bases:
BaseModelNested model for the
author_detailsblock of a review.- Parameters:
name – Author’s display name, may be empty.
username – Author’s TMDB username.
avatar_path – Path to the author’s avatar, or None. Unlike other
*_pathfields this is NOT constrained to an image extension — TMDB may store a gravatar URL here (e.g./https://secure.gravatar.com/...).rating – The author’s rating for the media (0–10), or None.
- avatar_path: str | None¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: Annotated[str, Strict(strict=True)]¶
- rating: float | None¶
- username: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.DiscoverMoviesResponse(*, page: Annotated[int, Ge(ge=1), Strict(strict=True)], results: Annotated[list[MovieListItem], MinLen(min_length=1)], total_pages: Annotated[int, Ge(ge=1), Strict(strict=True)], total_results: Annotated[int, Ge(ge=1), Strict(strict=True)])[source]¶
Bases:
PaginatedMovieListSchema for movie discovery response from
GET /3/discover/movie.Validates the paginated response structure containing the movies that matched the discover filter/sort criteria. Result items use the shared
MovieListItemmodel.resultsrequires at least one item — filter combinations expected to match nothing are asserted directly in the test instead of via this schema.- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tests.schemas.models.GenericResponse(*, status_message: Annotated[str, MinLen(min_length=1), Strict(strict=True)], success: Annotated[bool, Strict(strict=True)], status_code: Annotated[int, Ge(ge=0), Strict(strict=True)])[source]¶
Bases:
BaseModelSchema for generic error/status responses.
Used to validate error responses across all endpoints when the API returns a status message instead of resource data (e.g., 404, 401).
Replaces:
generic_schema.json- Example response::
{“status_message”: “Resource not found.”, “success”: false, “status_code”: 34}
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- status_code: Annotated[int, Strict(strict=True)]¶
- status_message: Annotated[str, Strict(strict=True)]¶
- success: Annotated[bool, Strict(strict=True)]¶
- class tests.schemas.models.Genre(*, id: Annotated[int, Ge(ge=0), Strict(strict=True)], name: Annotated[str, MinLen(min_length=1), Strict(strict=True)])[source]¶
Bases:
BaseModelNested model for a movie genre.
- Parameters:
id – Unique identifier for the genre.
name – Display name of the genre (e.g., “Action”, “Comedy”).
- id: Annotated[int, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.MovieDetails(*, adult: Annotated[bool, Strict(strict=True)], id: Annotated[int, Ge(ge=0), Strict(strict=True)], origin_country: list[str], original_language: Annotated[str, MinLen(min_length=2), MaxLen(max_length=2), Strict(strict=True)], original_title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], release_date: str | None = None, production_companies: list[ProductionCompany], genres: list[Genre], **extra_data: Any)[source]¶
Bases:
BaseModelSchema for movie details response from
GET /3/movie/{movie_id}.Validates the core fields returned by the TMDB movie details endpoint. Uses
extra = "allow"to accept additional fields not explicitly defined here (e.g., overview, budget, revenue, runtime).Replaces:
movie_schema.json- Parameters:
adult – Whether the movie is classified as adult content.
id – Unique TMDB movie identifier.
origin_country – List of ISO 3166-1 country codes.
original_language – ISO 639-1 language code of the original language.
original_title – Original title in the movie’s native language.
title – Localized title of the movie.
release_date – Release date in
YYYY-MM-DDformat, or None.production_companies – List of companies that produced the movie.
genres – List of genres the movie belongs to.
- adult: Annotated[bool, Strict(strict=True)]¶
- id: Annotated[int, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- origin_country: list[str]¶
- original_language: Annotated[str, Strict(strict=True)]¶
- original_title: Annotated[str, Strict(strict=True)]¶
- production_companies: list[ProductionCompany]¶
- release_date: str | None¶
- title: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.MovieListItem(*, adult: Annotated[bool, Strict(strict=True)], backdrop_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, genre_ids: list[int], id: Annotated[int, Ge(ge=0), Strict(strict=True)], original_language: Annotated[str, MinLen(min_length=2), MaxLen(max_length=2), Strict(strict=True)], original_title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], overview: str, popularity: Annotated[float, Ge(ge=0), Strict(strict=True)], poster_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, release_date: str, title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], video: Annotated[bool, Strict(strict=True)], vote_average: Annotated[float, Ge(ge=0), Le(le=10), Strict(strict=True)], vote_count: Annotated[int, Ge(ge=0), Strict(strict=True)], **extra_data: Any)[source]¶
Bases:
BaseModelNested model for a single movie in a paginated movie list.
Represents one item in the
resultsarray shared by TMDB’s list-style endpoints (e.g.GET /3/movie/popular,GET /3/search/movie).- Parameters:
adult – Whether the movie is classified as adult content.
backdrop_path – Path to the backdrop image, or None.
genre_ids – List of genre IDs associated with the movie.
id – Unique TMDB movie identifier.
original_language – ISO 639-1 language code.
original_title – Original title in the movie’s native language.
overview – Brief plot summary.
popularity – TMDB popularity score.
poster_path – Path to the poster image, or None.
release_date – Release date in
YYYY-MM-DDformat.title – Localized title of the movie.
video – Whether the movie has an associated video.
vote_average – Average user rating (0.0–10.0).
vote_count – Total number of user votes.
- adult: Annotated[bool, Strict(strict=True)]¶
- backdrop_path: str | None¶
- genre_ids: list[int]¶
- id: Annotated[int, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- original_language: Annotated[str, Strict(strict=True)]¶
- original_title: Annotated[str, Strict(strict=True)]¶
- overview: str¶
- popularity: Annotated[float, Strict(strict=True)]¶
- poster_path: str | None¶
- release_date: str¶
- title: Annotated[str, Strict(strict=True)]¶
- video: Annotated[bool, Strict(strict=True)]¶
- vote_average: Annotated[float, Strict(strict=True)]¶
- vote_count: Annotated[int, Strict(strict=True)]¶
- class tests.schemas.models.MovieReviewsResponse(*, id: Annotated[int, Ge(ge=0), Strict(strict=True)], page: Annotated[int, Ge(ge=1), Strict(strict=True)], results: Annotated[list[ReviewListItem], MinLen(min_length=1)], total_pages: Annotated[int, Ge(ge=1), Strict(strict=True)], total_results: Annotated[int, Ge(ge=1), Strict(strict=True)])[source]¶
Bases:
BaseModelSchema for a movie’s reviews list from
GET /3/movie/{movie_id}/reviews.Unlike the paginated movie-list endpoints, this envelope also carries a top-level
id(the movie whose reviews these are) alongside the usualpage/results/total_pages/total_resultsfields, and itsresultsare reviews, not movies. That distinct result type is why this is a standalone model and does not subclasspaginated_movie_list().resultsrequires at least one item — the reviews journey only validates against this schema for a movie that actually has reviews, asserting the empty case directly instead.- Parameters:
id – TMDB id of the movie the reviews belong to.
page – Current page number.
results – List of reviews on this page.
total_pages – Total number of review pages.
total_results – Total number of reviews across all pages.
- id: Annotated[int, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- page: Annotated[int, Strict(strict=True)]¶
- results: list[ReviewListItem]¶
- total_pages: Annotated[int, Strict(strict=True)]¶
- total_results: Annotated[int, Strict(strict=True)]¶
- class tests.schemas.models.NetworkDetails(*, headquarters: Annotated[str, Strict(strict=True)], homepage: Annotated[str, Strict(strict=True)], id: Annotated[int, Ge(ge=1), Strict(strict=True)], logo_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, name: Annotated[str, MinLen(min_length=1), Strict(strict=True)], origin_country: Annotated[str, Strict(strict=True)])[source]¶
Bases:
BaseModelSchema for network details response from
GET /3/network/{network_id}.Validates the response structure for the TMDB network details endpoint. The body is small and fully enumerated, so
extra = "forbid"keeps the contract strict.- Parameters:
headquarters – Network headquarters location, may be empty.
homepage – Network website URL, may be empty.
id – Unique TMDB network identifier.
logo_path – Path to the network logo image, or None.
name – Name of the network.
origin_country – ISO 3166-1 country code, may be empty (e.g., Netflix).
- headquarters: Annotated[str, Strict(strict=True)]¶
- homepage: Annotated[str, Strict(strict=True)]¶
- id: Annotated[int, Strict(strict=True)]¶
- logo_path: str | None¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: Annotated[str, Strict(strict=True)]¶
- origin_country: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.PersonDetails(*, adult: Annotated[bool, Strict(strict=True)], also_known_as: list[str], biography: Annotated[str, Strict(strict=True)], birthday: str | None = None, deathday: str | None = None, gender: Annotated[int, Ge(ge=0), Le(le=3), Strict(strict=True)], homepage: str | None = None, id: Annotated[int, Ge(ge=0), Strict(strict=True)], imdb_id: str | None = None, known_for_department: Annotated[str, MinLen(min_length=1), Strict(strict=True)], name: Annotated[str, MinLen(min_length=1), Strict(strict=True)], place_of_birth: str | None = None, popularity: Annotated[float, Ge(ge=0), Strict(strict=True)], profile_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, **extra_data: Any)[source]¶
Bases:
BaseModelSchema for person details response from
GET /3/person/{person_id}.Validates the response structure for the TMDB person details endpoint. Uses
extra = "allow"to accept additional fields not explicitly defined here (e.g., external_ids, combined_credits).Replaces:
person_details_schema.json- Parameters:
adult – Whether the person is associated with adult content.
also_known_as – Alternative names or aliases, or None.
biography – Biographical text about the person.
birthday – Date of birth in
YYYY-MM-DDformat.deathday – Date of death in
YYYY-MM-DDformat, or None if alive.gender – Gender identifier (0=not specified, 1=female, 2=male, 3=non-binary).
homepage – Personal website URL, or None.
id – Unique TMDB person identifier.
imdb_id – IMDb identifier (e.g.,
nm0000093).known_for_department – Primary department (e.g., “Acting”, “Directing”).
name – Full name of the person.
place_of_birth – City/country of birth, or None if unknown.
popularity – TMDB popularity score.
profile_path – Path to the profile image, or None.
- adult: Annotated[bool, Strict(strict=True)]¶
- also_known_as: list[str]¶
- biography: Annotated[str, Strict(strict=True)]¶
- birthday: str | None¶
- deathday: str | None¶
- gender: Annotated[int, Strict(strict=True)]¶
- homepage: str | None¶
- id: Annotated[int, Strict(strict=True)]¶
- imdb_id: str | None¶
- known_for_department: Annotated[str, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: Annotated[str, Strict(strict=True)]¶
- place_of_birth: str | None¶
- popularity: Annotated[float, Strict(strict=True)]¶
- profile_path: str | None¶
- class tests.schemas.models.PopularMoviesResponse(*, page: Annotated[int, Ge(ge=0), Strict(strict=True)], results: Annotated[list[MovieListItem], MinLen(min_length=1)], total_pages: Annotated[int, Ge(ge=0), Strict(strict=True)], total_results: Annotated[int, Ge(ge=0), Strict(strict=True)])[source]¶
Bases:
PaginatedMovieListSchema for popular movies list response from
GET /3/movie/popular.Validates the paginated response structure containing a list of popular movies. Result items use the shared
MovieListItemmodel.Replaces:
popular_movies_schema.json- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tests.schemas.models.ProductionCompany(*, id: Annotated[int, Ge(ge=0), Strict(strict=True)], logo_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, name: Annotated[str, MinLen(min_length=1), Strict(strict=True)], origin_country: str | None = None)[source]¶
Bases:
BaseModelNested model for a production company within movie details.
- Parameters:
id – Unique identifier for the production company.
logo_path – Path to the company logo image, or None if unavailable.
name – Name of the production company.
origin_country – ISO 3166-1 country code of the company’s origin.
- id: Annotated[int, Strict(strict=True)]¶
- logo_path: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: Annotated[str, Strict(strict=True)]¶
- origin_country: str | None¶
- class tests.schemas.models.RatingResponse(*, success: Annotated[bool, Strict(strict=True)], status_code: Annotated[int, Ge(ge=0), Strict(strict=True)], status_message: Annotated[str, MinLen(min_length=1), Strict(strict=True)])[source]¶
Bases:
BaseModelSchema for add/delete movie rating responses.
Validates the response structure when a rating is submitted or removed. Uses
extra = "forbid"to reject any unexpected fields, matching the strictadditionalProperties: falsefrom the original JSON schema.Replaces:
add_delete_rating_schema.json- Example response::
{“success”: true, “status_code”: 1, “status_message”: “Success.”}
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- status_code: Annotated[int, Strict(strict=True)]¶
- status_message: Annotated[str, Strict(strict=True)]¶
- success: Annotated[bool, Strict(strict=True)]¶
- class tests.schemas.models.ReviewDetails(*, id: Annotated[str, MinLen(min_length=1), Strict(strict=True)], author: Annotated[str, MinLen(min_length=1), Strict(strict=True)], author_details: AuthorDetails, content: Annotated[str, MinLen(min_length=1), Strict(strict=True)], created_at: Annotated[str, MinLen(min_length=1), Strict(strict=True)], iso_639_1: Annotated[str, MinLen(min_length=1), Strict(strict=True)], media_id: Annotated[int, Ge(ge=0), Strict(strict=True)], media_title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], media_type: Annotated[str, MinLen(min_length=1), Strict(strict=True)], updated_at: Annotated[str, MinLen(min_length=1), Strict(strict=True)], url: Annotated[str, MinLen(min_length=1), Strict(strict=True)])[source]¶
Bases:
BaseModelSchema for review details response from
GET /3/review/{review_id}.Validates the response structure for the TMDB review details endpoint. The body is small and fully enumerated, so
extra = "forbid"keeps the contract strict.- Parameters:
id – Unique TMDB review identifier (24-character hex string).
author – Author’s display name.
author_details – Nested author metadata (name, username, avatar, rating).
content – The review text.
created_at – Creation timestamp (ISO 8601).
iso_639_1 – ISO 639-1 language code of the review.
media_id – TMDB id of the reviewed media.
media_title – Title of the reviewed media.
media_type – Media type of the reviewed item (e.g.
movie).updated_at – Last-updated timestamp (ISO 8601).
url – Public URL of the review on themoviedb.org.
- author: Annotated[str, Strict(strict=True)]¶
- author_details: AuthorDetails¶
- content: Annotated[str, Strict(strict=True)]¶
- created_at: Annotated[str, Strict(strict=True)]¶
- id: Annotated[str, Strict(strict=True)]¶
- iso_639_1: Annotated[str, Strict(strict=True)]¶
- media_id: Annotated[int, Strict(strict=True)]¶
- media_title: Annotated[str, Strict(strict=True)]¶
- media_type: Annotated[str, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- updated_at: Annotated[str, Strict(strict=True)]¶
- url: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.ReviewListItem(*, author: Annotated[str, MinLen(min_length=1), Strict(strict=True)], author_details: AuthorDetails, content: Annotated[str, MinLen(min_length=1), Strict(strict=True)], created_at: Annotated[str, MinLen(min_length=1), Strict(strict=True)], id: Annotated[str, MinLen(min_length=1), Strict(strict=True)], updated_at: Annotated[str, MinLen(min_length=1), Strict(strict=True)], url: Annotated[str, MinLen(min_length=1), Strict(strict=True)])[source]¶
Bases:
BaseModelNested model for one item of the
movie/{id}/reviewsresultsarray.A list item is the subset of
ReviewDetailsthe reviews-list endpoint returns — it omits themedia_id/media_title/media_typefields that only the standalonereview/{id}detail endpoint carries. The nestedauthor_detailsblock is identical, so it reusesAuthorDetails.- Parameters:
author – Author’s display name.
author_details – Nested author metadata (name, username, avatar, rating).
content – The review text.
created_at – Creation timestamp (ISO 8601).
id – Unique TMDB review identifier (24-character hex string).
updated_at – Last-updated timestamp (ISO 8601).
url – Public URL of the review on themoviedb.org.
- author: Annotated[str, Strict(strict=True)]¶
- author_details: AuthorDetails¶
- content: Annotated[str, Strict(strict=True)]¶
- created_at: Annotated[str, Strict(strict=True)]¶
- id: Annotated[str, Strict(strict=True)]¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- updated_at: Annotated[str, Strict(strict=True)]¶
- url: Annotated[str, Strict(strict=True)]¶
- class tests.schemas.models.SearchMovieListItem(*, adult: Annotated[bool, Strict(strict=True)], backdrop_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, genre_ids: list[int] | None = None, id: Annotated[int, Ge(ge=0), Strict(strict=True)], original_language: Annotated[str, MinLen(min_length=2), MaxLen(max_length=2), Strict(strict=True)], original_title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], overview: str, popularity: Annotated[Annotated[float, Strict(strict=True)] | None, Ge(ge=0)] = None, poster_path: Annotated[str | None, _PydanticGeneralMetadata(pattern='.*\\.(png|jpg)$')] = None, release_date: str | None = None, title: Annotated[str, MinLen(min_length=1), Strict(strict=True)], video: Annotated[bool, Strict(strict=True)] | None = None, vote_average: Annotated[Annotated[float, Strict(strict=True)] | None, Ge(ge=0), Le(le=10)] = None, vote_count: Annotated[Annotated[int, Strict(strict=True)] | None, Ge(ge=0)] = None, **extra_data: Any)[source]¶
Bases:
MovieListItemNested model for a single movie in
GET /3/search/movieresults.Search results can include stub catalog entries (e.g. user-submitted placeholders with no genres, votes or release date). TMDB omits the corresponding keys entirely for such items rather than sending nulls, so the fields
MovieListItemrequires are made optional here. When a field is present it is still validated with the same strict type and bounds as the base model; only the presence requirement is relaxed.- Parameters:
genre_ids – List of genre IDs, or None when omitted.
popularity – TMDB popularity score, or None when omitted.
release_date – Release date in
YYYY-MM-DDformat, or None when omitted.video – Whether the movie has an associated video, or None when omitted.
vote_average – Average user rating (0.0–10.0), or None when omitted.
vote_count – Total number of user votes, or None when omitted.
- genre_ids: list[int] | None¶
- model_config: ClassVar[ConfigDict] = {'extra': 'allow'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- popularity: Annotated[float, Strict(strict=True)] | None¶
- release_date: str | None¶
- video: Annotated[bool, Strict(strict=True)] | None¶
- vote_average: Annotated[float, Strict(strict=True)] | None¶
- vote_count: Annotated[int, Strict(strict=True)] | None¶
- class tests.schemas.models.SearchMoviesResponse(*, page: Annotated[int, Ge(ge=1), Strict(strict=True)], results: Annotated[list[SearchMovieListItem], MinLen(min_length=1)], total_pages: Annotated[int, Ge(ge=1), Strict(strict=True)], total_results: Annotated[int, Ge(ge=1), Strict(strict=True)])[source]¶
Bases:
PaginatedMovieListSchema for movie search response from
GET /3/search/movie.Validates the paginated response structure containing the movies that matched a search query. Result items use
SearchMovieListItemrather than the sharedMovieListItem— search results can include stub catalog entries that omit the genre/vote/release fields, soresultsis redeclared here to point at the tolerant item model (Pydantic does not merge a subclass’s fields into a nested model, so the override must replace theresultsannotation itself).resultsstill requires at least one item — searches expected to return no matches are asserted directly in the test instead of via this schema.- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- results: list[SearchMovieListItem]¶
- class tests.schemas.models.TrendingMoviesResponse(*, page: Annotated[int, Ge(ge=1), Strict(strict=True)], results: Annotated[list[MovieListItem], MinLen(min_length=1)], total_pages: Annotated[int, Ge(ge=1), Strict(strict=True)], total_results: Annotated[int, Ge(ge=1), Strict(strict=True)])[source]¶
Bases:
PaginatedMovieListSchema for trending movies list response from
GET /3/trending/movie/{time_window}.Validates the paginated response structure containing the movies trending over the requested time window (
dayorweek). Result items use the sharedMovieListItemmodel.- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- tests.schemas.models.paginated_movie_list(ge=1)[source]¶
Build the base model for a paginated movie-list response.
TMDB’s list-style movie endpoints (popular, search, discover, trending) share one envelope: a
pagenumber, aresultsarray ofMovieListItem(required non-empty here — endpoints whose empty-result case is valid assert it directly in the test instead), andtotal_pages/total_resultscounts. Each endpoint subclasses the returned base so it keeps a distinct, individually-registered model name while sharing this field definition.- Parameters:
ge – Lower bound applied to the integer pagination fields (
page,total_pages,total_results). Defaults to 1; popular passes 0 for its looser contract.- Returns:
A Pydantic base model class with the shared paginated fields.