def test_getSeasonAndEpisode_try_to_cache_output(self): # Given fields = { 'title': u'Seinfeld', 'starttime': socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 50, 00), 'hasairdate': 1, 'airdate': u'1989-07-05' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When for i in xrange(100): #@UnusedVariable # TODO Verify hitting cache < 1sec per invocation. # Since tvrage api is not injected, cannot mock season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('1', season) self.assertEqual('1', episode)
def test_getSeasonAndEpisode_NBCNightlyNews_returns_None_cuz_TVRage_throws_KeyError( self): # Given fields = { 'title': u'NBC Nightly News', 'subtitle': u'blah', 'starttime': socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 50, 00), 'hasairdate': 1, 'airdate': u'2010-07-14' } program = RecordedProgram(pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_getSeasonAndEpisode_When_match_not_found_using_original_airdate_Then_match_by_subtitle( self): # Given fields = { 'title': u'WCG Ultimate Gamer', 'subtitle': u'In The Crosshairs', 'starttime': socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime': socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate': u'2010-09-20', # TVRage shows date as 2010-09-16 } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('2', season) self.assertEqual('5', episode)
def test_getSeasonAndEpisode_Success(self): fields = { 'title' : u'The Real World', 'starttime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'airdate' : u'2010-07-14' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'24', u'3')
def test_getSeasonAndEpisode_Success_HouseHunters(self): fields = { 'title' : u'House Hunters', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'airdate' : u'2008-11-02' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'30', u'2')
def test_getSeasonAndEpisode_When_show_not_found_Then_returns_none(self): fields = { 'title' : u'Crap Crappity Crapola', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'2010-08-03' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), None, None)
def test_love_and_hiphop_failure(self): fields = { 'title' : u'Love and HipHop', 'subtitle' : u'', 'airdate' : u'2011-11-21', 'starttime' : socketDateTime(2011, 12, 8, 22, 00, 00), 'endtime' : socketDateTime(2011, 12, 8, 23, 00, 00), } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'2', u'2')
def test_getSeasonAndEpisode_When_search_by_original_airdate_and_subtitle_fails_Then_search_on_record_date(self): fields = { 'title' : u'Late Night With Jimmy Fallon', 'subtitle' : u'xxx', 'starttime' : socketDateTime(2011, 12, 2, 2, 00, 00), 'endtime' : socketDateTime(2011, 12, 2, 3, 00, 00), 'airdate' : u'2006-10-10' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'2011', u'184')
def test_getSeasonAndEpisode_When_original_airdate_not_available_Then_return_nones(self): fields = { 'title' : u'The Real World', 'subtitle' : u'', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), None, None)
def test_getSeasonAndEpisode_When_original_airdate_not_available_and_subtitle_matches_Then_return_season_and_episode(self): fields = { 'title' : u'The Real World', 'subtitle' : u"Jemmye's White Knight", 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'24', u'3')
def test_getSeasonAndEpisode_When_no_matching_original_airdate_or_subtitle_Then_return_nones(self): fields = { 'title' : u'MasterChef', 'subtitle' : u'', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), None, None)
def test_getSeasonAndEpisode_succeeds_when_original_airdate_incorrect_and_one_day_behind(self): fields = { 'title' : u'Love and HipHop', 'subtitle' : u'', 'airdate' : u'2011-11-20', 'starttime' : socketDateTime(2011, 12, 8, 22, 00, 00), 'endtime' : socketDateTime(2011, 12, 8, 23, 00, 00), } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'2', u'2')
def test_getSeasonAndEpisode_When_original_airdate_and_subtitle_not_available_Then_return_Nones(self): fields = { 'title' : u'WCG Ultimate Gamer', 'subtitle' : u'', 'airdate' : u'', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), None, None)
def test_getSeasonAndEpisode_NBCNightlyNews_returns_None_cuz_TVRage_throws_KeyError(self): fields = { 'title' :u'NBC Nightly News', 'subtitle' :u'blah', 'starttime' :socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime' :socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' :u'2010-07-14' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), None, None)
def test_getSeasonAndEpisode_When_match_not_found_using_original_airdate_Then_match_by_subtitle(self): fields = { 'title' : u'WCG Ultimate Gamer', 'subtitle' : u'In The Crosshairs', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'airdate' : u'2010-09-20', # TVRage shows date as 2010-09-16 } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'2', u'5')
def test_getSeasonAndEpisode_When_matches_original_airdate_Then_return_season_and_episode(self): fields = { 'title' : u'The Real World', 'subtitle' : u'', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'2010-07-14' } self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'24', u'3')
def test_getSeasonAndEpisode_dont_blowup_when_a_season_is_missing(self): fields = { 'title' : u'The Daily Show With Jon Stewart', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'airdate' : u'2005-01-04' } program = RecordedProgram(data=pdata(fields), **self.deps) provider = TvRageProvider(self.platform) # When -- Season 3 for The Daily Show with Jon Stewart is missing season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNotNone(season) self.assertIsNotNone(episode)
def test_getSeasonAndEpisode_dont_blowup_when_a_season_is_missing(self): fields = { 'title': u'The Daily Show With Jon Stewart', 'starttime': socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime': socketDateTime(2010, 12, 2, 23, 50, 00), 'airdate': u'2005-01-04' } program = RecordedProgram(data=pdata(fields), **self.deps) provider = TvRageProvider(self.platform) # When -- Season 3 for The Daily Show with Jon Stewart is missing season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNotNone(season) self.assertIsNotNone(episode)
def test_getSeasonAndEpisode_When_show_not_found_Then_returns_none(self): # Setup fields = { 'title' : u'This Show Does Not Exist', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'hasairdate': 1, 'airdate' : u'2010-08-03' } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=Mock(), protocol=P, conn=Mock()) provider = TvdbFanartProvider(self.platform, nextProvider=None) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_getSeasonAndEpisode_Success(self): # Given fields = { 'title' : u'The Real World', 'starttime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'hasairdate': 1, 'airdate' : u'2010-07-14' } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('24', season) self.assertEqual('3', episode)
def test_getSeasonAndEpisode_Success_HouseHunters(self): # Given fields = { 'title' : u'House Hunters', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate' : u'2008-11-02' } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('30', season) self.assertEqual('2', episode)
def test_getSeasonAndEpisode_dont_blowup_when_a_season_is_missing(self): # Given fields = { 'title' : u'The Daily Show With Jon Stewart', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate' : u'2005-01-04' } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When -- Season 3 for The Daily Show with Jon Stewart is missing season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNotNone(season) self.assertIsNotNone(episode)
def test_getSeasonAndEpisode_When_show_not_found_Then_returns_none(self): # Given fields = { 'title' : u'Crap Crappity Crapola', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'hasairdate': 1, 'airdate' : u'2010-08-03' } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_getSeasonAndEpisode_try_to_cache_output(self): fields = { 'title' : u'Seinfeld', 'starttime' : socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'1989-07-05' } program = RecordedProgram(data=pdata(fields), **self.deps) provider = TvRageProvider(self.platform) # When for i in xrange(100): #@UnusedVariable # TODO Verify hitting cache < 1sec per invocation. # Since tvrage api is not injected, cannot mock season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('1', season) self.assertEqual('1', episode)
def test_getSeasonAndEpisode_When_match_not_found_using_original_airdate_Then_match_by_subtitle(self): # Given fields = { 'title' : u'WCG Ultimate Gamer', 'subtitle' : u'In The Crosshairs', 'starttime' : socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime' : socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate' : u'2010-09-20', # TVRage shows date as 2010-09-16 } program = RecordedProgram(data=pdata(fields,P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('2', season) self.assertEqual('5', episode)
def test_end_to_end_tvdb_flow(self): no_op = NoOpFanartProvider() tvdb = TvdbFanartProvider(self.platform) fileCache = FileCache(os.path.join(self.sandbox, 'http'), HttpResolver()) http = HttpCachingFanartProvider(fileCache, tvdb) superfast = SuperFastFanartProvider(self.platform, http, filename='tvdb') strike = OneStrikeAndYoureOutFanartProvider(self.platform, superfast, no_op, filename='tvdb') fields = { 'title': u'The Real World', 'subtitle': u'', 'starttime': socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate': u'2010-07-14' } #self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'24', u'3') program = RecordedProgram(data=pdata(fields), **self.deps) season, episode = strike.getSeasonAndEpisode(program) log.info(season) log.info(episode) self.assertEqual(('24', '3'), (season, episode)) method = 'getSeasonAndEpisode' # verify strikeout provider strikeKey = strike.createKey(method, program) self.assertFalse(strike.hasStruckOut(strikeKey)) # verify superfast provider superfastKey = superfast.createEpisodeKey(method, program) self.assertEqual(superfast.pcache[superfastKey], ('24', '3')) strike.close()
def test_getSeasonAndEpisode_NBCNightlyNews_returns_None_cuz_TVRage_throws_KeyError(self): # Given fields = { 'title' :u'NBC Nightly News', 'subtitle' :u'blah', 'starttime' :socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime' :socketDateTime(2008, 11, 4, 23, 50, 00), 'hasairdate' :1, 'airdate' :u'2010-07-14' } program = RecordedProgram(pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_pound_with_threads(self): max = 20 t = [] provider = TvRageProvider(self.platform) fields = { 'title' : u'Love and HipHop', 'subtitle' : u'', 'airdate' : u'2011-11-21', 'starttime' : socketDateTime(2011, 12, 8, 22, 00, 00), 'endtime' : socketDateTime(2011, 12, 8, 23, 00, 00), } program = RecordedProgram(data=pdata(fields), **self.deps) @run_async def doWork(provider): provider.getSeasonAndEpisode(program) for i in xrange(max): t.append(doWork(provider)) while t: t.pop().join()
def test_pound_with_threads(self): max = 20 t = [] provider = TvRageProvider(self.platform) fields = { 'title': u'Love and HipHop', 'subtitle': u'', 'airdate': u'2011-11-21', 'starttime': socketDateTime(2011, 12, 8, 22, 00, 00), 'endtime': socketDateTime(2011, 12, 8, 23, 00, 00), } program = RecordedProgram(data=pdata(fields), **self.deps) @run_async def doWork(provider): provider.getSeasonAndEpisode(program) for i in xrange(max): t.append(doWork(provider)) while t: t.pop().join()
def test_getSeasonAndEpisode_When_show_not_found_Then_returns_none(self): # Given fields = { 'title': u'Crap Crappity Crapola', 'starttime': socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 50, 00), 'hasairdate': 1, 'airdate': u'2010-08-03' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_getSeasonAndEpisode_When_show_not_found_Then_returns_none(self): # Setup fields = { 'title': u'This Show Does Not Exist', 'starttime': socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 45, 00), 'hasairdate': 1, 'airdate': u'2010-08-03' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=Mock(), protocol=P, conn=Mock()) provider = TvdbFanartProvider(self.platform, nextProvider=None) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNone(season) self.assertIsNone(episode)
def test_getSeasonAndEpisode_Success(self): # Given fields = { 'title': u'The Real World', 'starttime': socketDateTime(2008, 11, 4, 23, 45, 00), 'endtime': socketDateTime(2008, 11, 4, 23, 45, 00), 'hasairdate': 1, 'airdate': u'2010-07-14' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('24', season) self.assertEqual('3', episode)
def test_getSeasonAndEpisode_Success_HouseHunters(self): # Given fields = { 'title': u'House Hunters', 'starttime': socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime': socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate': u'2008-11-02' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When season, episode = provider.getSeasonAndEpisode(program) # Then self.assertEqual('30', season) self.assertEqual('2', episode)
def test_getSeasonAndEpisode_dont_blowup_when_a_season_is_missing(self): # Given fields = { 'title': u'The Daily Show With Jon Stewart', 'starttime': socketDateTime(2010, 12, 2, 22, 45, 00), 'endtime': socketDateTime(2010, 12, 2, 23, 50, 00), 'hasairdate': 1, 'airdate': u'2005-01-04' } program = RecordedProgram(data=pdata(fields, P.version()), settings=Mock(), translator=Mock(), platform=self.platform, protocol=P, conn=Mock()) provider = TvRageProvider(self.platform) # When -- Season 3 for The Daily Show with Jon Stewart is missing season, episode = provider.getSeasonAndEpisode(program) # Then self.assertIsNotNone(season) self.assertIsNotNone(episode)
def test_end_to_end_tvdb_flow(self): no_op = NoOpFanartProvider() tvdb = TvdbFanartProvider(self.platform) fileCache = FileCache(os.path.join(self.sandbox, 'http'), HttpResolver()) http = HttpCachingFanartProvider(fileCache, tvdb) superfast = SuperFastFanartProvider(self.platform, http, filename='tvdb') strike = OneStrikeAndYoureOutFanartProvider(self.platform, superfast, no_op, filename='tvdb') fields = { 'title' : u'The Real World', 'subtitle' : u'', 'starttime' : socketDateTime(2008, 11, 4, 22, 45, 00), 'endtime' : socketDateTime(2008, 11, 4, 23, 50, 00), 'airdate' : u'2010-07-14' } #self.assertSeasonAndEpisode(RecordedProgram(data=pdata(fields), **self.deps), u'24', u'3') program = RecordedProgram(data=pdata(fields), **self.deps) season, episode = strike.getSeasonAndEpisode(program) log.info(season) log.info(episode) self.assertEqual(('24','3'), (season, episode)) method = 'getSeasonAndEpisode' # verify strikeout provider strikeKey = strike.createKey(method, program) self.assertFalse(strike.hasStruckOut(strikeKey)) # verify superfast provider superfastKey = superfast.createEpisodeKey(method, program) self.assertEqual(superfast.pcache[superfastKey], ('24','3')) strike.close()