class AnonymousTvDBTestCase(BaseTestCase): """TvDB client without API key test case.""" def setUp(self): super(AnonymousTvDBTestCase, self).setUp() self.tvdb = TvDB() def test_response_error(self): self.response(status_code=404) with self.assertRaises(APIResponseError): self.tvdb.search("something") def test_response_unexpected_content_type(self): self.response(status_code=200, content_type="text/plain") with self.assertRaises(APIResponseError): self.tvdb.search("something") def test_search_no_results(self): self.response(filename="empty.xml") results = self.tvdb.search("nothing") self.assertEqual(results, []) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/GetSeries.php", params={"seriesname": "nothing"} ) def test_search_results(self): self.response(filename="getseries.xml") results = self.tvdb.search("chuck") self.requests.get.assert_called_once_with( "http://thetvdb.com/api/GetSeries.php", params={"seriesname": "chuck"} ) self.assertEqual(len(results), 7) def test_get_series_by_id_requires_api_key(self): with self.assertRaises(APIKeyRequiredError): self.tvdb.get_series_by_id(1111) def test_get_episode_by_id_requires_api_key(self): with self.assertRaises(APIKeyRequiredError): self.tvdb.get_episode_by_id(1111) def test_get_episode_requires_api_key(self): with self.assertRaises(APIKeyRequiredError): self.tvdb.get_episode(80348, 1, 1)
class TvDBTestCase(BaseTestCase): """TvDB client with API key test case.""" def setUp(self): super(TvDBTestCase, self).setUp() self.tvdb = TvDB(api_key="123456789") def test_get_series_by_id(self): self.response(filename="series.xml") result = self.tvdb.get_series_by_id(321) self.assertIsInstance(result, Series) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/series/321/en.xml", params={}) def test_get_series_by_id_missing_data(self): self.response(filename="empty.xml") result = self.tvdb.get_series_by_id(321) self.assertIsNone(result) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/series/321/en.xml", params={}) def test_get_series_by_id_full_data(self): self.response(filename="80348.zip", content_type="application/zip") result = self.tvdb.get_series_by_id(80348, extended=True) self.assertIsInstance(result, Series) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/series/80348/all/en.zip", params={}) # check episodes were loaded self.assertEqual(len(result.seasons), 6) self.assertEqual(len(result.seasons[1]), 13) def test_get_episode_by_id(self): self.response(filename="episode.xml") result = self.tvdb.get_episode_by_id(332179) self.assertIsInstance(result, Episode) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/episodes/332179/en.xml", params={}) def test_get_episode_by_id_missing_data(self): self.response(filename="empty.xml") result = self.tvdb.get_episode_by_id(321) self.assertIsNone(result) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/episodes/321/en.xml", params={}) def test_get_episode(self): self.response(filename="episode.xml") result = self.tvdb.get_episode(80348, 1, 1) self.assertIsInstance(result, Episode) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/123456789/series/80348/default/1/1/en.xml", params={} ) def test_get_episode_missing_data(self): self.response(filename="empty.xml") result = self.tvdb.get_episode(80348, 6, 1) self.assertIsNone(result) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/123456789/series/80348/default/6/1/en.xml", params={} ) def test_updated_without_timeframe_default_day(self): self.response(filename="updates_day.zip", content_type="application/zip") results = self.tvdb.updated() for result in results: self.assertIsInstance(result, Update) self.requests.get.assert_called_once_with("http://thetvdb.com/api/123456789/updates/updates_day.zip", params={}) def test_updated_with_timeframe(self): self.response(filename="updates_month.zip", content_type="application/zip") results = self.tvdb.updated(TvDB.MONTH) for result in results: self.assertIsInstance(result, Update) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/123456789/updates/updates_month.zip", params={} ) def test_updated_with_invalid_timeframe(self): with self.assertRaises(TvDBException): self.tvdb.updated("anything") def test_updated_since_no_kind_specified(self): self.response(filename="updates_since.xml") results = self.tvdb.updated_since(1234567890) for result in results: self.assertIsInstance(result, Update) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/Updates.php?type=all&time=1234567890", params={} ) def test_updated_since_with_specific_kind(self): self.response(filename="updates_since_episodes.xml") results = self.tvdb.updated_since(1234567890, kind=TvDB.EPISODE) for result in results: self.assertIsInstance(result, Update) self.assertEqual(result.kind, TvDB.EPISODE) self.requests.get.assert_called_once_with( "http://thetvdb.com/api/Updates.php?type=episode&time=1234567890", params={} ) def test_updated_since_with_invalid_kind(self): with self.assertRaises(TvDBException): self.tvdb.updated_since(123456780, "anything")
def setUp(self): super(TvDBEpisodeTestCase, self).setUp() self.response(filename="episode.xml") tvdb = TvDB(api_key="123456789") self.result = tvdb.get_episode_by_id(332179)