From 42555849b227ac6b838a15cf31223e09ed5710bb Mon Sep 17 00:00:00 2001 From: lomion Date: Fri, 20 Aug 2021 10:07:57 +0200 Subject: [PATCH] Fix "No answer if no movie was found" --- test_tmdb.py | 10 +++++++++- tmdb/tmdb_api.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test_tmdb.py b/test_tmdb.py index 2b48fb0..9bfc111 100644 --- a/test_tmdb.py +++ b/test_tmdb.py @@ -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') diff --git a/tmdb/tmdb_api.py b/tmdb/tmdb_api.py index f57ccac..0cc824a 100644 --- a/tmdb/tmdb_api.py +++ b/tmdb/tmdb_api.py @@ -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']