-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote TMDB API testing using pytest; proper asserts on all dictiona…
…ries performed
- Loading branch information
Showing
1 changed file
with
55 additions
and
3 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 |
---|---|---|
@@ -1,11 +1,63 @@ | ||
import pytest | ||
import sys | ||
import os | ||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
from utils import * | ||
|
||
if __name__ == "__main__": | ||
init_tmdb() | ||
@pytest.fixture(scope="module") | ||
def tmdb_setup(): | ||
init_tmdb("../config.json") | ||
|
||
def remove_key_from_list_of_dicts(lst, key): | ||
"""Remove specified key from all dictionaries in a list.""" | ||
for item in lst: | ||
if key in item: | ||
del item[key] | ||
return lst | ||
|
||
def test_get_tmdb_data(tmdb_setup): | ||
movies = [1730, 104871, 31414, 76819] | ||
expected_info = [ | ||
{ | ||
'tmdb_id': 1730, | ||
'title': 'Inland Empire', | ||
'directors': [{'id': 5602, 'name': 'David Lynch'}], | ||
'genres': ['Thriller', 'Mystery', 'Fantasy', 'Horror'], | ||
'release_year': 2006, | ||
'runtime': 180, | ||
'user_rating': [] | ||
}, | ||
{ | ||
'tmdb_id': 104871, | ||
'title': 'Sicily!', | ||
'directors': [{'id': 935136, 'name': 'Jean-Marie Straub'}, | ||
{'id': 935137, 'name': 'Danièle Huillet'}], | ||
'genres': ['Drama'], | ||
'release_year': 1999, | ||
'runtime': 66, | ||
'user_rating': [] | ||
}, | ||
{ | ||
'tmdb_id': 31414, | ||
'title': 'Satantango', | ||
'directors': [{'id': 85637, 'name': 'Béla Tarr'}], | ||
'genres': ['Drama'], | ||
'release_year': 1994, | ||
'runtime': 432, | ||
'user_rating': [] | ||
}, | ||
{ | ||
'tmdb_id': 76819, | ||
'title': 'Teenage Hooker Became A Killing Machine In Daehakro', | ||
'directors': [{'id': 1371835, 'name': 'Nam Gee-woong'}], | ||
'genres': ['Science Fiction', 'Horror'], | ||
'release_year': 2000, | ||
'runtime': 60, | ||
'user_rating': [] | ||
} | ||
] | ||
|
||
info = [get_tmdb_data(movie) for movie in movies] | ||
print(info) | ||
info_filtered = remove_key_from_list_of_dicts(info, 'popularity') | ||
assert info_filtered == expected_info |