class TestClientEpisodes(unittest.TestCase): """Client episodes unit tests.""" def setUp(self): self.client = TvdbClient() self.client.login() def tearDown(self): self.client.clear_token() pass def test_get_episode(self): response = self.client.get_episode(5255064) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, Episode) self.assertTrue(response.series_id == '296295') self.assertTrue(response.aired_season == 1) self.assertTrue(response.aired_episode_number == 1) def test_get_episode_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_episode(5255064) self.assertTrue(e.exception.status == 401) def test_get_episode_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_episode(0) self.assertTrue(e.exception.status == 404)
class TestClientEpisodes(unittest.TestCase): """Client updates unit tests.""" def setUp(self): self.client = TvdbClient() self.client.login() def tearDown(self): self.client.clear_token() pass def test_get_updates(self): day = 24 * 60 * 60 yesterday = date.today() - timedelta(days=1) yesterday_epoch = (yesterday.toordinal() - date(1970, 1, 1).toordinal()) * day response = self.client.get_updates(str(yesterday_epoch)) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, UpdateData) self.assertTrue(len(response.data) > 0) self.assertIsInstance(response.data[0], Update) def test_get_episode_401(self): self.client.clear_token() day = 24 * 60 * 60 today_epoch = (date.today().toordinal() - date(1970, 1, 1).toordinal()) * day # asserts with self.assertRaises(ApiException) as e: self.client.get_updates(str(today_epoch)) self.assertTrue(e.exception.status == 401) def test_get_episode_404(self): # asserts day = 24 * 60 * 60 tomorrow = date.today() + timedelta(days=1) tomorrow_epoch = (tomorrow.toordinal() - date(1970, 1, 1).toordinal()) * day with self.assertRaises(ApiException) as e: self.client.get_updates(str(tomorrow_epoch)) self.assertTrue(e.exception.status == 404)
class TestClientSeries(unittest.TestCase): """Client series unit tests.""" def setUp(self): self.client = TvdbClient() self.client.login() def tearDown(self): self.client.clear_token() pass def test_get_series(self): response = self.client.get_series(296295) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesData) self.assertTrue(response.data.imdb_id == 'tt4189022') self.assertTrue(response.data.series_name == 'Ash vs Evil Dead') @unittest.skip('Skipping because no errors are returned anymore in api response') def test_get_series_with_errors(self): response = self.client.get_series(296295, language='nl') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesData) self.assertTrue(response.data.imdb_id == 'tt4189022') self.assertIsNotNone(response.errors) self.assertIsNotNone(response.errors.invalid_language) def test_get_series_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series(296295) self.assertTrue(e.exception.status == 401) def test_get_series_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series(0) self.assertTrue(e.exception.status == 404)
class TestClientAuth(unittest.TestCase): """Client authentication unit tests.""" def setUp(self): self.client = TvdbClient() self.token = self.client.login() def tearDown(self): self.client.clear_token() self.token = None def test_authenticate(self): # asserts self.assertIsNotNone(self.token) def test_authenticate_401(self): # clear api key self.client.configuration.api_key['ApiKey'] = '' # asserts with self.assertRaises(ApiException) as e: self.client.login() self.assertTrue(e.exception.status == 401) def test_refresh_token(self): # sleep before refreshing the token to be sure we get a new one time.sleep(2) refresh_token = self.client.refresh_token() # asserts self.assertIsNotNone(refresh_token) self.assertNotEquals(self.token, refresh_token) def test_refresh_token_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.refresh_token() self.assertTrue(e.exception.status == 401)
class TestClientSeriesImages(unittest.TestCase): """Client series images unit tests.""" def setUp(self): self.client = TvdbClient() self.client.login() def tearDown(self): self.client.clear_token() pass def test_get_series_images_count(self): response = self.client.get_series_images_count(296295) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesImagesCounts) self.assertIsNotNone(response.data) self.assertIsInstance(response.data, SeriesImagesCount) self.assertTrue(response.data.fanart > 0) self.assertTrue(response.data.poster > 0) self.assertTrue(response.data.season > 0) self.assertTrue(response.data.series > 0) def test_get_series_images_count_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_images_count(296295) self.assertTrue(e.exception.status == 401) def test_get_series_images_count_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_images_count(0) self.assertTrue(e.exception.status == 404) def test_get_series_images(self): response = self.client.get_series_images(296295, 'poster') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesImageQueryResults) self.assertTrue(len(response.data) > 0) self.assertIsInstance(response.data[0], SeriesImageQueryResult) self.assertTrue(response.data[0].id > 0) self.assertTrue(response.data[0].key_type == 'poster') def test_get_series_images_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_images(296295) self.assertTrue(e.exception.status == 401) def test_get_series_images_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_images(0) self.assertTrue(e.exception.status == 404) def test_get_series_highest_rated_image(self): response = self.client.get_series_highest_rated_image(296295) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesImageQueryResult) self.assertTrue(response.key_type == 'poster') def test_get_series_highest_rated_image_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_highest_rated_image(296295) self.assertTrue(e.exception.status == 401) def test_get_series_highest_rated_image_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_highest_rated_image(0) self.assertTrue(e.exception.status == 404)
class TestClientSeriesEpisodes(unittest.TestCase): """Client series episodes unit tests.""" def setUp(self): self.client = TvdbClient() self.client.login() def tearDown(self): self.client.clear_token() pass def test_get_series_episodes_summary(self): response = self.client.get_series_episodes_summary(296295) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesSummary) self.assertTrue(response.aired_episodes == '53') self.assertIsNotNone(response.aired_seasons) self.assertIsInstance(response.aired_seasons, list) self.assertTrue(len(response.aired_seasons) == 4) def test_get_series_episodes_summary_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes_summary(296295) self.assertTrue(e.exception.status == 401) @unittest.skip('Skipping because no 404 is returned anymore as api response for an invalid series id') def test_get_series_episodes_summary_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes_summary(0) self.assertTrue(e.exception.status == 404) def test_get_series_episodes(self): response = self.client.get_series_episodes(296295) # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodes) self.assertTrue(len(response.data) > 0) self.assertIsNotNone(response.links) self.assertIsNotNone(response.links.first) self.assertIsNotNone(response.links.last) def test_get_series_episodes_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes(296295) self.assertTrue(e.exception.status == 401) def test_get_series_episodes_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes(0) self.assertTrue(e.exception.status == 404) def test_get_series_episodes_by_season(self): response = self.client.get_series_episodes_by_season(296295, '1') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesQuery) self.assertTrue(len(response.data) == 10) self.assertIsInstance(response.data[0], Episode) self.assertTrue(response.data[0].id == 5255064) self.assertTrue(response.data[0].aired_season == 1) self.assertTrue(response.data[0].aired_episode_number == 1) def test_get_series_episodes_by_season_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes_by_season(296295, '0') self.assertTrue(e.exception.status == 401) def test_get_series_episodes_by_season_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episodes_by_season(0, '0') self.assertTrue(e.exception.status == 404) def test_get_series_episode(self): response = self.client.get_series_episode(296295, '1', '1') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesQuery) self.assertTrue(len(response.data) == 1) self.assertTrue(response.data[0].id == 5255064) self.assertTrue(response.data[0].aired_season == 1) self.assertTrue(response.data[0].aired_episode_number == 1) @unittest.skip('Skipping because no errors are returned anymore in api response') def test_get_series_episode_with_errors(self): response = self.client.get_series_episode(296295, '1', '1', language='nl') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesQuery) self.assertTrue(len(response.data) == 1) self.assertTrue(response.data[0].id == 5255064) self.assertTrue(response.data[0].aired_season == 1) self.assertTrue(response.data[0].aired_episode_number == 1) self.assertIsNotNone(response.errors) self.assertIsNotNone(response.errors.invalid_language) def test_get_series_episode_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episode(296295, '1', '1') self.assertTrue(e.exception.status == 401) def test_get_series_episode_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episode(0, '0', '0') self.assertTrue(e.exception.status == 404) def test_get_series_episode_by_absolute_number(self): response = self.client.get_series_episode_by_absolute_number(296295, '1') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesQuery) self.assertTrue(len(response.data) == 1) self.assertTrue(response.data[0].id == 5255064) self.assertTrue(response.data[0].absolute_number == 1) @unittest.skip('Skipping because no errors are returned anymore in api response') def test_get_series_episode_by_absolute_number_with_errors(self): response = self.client.get_series_episode_by_absolute_number(296295, '1', language='nl') # asserts self.assertIsNotNone(response) self.assertIsInstance(response, SeriesEpisodesQuery) self.assertTrue(len(response.data) == 1) self.assertTrue(response.data[0].id == 5255064) self.assertTrue(response.data[0].absolute_number == 1) self.assertIsNotNone(response.errors) self.assertIsNotNone(response.errors.invalid_language) def test_get_series_episode_by_absolute_number_401(self): self.client.clear_token() # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episode_by_absolute_number(296295, '1') self.assertTrue(e.exception.status == 401) def test_get_series_episode_by_absolute_number_404(self): # asserts with self.assertRaises(ApiException) as e: self.client.get_series_episode_by_absolute_number(0, '0') self.assertTrue(e.exception.status == 404)