Fix "No answer if no movie was found"
This commit is contained in:
parent
74ac2415cc
commit
42555849b2
10
test_tmdb.py
10
test_tmdb.py
|
@ -23,6 +23,7 @@ class TestTmdbMethods(unittest.TestCase):
|
||||||
movie = Movie()
|
movie = Movie()
|
||||||
id = movie.search_title('Breakfast Club')
|
id = movie.search_title('Breakfast Club')
|
||||||
self.assertEqual(id, 2108)
|
self.assertEqual(id, 2108)
|
||||||
|
self.assertEqual(movie.valid, True)
|
||||||
|
|
||||||
def test_cast(self):
|
def test_cast(self):
|
||||||
movie = Movie()
|
movie = Movie()
|
||||||
|
@ -76,6 +77,7 @@ class TestTmdbMethods(unittest.TestCase):
|
||||||
id = movie.search_title('Breakfast Club 2019')
|
id = movie.search_title('Breakfast Club 2019')
|
||||||
self.assertEqual(id, None)
|
self.assertEqual(id, None)
|
||||||
self.assertEqual(None, movie.title)
|
self.assertEqual(None, movie.title)
|
||||||
|
self.assertEqual(movie.valid, False)
|
||||||
|
|
||||||
def test_search_year(self):
|
def test_search_year(self):
|
||||||
movie = Movie()
|
movie = Movie()
|
||||||
|
@ -101,6 +103,12 @@ class TestTmdbMethods(unittest.TestCase):
|
||||||
size = movie.set_poster_size("w666")
|
size = movie.set_poster_size("w666")
|
||||||
self.assertEqual(size, None)
|
self.assertEqual(size, None)
|
||||||
|
|
||||||
|
def test_year_no_y(self):
|
||||||
|
movie = Movie()
|
||||||
|
id = movie.search_title('infinite 2021')
|
||||||
|
self.assertEqual(id, None)
|
||||||
|
self.assertEqual(movie.valid, False)
|
||||||
|
|
||||||
# TV Shows
|
# TV Shows
|
||||||
def test_search_tvshow(self):
|
def test_search_tvshow(self):
|
||||||
movie = TvShow()
|
movie = TvShow()
|
||||||
|
@ -120,7 +128,7 @@ class TestTmdbMethods(unittest.TestCase):
|
||||||
def test_poster_path(self):
|
def test_poster_path(self):
|
||||||
movie = Movie()
|
movie = Movie()
|
||||||
movie.search_title('Dune')
|
movie.search_title('Dune')
|
||||||
self.assertEqual(movie.poster_url, "http://image.tmdb.org/t/p/w92/9HNZTw2D3cM1yA08FF5SeWEO9eX.jpg")
|
self.assertEqual(movie.poster_url, "http://image.tmdb.org/t/p/w92/cDbNAY0KM84cxXhmj8f0dLWza3t.jpg")
|
||||||
|
|
||||||
def test_movie_popular_length(self):
|
def test_movie_popular_length(self):
|
||||||
results = apiRequests('/movie/popular')
|
results = apiRequests('/movie/popular')
|
||||||
|
|
|
@ -119,10 +119,15 @@ class Movie(TmdbApiSingle):
|
||||||
movie_id = json['results'][0]['id']
|
movie_id = json['results'][0]['id']
|
||||||
self.query_details(movie_id)
|
self.query_details(movie_id)
|
||||||
return movie_id
|
return movie_id
|
||||||
|
else:
|
||||||
|
self.valid = False
|
||||||
|
return None
|
||||||
|
|
||||||
def query_details(self, id):
|
def query_details(self, id):
|
||||||
data = self.request('movie/' + str(id))
|
data = self.request('movie/' + str(id))
|
||||||
self.title = data['title']
|
self.title = data['title']
|
||||||
|
if not self.title:
|
||||||
|
self.valid = False
|
||||||
self.id = data['id']
|
self.id = data['id']
|
||||||
self.poster_url = self.base_url_poster + data['poster_path']
|
self.poster_url = self.base_url_poster + data['poster_path']
|
||||||
self.overview = data['overview']
|
self.overview = data['overview']
|
||||||
|
@ -152,10 +157,15 @@ class TvShow(TmdbApiSingle):
|
||||||
movie_id = json['results'][0]['id']
|
movie_id = json['results'][0]['id']
|
||||||
self.query_details(movie_id)
|
self.query_details(movie_id)
|
||||||
return movie_id
|
return movie_id
|
||||||
|
else:
|
||||||
|
self.valid = False
|
||||||
|
return None
|
||||||
|
|
||||||
def query_details(self, id):
|
def query_details(self, id):
|
||||||
data = self.request('tv/' + str(id))
|
data = self.request('tv/' + str(id))
|
||||||
self.title = data['name']
|
self.title = data['name']
|
||||||
|
if not self.title:
|
||||||
|
self.valid = False
|
||||||
self.id = data['id']
|
self.id = data['id']
|
||||||
self.poster_url = self.base_url_poster + data['poster_path']
|
self.poster_url = self.base_url_poster + data['poster_path']
|
||||||
self.overview = data['overview']
|
self.overview = data['overview']
|
||||||
|
|
Loading…
Reference in a new issue