Esempio n. 1
0
class HttpCachingFanartProviderTest(unittest.TestCase):
    def setUp(self):
        self.nextProvider = Mock()
        self.dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.dir, ignore_errors=True)
        self.httpCache = FileCache(self.dir, HttpResolver())
        self.program = TVProgram(
            {
                'title': 'Not Important',
                'category_type': 'series'
            },
            translator=Mock())
        self.provider = HttpCachingFanartProvider(self.httpCache,
                                                  self.nextProvider)
        self.addCleanup(self.provider.close)

    def test_getPosters_When_next_provider_returns_posters_Then_cache_and_return_first_poster_and_add_remaining_to_work_queue(
            self):
        httpUrls = [
            'http://www.gstatic.com/hostedimg/1f4337d461f1431c_large',
            'http://www.gstatic.com/hostedimg/50edad09a73fa0ed_large',
            'http://www.gstatic.com/hostedimg/d915322b880dcaf2_large',
            'http://www.gstatic.com/hostedimg/998ad397414e3727_large',
            'http://www.gstatic.com/hostedimg/ba55ddda30df5f96_large',
            'http://www.gstatic.com/hostedimg/7f0a19596a92fad1_large',
            'http://www.gstatic.com/hostedimg/8edb2dfe5ba34685_large',
            'http://www.gstatic.com/hostedimg/ffdb442e9f46a3c3_large'
        ]

        when(self.nextProvider).getPosters(any(Program)).thenReturn(httpUrls)

        # Test
        posters = self.provider.getPosters(self.program)

        # Verify
        log.debug('Posters= %s' % posters)
        self.assertEqual(1, len(posters))

        while len(posters) < len(httpUrls):
            time.sleep(1)
            log.debug('Images downloaded: %d' % len(posters))

    def test_getPosters_When_next_link_in_chain_returns_posters_Then_cache_locally_on_filesystem(
            self):
        # Setup
        when(self.nextProvider).getPosters(any(Program)).thenReturn(
            ['http://www.google.com/intl/en_ALL/images/logo.gif'])
        when(self.httpCache).get(any(str)).thenReturn('logo.gif')

        # Test
        posters = self.provider.getPosters(self.program)

        # Verify
        log.debug('Posters= %s' % posters)
        self.assertEqual('logo.gif', posters[0])

    def test_getPosters_When_next_link_in_chain_doesnt_find_posters_Then_dont_cache_anything(
            self):
        when(self.nextProvider).getPosters(any(Program)).thenReturn([])
        self.assertListEqual([], self.provider.getPosters(self.program))
Esempio n. 2
0
 def setUp(self):
     self.nextProvider = Mock()
     self.dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, self.dir, ignore_errors=True)
     self.httpCache = FileCache(self.dir, HttpResolver())
     self.program = TVProgram({'title': 'Not Important', 'category_type':'series'}, translator=Mock())
     self.provider = HttpCachingFanartProvider(self.httpCache, self.nextProvider)
     self.addCleanup(self.provider.close)
Esempio n. 3
0
class HttpCachingFanartProviderTest(unittest.TestCase):

    def setUp(self):
        self.nextProvider = Mock()
        self.dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.dir, ignore_errors=True)
        self.httpCache = FileCache(self.dir, HttpResolver())
        self.program = TVProgram({'title': 'Not Important', 'category_type':'series'}, translator=Mock())
        self.provider = HttpCachingFanartProvider(self.httpCache, self.nextProvider)
        self.addCleanup(self.provider.close)

    def test_getPosters_When_next_provider_returns_posters_Then_cache_and_return_first_poster_and_add_remaining_to_work_queue(self):
        httpUrls = [
            'http://www.gstatic.com/hostedimg/1f4337d461f1431c_large',
            'http://www.gstatic.com/hostedimg/50edad09a73fa0ed_large',
            'http://www.gstatic.com/hostedimg/d915322b880dcaf2_large',
            'http://www.gstatic.com/hostedimg/998ad397414e3727_large',
            'http://www.gstatic.com/hostedimg/ba55ddda30df5f96_large',
            'http://www.gstatic.com/hostedimg/7f0a19596a92fad1_large',
            'http://www.gstatic.com/hostedimg/8edb2dfe5ba34685_large',
            'http://www.gstatic.com/hostedimg/ffdb442e9f46a3c3_large']
             
        when(self.nextProvider).getPosters(any(Program)).thenReturn(httpUrls)
        
        # Test
        posters = self.provider.getPosters(self.program)
        
        # Verify
        log.debug('Posters= %s' % posters)
        self.assertEqual(1, len(posters))
        
        while len(posters) < len(httpUrls):
            time.sleep(1)
            log.debug('Images downloaded: %d' % len(posters))
        
    def test_getPosters_When_next_link_in_chain_returns_posters_Then_cache_locally_on_filesystem(self):
        # Setup
        when(self.nextProvider).getPosters(any(Program)).thenReturn(['http://www.google.com/intl/en_ALL/images/logo.gif'])
        when(self.httpCache).get(any(str)).thenReturn('logo.gif')
        
        # Test
        posters = self.provider.getPosters(self.program)
        
        # Verify
        log.debug('Posters= %s' % posters)
        self.assertEqual('logo.gif', posters[0])

    def test_getPosters_When_next_link_in_chain_doesnt_find_posters_Then_dont_cache_anything(self):
        when(self.nextProvider).getPosters(any(Program)).thenReturn([])
        self.assertListEqual([], self.provider.getPosters(self.program))
Esempio n. 4
0
 def setUp(self):
     self.nextProvider = Mock()
     self.dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, self.dir, ignore_errors=True)
     self.httpCache = FileCache(self.dir, HttpResolver())
     self.program = TVProgram({'title': 'Not Important', 'category_type':'series'}, translator=Mock())
     self.provider = HttpCachingFanartProvider(self.httpCache, self.nextProvider)
     self.addCleanup(self.provider.close)
Esempio n. 5
0
    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()