예제 #1
0
    def test_store_When_channel_has_icon_Then_download_icon(self):
        # Setup
        channels = filter(lambda x: x.getIconPath(), self.db.getChannels()
                          )  # filter out channels that don't have an icon
        self.assertTrue(
            len(channels) > 0, 'Channels with icon needed in db to run test')
        downloader = MythChannelIconResolver(self.conn)

        # Test - download icons for first 5 channels
        for channel in channels[:min(5, len(channels))]:
            if channel.getIconPath():
                dest = os.path.sep.join([
                    tempfile.gettempdir(),
                    'channel_' + str(channel.getChannelId()) +
                    channel.getCallSign() + str(time.time()) + '.png'
                ])
                downloader.store(channel, dest)

                # Verify
                log.debug('Downloaded %s to %s' %
                          (channel.getIconPath(), dest))
                self.assertTrue(os.path.exists(dest))
                self.assertTrue(os.path.isfile(dest))
                self.assertTrue(os.path.getsize(dest) > 0)

                # Cleanup
                os.remove(dest)
예제 #2
0
    def bootstrapCaches(self):
        self.stage = 'Initializing Caches'

        from mythbox.util import NativeTranslator
        from mythbox.filecache import FileCache, HttpResolver, MythThumbnailFileCache
        from mythbox.mythtv.resolver import MythChannelIconResolver, MythThumbnailResolver
        from os.path import join

        from mythbox.mythtv.cache import DomainCache
        self.domainCache = DomainCache(bus=self.bus)

        cacheDir = self.platform.getCacheDir()
        self.translator = NativeTranslator(self.platform.getScriptDir())
        self.mythThumbnailCache = MythThumbnailFileCache(
            join(cacheDir, 'thumbnail'), MythThumbnailResolver(), self.bus,
            self.domainCache)
        self.mythChannelIconCache = FileCache(join(cacheDir, 'channel'),
                                              MythChannelIconResolver())
        self.httpCache = FileCache(join(cacheDir, 'http'), HttpResolver())

        self.cachesByName = {
            'mythThumbnailCache': self.mythThumbnailCache,
            'mythChannelIconCache': self.mythChannelIconCache,
            'httpCache': self.httpCache,
            'domainCache': self.domainCache
        }
예제 #3
0
    def test_store_When_channel_has_no_icon_Then_do_nothing(self):
        # Setup
        channel = Channel({
            'name': 'Bogus Channel',
            'icon': None,
            'chanid': '9',
            'callsign': 'WXYZ'
        })
        conn = Mock()
        downloader = MythChannelIconResolver(conn)

        # Test
        downloader.store(channel, 'bogusDestDir')

        # Verify
        verifyZeroInteractions(conn)
예제 #4
0
    def test_store_When_channel_has_iconpath_but_filename_misspelled_Then_do_nothing(
            self):
        # Setup
        channel = Channel({
            'name': 'Bogus Channel',
            'icon': 'bogusIcon.png',
            'chanid': '9',
            'callsign': 'WXYZ'
        })
        downloader = MythChannelIconResolver(self.conn)

        # Test - download icons for first 5 channels
        dest = os.path.sep.join([
            tempfile.gettempdir(),
            str(channel.getChannelId()) + channel.getCallSign() +
            str(time.time()) + ".png"
        ])
        downloader.store(channel, dest)

        # Verify
        self.assertFalse(os.path.exists(dest))