-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
Certifications
- Loading branch information
1 parent
2b1802b
commit f3e8699
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from themoviedb import routes, schemas | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_certifications_movie(get_data, assert_data): | ||
data = get_data("certifications/movie_list") | ||
|
||
with patch("themoviedb.routes.base.ClientSession.request") as mocked: | ||
mocked.return_value.__aenter__.return_value.json.return_value = data | ||
certifications = await routes.Certifications().movie() | ||
mocked.assert_called_with( | ||
"GET", | ||
"https://api.themoviedb.org/3/certification/movie/list", | ||
params={ | ||
"api_key": "TEST_TMDB_KEY", | ||
"language": "en-US", | ||
"region": "US", | ||
"watch_region": "US", | ||
} | ||
) | ||
|
||
assert isinstance(certifications, schemas.Certifications) | ||
assert assert_data(certifications, data) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_certifications_tv(get_data, assert_data): | ||
data = get_data("certifications/tv_list") | ||
|
||
with patch("themoviedb.routes.base.ClientSession.request") as mocked: | ||
mocked.return_value.__aenter__.return_value.json.return_value = data | ||
certifications = await routes.Certifications().tv() | ||
mocked.assert_called_with( | ||
"GET", | ||
"https://api.themoviedb.org/3/certification/tv/list", | ||
params={ | ||
"api_key": "TEST_TMDB_KEY", | ||
"language": "en-US", | ||
"region": "US", | ||
"watch_region": "US", | ||
} | ||
) | ||
assert isinstance(certifications, schemas.Certifications) | ||
assert assert_data(certifications, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from themoviedb import schemas, utils | ||
from themoviedb.routes.base import Base | ||
|
||
|
||
class Certifications(Base): | ||
|
||
async def movie(self) -> schemas.Certifications: | ||
"""Get an up to date list of the officially supported movie certifications on TMDB. | ||
See more: https://developers.themoviedb.org/3/certifications/get-movie-certifications | ||
""" | ||
data = await self.request("certification/movie/list") | ||
return utils.as_dataclass(schemas.Certifications, data) | ||
|
||
async def tv(self) -> schemas.Certifications: | ||
"""Get an up to date list of the officially supported TV show certifications on TMDB. | ||
See more: https://developers.themoviedb.org/3/certifications/get-tv-certifications | ||
""" | ||
data = await self.request("certification/tv/list") | ||
return utils.as_dataclass(schemas.Certifications, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from dataclasses import dataclass | ||
from typing import Dict, List, Optional | ||
|
||
from themoviedb.schemas._result import Result | ||
|
||
|
||
@dataclass | ||
class Certification: | ||
certification: Optional[str] = None | ||
meaning: Optional[str] = None | ||
order: Optional[int] = None | ||
|
||
|
||
@dataclass | ||
class Certifications(Result): | ||
certifications: Optional[Dict[str, List[Certification]]] = None | ||
|
||
def __post_init__(self) -> None: | ||
self.results = self.certifications | ||
|
||
def __bool__(self) -> bool: | ||
return bool(self.results) | ||
|
||
def __getitem__(self, region: str) -> List[Certification]: | ||
return self.results[region] | ||
|
||
@property | ||
def regions(self) -> List[str]: | ||
return list(self.results.keys()) |