def test_get(self): """Provided the show id, you should be able to get the show object""" api = TVDB("B43FF87DE395DF56") show = api.get(79349, "en") self.assertEqual(show.SeriesName, "Dexter") self.assertEqual(show.id, 79349)
def test_iterate_search(self): """It should be possible to iterate over a search result""" api = TVDB("B43FF87DE395DF56") search = api.search("house", "en") for s in search: self.assertEqual(type(s), pytvdbapi.api.Show)
def test_get(self): """Provided the show id, you should be able to get the show object""" api = TVDB("B43FF87DE395DF56") show = api.get_series(79349, "en") self.assertEqual(show.SeriesName, "Dexter") self.assertEqual(show.id, 79349)
def test_default_order(self): """It should be possible to get an episode using the default sort order""" api = TVDB("B43FF87DE395DF56") ep = api.get_episode(0, "en", "default", True, seriesid=79349, seasonnumber=2, episodenumber=5) self.assertEqual(ep.absolute_number, 17)
def test_episode_id_kwarg(self): """It should be possible to load the episode passing the episode id as a kwarg""" api = TVDB("B43FF87DE395DF56") ep = api.get_episode(0, "en", "id", True, episodeid=308834) self.assertEqual(ep.id, 308834) self.assertEqual(ep.EpisodeName, 'Crocodile')
def test_missing_id(self): """It should be possible to call get_episode without passing id as positional argument""" api = TVDB("B43FF87DE395DF56") ep = api.get_episode("en", "id", True, episodeid=308834) self.assertEqual(ep.id, 308834) self.assertEqual(ep.EpisodeName, 'Crocodile')
def test_valid_show(self): """Given correct values, the function should return a valid Episode instance""" api = TVDB("B43FF87DE395DF56") # Second episode of dexter ep = api.get_episode_by_air_date(79349, 'en', datetime.date(2006, 10, 8)) self.assertEqual(ep.id, 308834) self.assertEqual(ep.EpisodeName, 'Crocodile')
def test_zap2it_id(self): """It should be possible to load the show using the zap2it id""" api = TVDB("B43FF87DE395DF56") show = api.get_series('EP00859795', 'en', 'zap2it') self.assertEqual(show.seriesid, 79349) # Dexter show = api.get_series(859795, 'en', 'zap2it') self.assertEqual(show.seriesid, 79349) # Dexter
def test_imdb_id(self): """It should be possible to use the imdb id to get the series""" api = TVDB("B43FF87DE395DF56") show = api.get_series(773262, 'en', 'imdb') self.assertEqual(show.seriesid, 79349) # Dexter show = api.get_series('tt0773262', 'en', 'imdb') self.assertEqual(show.seriesid, 79349) # Dexter
def test_no_actors(self): """ The Show instance should have an empty actor_objects when the actor data has not been loaded. """ api = TVDB("B43FF87DE395DF56", actors=False) show = api.get_series(79349, "en") # Load the series Dexter show.update() self.assertEqual(len(show.actor_objects), 0)
def test_iterable_actors(self): """ It should be possible to iterate over the actor objects """ api = TVDB("B43FF87DE395DF56", actors=True) show = api.get(79349, "en") # Load the series Dexter show.update() for actor in show.actor_objects: self.assertEqual(type(actor), Actor)
def test_get_episode(self): """ Provided the episode id, you should be able to get episode instance. """ api = TVDB("B43FF87DE395DF56") ep = api.get_episode(308834, "en") self.assertEqual(ep.id, 308834) self.assertEqual(ep.EpisodeName, 'Crocodile')
def test_force_language(self): """ It should be possible to use the "force_lang" keyword when creating the TVDB instance """ api = TVDB("B43FF87DE395DF56", force_lang=True) search = api.search("dexter", "it") self.assertEqual(len(search), 2)
def test_no_actors(self): """ The Show instance should have an empty actor_objects when the actor data has not been loaded. """ api = TVDB("B43FF87DE395DF56", actors=False) show = api.get(79349, "en") # Load the series Dexter show.update() self.assertEqual(len(show.actor_objects), 0)
def test_get_series(self): """ It should be possible to use the get_series alias to get a show given the right show id. """ api = TVDB("B43FF87DE395DF56") show = api.get_series(79349, "en") self.assertEqual(show.SeriesName, "Dexter") self.assertEqual(show.id, 79349)
def test_get_actors(self): """ The Show instance should have an actor_objects attribute when the actor data is loaded. """ api = TVDB("B43FF87DE395DF56", actors=True) show = api.get(79349, "en") # Load the series Dexter show.update() self.assertEqual(hasattr(show, "actor_objects"), True)
def test_invalid_actor_attribute(self): """ Actor instance should raise an exception when accessing an invalid attribute. """ api = TVDB("B43FF87DE395DF56", actors=True) show = api.get(79349, "en") # Load the series Dexter show.update() actor = show.actor_objects[0] self.assertRaises(error.TVDBAttributeError, actor.__getattr__, 'foo')
def test_invalid_search_index(self): """Search should raise TVDBIndexError when trying to access an invalid index """ api = TVDB("B43FF87DE395DF56") search = api.search("dexter", "en") self.assertRaises(error.TVDBIndexError, search.__getitem__, 2) self.assertRaises(error.TVDBIndexError, search.__getitem__, 5) self.assertRaises(error.TVDBIndexError, search.__getitem__, 100) self.assertRaises(error.TVDBIndexError, search.__getitem__, "foo")
def test_invalid_search_index(self): """Search should raise TVDBIndexError when trying to access an invalid index """ api = TVDB("B43FF87DE395DF56") search = api.search("dexter", "en") self.assertRaises(error.TVDBIndexError, search.__getitem__, 10) self.assertRaises(error.TVDBIndexError, search.__getitem__, 50) self.assertRaises(error.TVDBIndexError, search.__getitem__, 100) self.assertRaises(error.TVDBValueError, search.__getitem__, "foo")
def test_actor_representation(self): """ The representation of the actor should be properly formatted. """ api = TVDB("B43FF87DE395DF56", actors=True) show = api.get(79349, "en") # Load the series Dexter show.update() regexp = re.compile("^<Actor - .*?>$") for actor in show.actor_objects: self.assertNotEqual(regexp.match(actor.__repr__()), None)
def test_insensitive_attributes(self): """If selected, it should be possible to access the attributes in a case insensitive manner""" api = TVDB("B43FF87DE395DF56", actors=True, ignore_case=True) show = api.get_series(79349, "en") # Load the series Dexter show.update() actor = show.actor_objects[0] for a in dir(actor): self.assertTrue(hasattr(actor, a)) self.assertTrue(hasattr(actor, a.lower())) self.assertTrue(hasattr(actor, a.upper()))
def test_insensitive_attributes(self): """If selected, it should be possible to access the attributes in a case insensitive manner.""" api = TVDB("B43FF87DE395DF56", banners=True, ignore_case=True) show = api.get(79349, "en") # Load the series Dexter show.update() banner = show.banner_objects[0] for a in dir(banner): self.assertTrue(hasattr(banner, a)) self.assertTrue(hasattr(banner, a.lower())) self.assertTrue(hasattr(banner, a.upper()))
def test_attribute_case(self): """ When ignore_case is False, all attributes should be case sensitive """ api = TVDB("B43FF87DE395DF56", ignore_case=False) search = api.search("friends", 'en') # Load and update the show show = search[0] show.update() self.assertRaises(error.TVDBAttributeError, show.__getattr__, "ImDB_id")
def test_search(self): """It should be possible to search for shows""" api = TVDB("B43FF87DE395DF56") search = api.search("dexter", "en") self.assertEqual(len(search), 1) search = api.search("scrubs", "en") self.assertEqual(len(search), 2) search = api.search("dexter", "en") self.assertEqual(len(search), 1) self.assertEqual(search.search, "dexter")
def test_unicode_search(self): """ It should be possible to search for shows containing non ascii chars """ api = TVDB("B43FF87DE395DF56") search = api.search("Alarm für cobra 11", "de") show = search[0] self.assertEqual(show[1][2].EpisodeName, "Rote Rosen, schwarzer Tod") search = api.search('3年B組金八先生', "zh") show = search[0] self.assertEqual(show[1][1].EpisodeName, "3年B組金八先生")
def test_ignore_case(self): """ It should be possible to pass the ignore_case keyword to the api and access all show/season/episode attributes in a case insensitive way. """ api = TVDB("B43FF87DE395DF56", ignore_case=True) search = api.search("friends", 'en') # Load and update the show show = search[0] show.update() self.assertEqual(show.IMDB_ID, show.imdb_id) self.assertEqual(show.ImDB_id, show.imDb_Id)
def test_invalid_language(self): """Search function should raise TVDBValueError when trying to search with an invalid language """ api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBValueError, api.search, "dexter", "lu")
def test_invalid_method(self): """Function should raise TVDBValueError if an invalid method is passed""" api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", -1) self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "foo") self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "")
def test_non_date(self): """Function should raise an exception if the air_date parameter is of the wrong type""" api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 'en', 'foo') self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 'en', '2001-12-21') self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 'en', 2)
def test_invalid_id(self): """If the show can not be found, a TVDBValueError should be raised""" api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBIdError, api.get, 99999999999999, "en") self.assertRaises(error.TVDBIdError, api.get, "foo", "en") self.assertRaises(error.TVDBIdError, api.get, "", "en")
def test_missing_arguments(self): """Function should raise TVDBValueError if arguments for the method is missing""" api = TVDB("B43FF87DE395DF56") # self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "id") self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "default") self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "dvd") self.assertRaises(error.TVDBValueError, api.get_episode, 308834, "en", "absolute")
def test_actor_attributes(self): """ The attributes of the Actors class should be correct """ api = TVDB("B43FF87DE395DF56", actors=True) show = api.get(79349, "en") # Load the series Dexter show.update() actor = show.actor_objects[0] self.assertEqual(hasattr(actor, "id"), True) self.assertEqual(hasattr(actor, "Image"), True) self.assertEqual(hasattr(actor, "Name"), True) self.assertEqual(hasattr(actor, "Role"), True) self.assertEqual(hasattr(actor, "SortOrder"), True) self.assertEqual(hasattr(actor, "image_url"), True) self.assertEqual(len(dir(actor)), 6)
def test_invalid_language(self): """ Function should raise TVDBValueError if an invalid language is passed """ api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBValueError, api.get_series, 79349, "foo") self.assertRaises(error.TVDBValueError, api.get_series, 79349, "")
def test_invalid_id(self): """Function should raise bad data exception if an invalid id is passed""" api = TVDB("B43FF87DE395DF56") self.assertRaises(error.BadData, api.get_episode, "en", "id", True, episodeid=0, seriesid=81797) self.assertRaises(error.TVDBNotFoundError, api.get_episode, "en", "id", True, episodeid=-1, seriesid=81797) self.assertRaises(error.TVDBNotFoundError, api.get_episode, "en", "id", True, episodeid="foo", seriesid=81797) self.assertRaises(error.BadData, api.get_episode, "en", "id", True, episodeid=99999999999, seriesid=81797)
def test_invalid_language(self): """Function should raise an exception if an invalid language is passed""" api = TVDB("B43FF87DE395DF56") self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 'foo', datetime.date(2006, 10, 8)) self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 2, datetime.date(2006, 10, 8)) self.assertRaises(error.TVDBValueError, api.get_episode_by_air_date, 79349, 'english', datetime.date(2006, 10, 8))
def setUp(self): api = TVDB("B43FF87DE395DF56", actors=True) self.show = api.get_series(79349, "en") # Load the series Dexter self.show.update()
def _getShow(self, _banners=True): api = TVDB("B43FF87DE395DF56", banners=_banners) show = api.get(79349, "en") # Load the series Dexter show.update() return show
def test_case_insensitive(self): """The test should be case insensitive""" api = TVDB("B43FF87DE395DF56") search = api.search("DeXtEr", "en") self.assertEqual(len(search), 1)
def test_names_with_spaces(self): """It should be possible to search for shows with spaces in the name""" api = TVDB("B43FF87DE395DF56") search = api.search("How I Met Your Mother", "en") self.assertEqual(len(search), 1)
def test_absolute_order(self): """it should be possible to get an episode using absolute number""" api = TVDB("B43FF87DE395DF56") ep = api.get_episode(0, "en", "absolute", True, seriesid=81797, absolutenumber=62) self.assertEqual(ep.EpisodeName, "The First Obstacle? Giant Whale Laboon Appears")
def get(self, language, name): db = TVDB(tvdb_api_key) shows = db.search(name, language) shows = [show_to_dict(show) for show in shows] data = {"status": "success", "data": shows} self.write(data)
def _load_show(show): """Helper function to load a show show from server""" api = TVDB("B43FF87DE395DF56") search = api.search(show, "en") return search[0]