Skip to content

Commit

Permalink
feat: add support for EpisodeGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
leandcesar committed Mar 11, 2023
1 parent f3e8699 commit 4479e7d
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 25 deletions.
28 changes: 28 additions & 0 deletions tests/test_episode_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest.mock import patch

import pytest

from themoviedb import routes, schemas


@pytest.mark.asyncio
async def test_episode_group_details(get_data, assert_data):
data = get_data("tv_episode_groups/details")
episode_group_id = 123

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
episode_groups = await routes.EpisodeGroup(episode_group_id).details()
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/tv/episode_group/{episode_group_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
},
)

assert isinstance(episode_groups, schemas.EpisodeGroup)
assert assert_data(episode_groups, data)
154 changes: 149 additions & 5 deletions tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,126 @@
from themoviedb import routes, schemas


@pytest.mark.asyncio
async def test_find_by_imdb(get_data, assert_data):
data = get_data("find/find")
imdb_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_imdb(imdb_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{imdb_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "imdb_id",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_tvdb(get_data, assert_data):
data = get_data("find/find")
tvdb_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_tvdb(tvdb_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{tvdb_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "tvdb_id",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_freebase_mid(get_data, assert_data):
data = get_data("find/find")
freebase_mid = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_freebase_mid(freebase_mid)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{freebase_mid}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "freebase_mid",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_freebase(get_data, assert_data):
data = get_data("find/find")
freebase_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_freebase(freebase_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{freebase_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "freebase_id",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_tvrage(get_data, assert_data):
data = get_data("find/find")
tvrage_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_tvrage(tvrage_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{tvrage_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "tvrage_id",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_facebook(get_data, assert_data):
data = get_data("find/find")
Expand All @@ -30,22 +150,46 @@ async def test_find_by_facebook(get_data, assert_data):


@pytest.mark.asyncio
async def test_find_by_imdb(get_data, assert_data):
async def test_find_by_instagram(get_data, assert_data):
data = get_data("find/find")
imdb_id = "test"
instagram_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_imdb(imdb_id)
results = await routes.Find().by_instagram(instagram_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{imdb_id}",
f"https://api.themoviedb.org/3/find/{instagram_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "imdb_id",
"external_source": "instagram_id",
},
)

assert isinstance(results, schemas.MultiResults)
assert assert_data(results, data)


@pytest.mark.asyncio
async def test_find_by_twitter(get_data, assert_data):
data = get_data("find/find")
twitter_id = "test"

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
results = await routes.Find().by_twitter(twitter_id)
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/find/{twitter_id}",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
"region": "US",
"watch_region": "US",
"external_source": "twitter_id",
},
)

Expand Down
38 changes: 19 additions & 19 deletions tests/test_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ async def test_person_images(get_data, assert_data):
assert assert_data(images, data)


@pytest.mark.skip
@pytest.mark.asyncio
async def test_person_movie_credits(get_data, assert_data):
data = get_data("people/movie_credits")
async def test_person_combined_credits(get_data, assert_data):
data = get_data("people/combined_credits")
person_id = 123

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
movie_credits = await routes.Person(person_id).movie_credits()
combined_credits = await routes.Person(person_id).combined_credits()
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/person/{person_id}/movie_credits",
f"https://api.themoviedb.org/3/person/{person_id}/combined_credits",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
Expand All @@ -94,21 +95,21 @@ async def test_person_movie_credits(get_data, assert_data):
},
)

assert isinstance(movie_credits, schemas.CreditsMovie)
assert assert_data(movie_credits, data)
assert isinstance(combined_credits, schemas.CreditsCombined)
assert assert_data(combined_credits, data)


@pytest.mark.asyncio
async def test_person_tv_credits(get_data, assert_data):
data = get_data("people/tv_credits")
async def test_person_movie_credits(get_data, assert_data):
data = get_data("people/movie_credits")
person_id = 123

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
tv_credits = await routes.Person(person_id).tv_credits()
movie_credits = await routes.Person(person_id).movie_credits()
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/person/{person_id}/tv_credits",
f"https://api.themoviedb.org/3/person/{person_id}/movie_credits",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
Expand All @@ -117,22 +118,21 @@ async def test_person_tv_credits(get_data, assert_data):
},
)

assert isinstance(tv_credits, schemas.CreditsTV)
assert assert_data(tv_credits, data)
assert isinstance(movie_credits, schemas.CreditsMovie)
assert assert_data(movie_credits, data)


@pytest.mark.skip
@pytest.mark.asyncio
async def test_person_combined_credits(get_data, assert_data):
data = get_data("people/combined_credits")
async def test_person_tv_credits(get_data, assert_data):
data = get_data("people/tv_credits")
person_id = 123

with patch("themoviedb.routes.base.ClientSession.request") as mocked:
mocked.return_value.__aenter__.return_value.json.return_value = data
combined_credits = await routes.Person(person_id).combined_credits()
tv_credits = await routes.Person(person_id).tv_credits()
mocked.assert_called_with(
"GET",
f"https://api.themoviedb.org/3/person/{person_id}/combined_credits",
f"https://api.themoviedb.org/3/person/{person_id}/tv_credits",
params={
"api_key": "TEST_TMDB_KEY",
"language": "en-US",
Expand All @@ -141,8 +141,8 @@ async def test_person_combined_credits(get_data, assert_data):
},
)

assert isinstance(combined_credits, schemas.CreditsCombined)
assert assert_data(combined_credits, data)
assert isinstance(tv_credits, schemas.CreditsTV)
assert assert_data(tv_credits, data)


@pytest.mark.asyncio
Expand Down
1 change: 1 addition & 0 deletions themoviedb/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from themoviedb.routes.companies import Company
from themoviedb.routes.collections import Collection
from themoviedb.routes.discover import Discover
from themoviedb.routes.episode_groups import EpisodeGroup
from themoviedb.routes.episodes import Episode
from themoviedb.routes.find import Find
from themoviedb.routes.genres import Genres
Expand Down
17 changes: 17 additions & 0 deletions themoviedb/routes/episode_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from themoviedb import schemas, utils
from themoviedb.routes.base import Base


class EpisodeGroup(Base):
def __init__(self, episode_group_id: int, **kwargs) -> None:
super().__init__(**kwargs)
self.episode_group_id = episode_group_id

async def details(self) -> schemas.EpisodeGroup:
"""Get the details of a TV episode group.
See more: https://developers.themoviedb.org/3/tv-episode-groups/get-tv-episode-group-details
"""
data = await self.request(f"tv/episode_group/{self.episode_group_id}")
return utils.as_dataclass(schemas.EpisodeGroup, data)
2 changes: 2 additions & 0 deletions themoviedb/schemas/_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class PartialEpisode:
still_path: Optional[str] = None
vote_average: Optional[float] = None
vote_count: Optional[int] = None
show_id: Optional[int] = None
order: Optional[int] = None

def __str__(self) -> str:
return self.name
Expand Down
12 changes: 11 additions & 1 deletion themoviedb/schemas/episode_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
from typing import List, Optional

from themoviedb.schemas._enums import EpisodeGroupType
from themoviedb.schemas._partial import PartialNetwork
from themoviedb.schemas._partial import PartialEpisode, PartialNetwork
from themoviedb.schemas._result import ResultWithID


@dataclass
class Group:
id: Optional[str] = None
name: Optional[str] = None
order: Optional[int] = None
episodes: Optional[List[PartialEpisode]] = None
locked: Optional[bool] = None


@dataclass
class EpisodeGroup:
id: Optional[str] = None
description: Optional[str] = None
episode_count: Optional[int] = None
group_count: Optional[int] = None
groups: Optional[List[Group]] = None
name: Optional[str] = None
network: Optional[PartialNetwork] = None
type: Optional[EpisodeGroupType] = None
Expand Down

0 comments on commit 4479e7d

Please sign in to comment.