Test Data Generators¶
Test data generators for dynamic test values.
- tests.helpers.test_data_generators.pick_random_movie_id() int[source]¶
Return a random movie ID from the cached movie_ids.txt list.
The file is read once via
_load_movie_ids(); each call only performs an in-memory random choice.- Returns:
Random movie ID, e.g.
27205.- Raises:
FileNotFoundError – If movie_ids.txt doesn’t exist
ValueError – If file is empty or contains invalid data
- tests.helpers.test_data_generators.pick_random_network_id() int[source]¶
Return a random TMDB network ID from the hardcoded
NETWORK_IDSlist.- Returns:
Random network ID, e.g.
213(Netflix).
- tests.helpers.test_data_generators.pick_random_rated_movie_id(acc_id, session_id) int[source]¶
Fetches rated movies from the account and returns a random movie ID.
- Returns:
Random rated movie ID, e.g.
27205.- Raises:
ValueError – If no rated movies are found
- tests.helpers.test_data_generators.pick_random_review_id(max_attempts: int = 25) str[source]¶
Return a random review ID harvested from a random movie’s reviews.
Reuses
pick_random_movie_id(), then fetches that movie’s reviews viaGET /3/movie/{id}/reviews. Most movies inmovie_ids.txthave no reviews, so it retries random movies until one has at least one review, then returns a random review’s id.MoviesAPIis imported lazily to avoid an import cycle (apiimports would otherwise load during test-data import).- Parameters:
max_attempts – Maximum random movies to try before giving up.
- Returns:
A TMDB review ID (24-character hex string), e.g.
"58a231c592514111d5001a2f".- Raises:
ValueError – If no reviews are found within
max_attemptstries.
- tests.helpers.test_data_generators.random_invalid_rating() float[source]¶
Generate a random invalid movie rating (outside 0.5-10.0 range).
- Returns:
Random invalid rating, e.g.
-3.5or14.2.
- tests.helpers.test_data_generators.random_rating(min_val: float = 0.5, max_val: float = 10.0) float[source]¶
Generate a random valid movie rating in 0.5 increments.
- Parameters:
min_val – Minimum rating value (default: 0.5)
max_val – Maximum rating value (default: 10.0)
- Returns:
Random rating in 0.5 increments, e.g.
7.5.