Fix "No answer if no movie was found"

This commit is contained in:
lomion 2021-08-20 10:07:57 +02:00
parent 74ac2415cc
commit 42555849b2
2 changed files with 19 additions and 1 deletions

View file

@ -23,6 +23,7 @@ class TestTmdbMethods(unittest.TestCase):
movie = Movie()
id = movie.search_title('Breakfast Club')
self.assertEqual(id, 2108)
self.assertEqual(movie.valid, True)
def test_cast(self):
movie = Movie()
@ -76,6 +77,7 @@ class TestTmdbMethods(unittest.TestCase):
id = movie.search_title('Breakfast Club 2019')
self.assertEqual(id, None)
self.assertEqual(None, movie.title)
self.assertEqual(movie.valid, False)
def test_search_year(self):
movie = Movie()
@ -100,6 +102,12 @@ class TestTmdbMethods(unittest.TestCase):
self.assertEqual(movie.base_url_poster, f"{movie.base_url_images}w500")
size = movie.set_poster_size("w666")
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
def test_search_tvshow(self):
@ -120,7 +128,7 @@ class TestTmdbMethods(unittest.TestCase):
def test_poster_path(self):
movie = Movie()
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):
results = apiRequests('/movie/popular')

View file

@ -119,10 +119,15 @@ class Movie(TmdbApiSingle):
movie_id = json['results'][0]['id']
self.query_details(movie_id)
return movie_id
else:
self.valid = False
return None
def query_details(self, id):
data = self.request('movie/' + str(id))
self.title = data['title']
if not self.title:
self.valid = False
self.id = data['id']
self.poster_url = self.base_url_poster + data['poster_path']
self.overview = data['overview']
@ -152,10 +157,15 @@ class TvShow(TmdbApiSingle):
movie_id = json['results'][0]['id']
self.query_details(movie_id)
return movie_id
else:
self.valid = False
return None
def query_details(self, id):
data = self.request('tv/' + str(id))
self.title = data['name']
if not self.title:
self.valid = False
self.id = data['id']
self.poster_url = self.base_url_poster + data['poster_path']
self.overview = data['overview']