This repository has been archived by the owner on Oct 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_tmdb.py
170 lines (126 loc) · 4.55 KB
/
test_tmdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python2
from __future__ import print_function
from __future__ import unicode_literals
import tmdb
def test_simple_search():
"""Simple test search
"""
t = tmdb.MovieDb()
sr = t.search("Fight Club")
assert isinstance(sr, tmdb.SearchResults)
assert sr[0]['name'] == "Fight Club"
def test_search_results():
"""Check SearchResults are usable
"""
t = tmdb.MovieDb()
results = t.search("Fight Club")
first_result = results[0]
assert isinstance(first_result, tmdb.MovieResult)
print(first_result['name'])
assert first_result['name'] == 'Fight Club'
print(first_result['released'])
assert first_result['released'] == '1999-10-14'
print(first_result['imdb_id'])
assert first_result['imdb_id'] == 'tt0137523'
def test_info_from_search():
"""Get info from first search result
"""
t = tmdb.MovieDb()
results = t.search("Fight Club")
first_result = results[0]
info = first_result.info()
assert info['name'] == "Fight Club"
def test_search_to_info():
"""Gets a movie ID via search helper, then calls getMovieInfo using this
"""
sr = tmdb.search("fight club")[0]
movie = tmdb.getMovieInfo(sr['id'])
assert sr['name'] == movie['name']
def test_get_director():
"""Checks you can get the director of a film
"""
mid = tmdb.search("Inglourious Basterds")[0]['id']
movie = tmdb.getMovieInfo(mid)
assert len(movie['cast']['director']) == 1
assert movie['cast']['director'][0]['name'] == "Quentin Tarantino"
def test_get_movie_from_imdb():
"""Checks that a movie can be retrieved via its IMDb ID
"""
movie = tmdb.getMovieInfo('tt0079023')
assert len(movie['cast']['director']) == 2
assert movie['cast']['director'][0]['name'] == "Jean-Marie Straub"
print(repr(movie['cast']['director'][1]['name']))
assert movie['cast']['director'][1]['name'] == u"Dani\xe8le Huillet"
def test_search_wrapper():
"""Tests tmdb.search() wrapper works correctly
"""
r = tmdb.search("The Matrix")
assert isinstance(r, tmdb.SearchResults)
def test_getmovieinfo_wrapper():
"""Tests tmdb.getMovieInfo() wrapper works correctly
"""
r = tmdb.getMovieInfo(550)
assert isinstance(r, tmdb.Movie)
def test_artwork_generator():
"""Generates several tests posters/backdrops
Uses test generator to prevent multiple requests for the movie info
"""
filmId = tmdb.MovieDb().search("Fight Club")[0]['id']
film = tmdb.MovieDb().getMovieInfo(filmId)
def test_poster_urls():
"""Checks posters are valid looking URLs
"""
for poster in film['images'].posters:
for key, value in poster.items():
if key not in ['id', 'type']:
assert value.startswith("http://")
yield test_poster_urls
def test_backdrop_urls():
"""Checks backdrop images are valid looking URLs
"""
for poster in film['images'].posters:
for key, value in poster.items():
if key not in ['id', 'type']:
assert value.startswith("http://")
yield test_backdrop_urls
def test_artwork_repr():
"""Checks artwork repr looks sensible
"""
poster_repr = repr(film['images'].posters[0])
assert poster_repr.startswith("<Image (poster for ID")
backdrop_repr = repr(film['images'].backdrops[0])
assert backdrop_repr.startswith("<Image (backdrop for ID")
yield test_artwork_repr
def test_posters():
"""Check retrieving largest artwork
"""
assert len(film['images'].posters) > 1
assert len(film['images'].backdrops) > 1
print(film['images'].posters[0]['cover'])
url = film['images'].posters[0]['cover']
assert url.startswith('http://')
assert url.endswith('.jpg')
yield test_posters
def test_mediagetinfo():
"""Tests searching by file hash
"""
import nose
raise nose.SkipTest("Finding reliable hash to test with is difficult..")
t = tmdb.MovieDb()
films = t.mediaGetInfo(hash = '907172e7fe51ba57', size = 742086656)
film = films[0]
print(film['name'])
assert film['name'] == 'Sin City'
def test_castthumbnails():
"""Tests actors have thumbnails
"""
t = tmdb.MovieDb()
film = t.getMovieInfo(950)
assert 'thumb' in film['cast']['actor'][0]
assert film['cast']['actor'][0]['thumb'].startswith('http://')
def test_doctest():
import doctest
doctest.testmod(tmdb, raise_on_error = True)
if __name__ == '__main__':
import nose
nose.main()