"""Tests for progress models."""
from datetime import UTC, datetime
from typing import get_type_hints
from models.progress.playback import (
PlaybackEpisodeInfo,
PlaybackMovieInfo,
PlaybackProgressResponse,
PlaybackShowInfo,
)
from models.progress.show_progress import (
EpisodeInfo,
EpisodeProgressResponse,
HiddenSeasonResponse,
SeasonProgressResponse,
ShowProgressResponse,
)
from models.types.ids import TraktIds
class TestShowProgressModels:
"""Tests for show progress Pydantic models."""
def test_show_progress_response_structure(self) -> None:
"""Test ShowProgressResponse has expected fields."""
hints = get_type_hints(ShowProgressResponse)
# Required fields
assert "aired" in hints
assert "completed" in hints
assert "last_watched_at" in hints
assert "seasons" in hints
# Optional fields
assert "reset_at" in hints
assert "hidden_seasons" in hints
assert "next_episode" in hints
assert "last_episode" in hints
def test_season_progress_response_structure(self) -> None:
"""Test SeasonProgressResponse has expected fields."""
hints = get_type_hints(SeasonProgressResponse)
assert "number" in hints
assert "aired" in hints
assert "completed" in hints
assert "episodes" in hints
def test_episode_progress_response_structure(self) -> None:
"""Test EpisodeProgressResponse has expected fields."""
hints = get_type_hints(EpisodeProgressResponse)
assert "number" in hints
assert "completed" in hints
assert "last_watched_at" in hints
def test_episode_info_structure(self) -> None:
"""Test EpisodeInfo has expected fields."""
hints = get_type_hints(EpisodeInfo)
assert "season" in hints
assert "number" in hints
assert "title" in hints
assert "ids" in hints
def test_hidden_season_response_structure(self) -> None:
"""Test HiddenSeasonResponse has expected fields."""
hints = get_type_hints(HiddenSeasonResponse)
assert "number" in hints
assert "ids" in hints
class TestPlaybackProgressModels:
"""Tests for playback progress Pydantic models."""
def test_playback_progress_response_movie(self) -> None:
"""Test PlaybackProgressResponse with movie type."""
movie_item = PlaybackProgressResponse(
progress=45.5,
paused_at=datetime(2024, 1, 20, 15, 30, 0, tzinfo=UTC),
id=12345,
type="movie",
movie=PlaybackMovieInfo(
title="Inception",
year=2010,
ids=TraktIds(trakt=16662, imdb="tt1375666"),
),
)
assert movie_item.type == "movie"
assert movie_item.progress == 45.5
assert movie_item.movie is not None
assert movie_item.movie.title == "Inception"
def test_playback_progress_response_episode(self) -> None:
"""Test PlaybackProgressResponse with episode type."""
episode_item = PlaybackProgressResponse(
progress=23.7,
paused_at=datetime(2024, 1, 21, 20, 0, 0, tzinfo=UTC),
id=67890,
type="episode",
episode=PlaybackEpisodeInfo(
season=1,
number=5,
title="Gray Matter",
ids=TraktIds(trakt=62089),
),
show=PlaybackShowInfo(
title="Breaking Bad",
year=2008,
ids=TraktIds(trakt=1388),
),
)
assert episode_item.type == "episode"
assert episode_item.progress == 23.7
assert episode_item.episode is not None
assert episode_item.episode.season == 1
assert episode_item.show is not None
assert episode_item.show.title == "Breaking Bad"
def test_playback_movie_info_structure(self) -> None:
"""Test PlaybackMovieInfo has expected fields."""
hints = get_type_hints(PlaybackMovieInfo)
assert "title" in hints
assert "year" in hints
assert "ids" in hints
def test_playback_episode_info_structure(self) -> None:
"""Test PlaybackEpisodeInfo has expected fields."""
hints = get_type_hints(PlaybackEpisodeInfo)
assert "season" in hints
assert "number" in hints
assert "title" in hints
assert "ids" in hints
def test_playback_show_info_structure(self) -> None:
"""Test PlaybackShowInfo has expected fields."""
hints = get_type_hints(PlaybackShowInfo)
assert "title" in hints
assert "year" in hints
assert "ids" in hints