Esempio n. 1
0
    def test_update_channels(self):
        channel1 = PodcastChannel()
        channel2 = PodcastChannel()
        qs = [channel1, channel2]

        self.mock.StubOutWithMock(channel1, 'update_channel')
        self.mock.StubOutWithMock(channel2, 'update_channel')
        channel1.update_channel()
        channel2.update_channel()

        self.mock.ReplayAll()
        self.admin.update_channels(self.request, qs)
        self.mock.VerifyAll()
Esempio n. 2
0
    def test_save_model(self):
        channel = PodcastChannel()
        self.mock.StubOutWithMock(channel, 'save')
        self.mock.StubOutWithMock(channel, 'update_channel')
        channel.save()
        channel.update_channel()

        self.mock.ReplayAll()
        self.admin.save_model(self.request, channel, None, None)
        self.mock.VerifyAll()
    def test_parse_cover_url_itunes_image(self):
        feed_content = '''
        <rss version="2.0" xmlns:itunes="http://www.itunes.com/podcast-1.0">
            <channel>
                <title>Fake Feed</title>
                <itunes:image href="http://example.com/feed.jpg" />
                <item><title>Episode 123</title></item>
            </channel>
        </rss>
        '''
        tree = etree.fromstring(feed_content).find('channel')

        self.assertEqual(PodcastChannel().parse_cover_url(tree),
                         'http://example.com/feed.jpg')
    def test_parse_cover_url_media_thumbnail(self):
        feed_content = '''
        <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
            <channel>
                <title>Fake Feed</title>
                <media:thumbnail url="http://example.com/feed.jpg" />
                <item><title>Episode 123</title></item>
            </channel>
        </rss>
        '''
        tree = etree.fromstring(feed_content).find('channel')

        self.assertEqual(PodcastChannel().parse_cover_url(tree),
                         'http://example.com/feed.jpg')
    def test_parse_cover_url_image_tage(self):
        feed_content = '''
        <rss version="2.0">
            <channel>
                <title>Fake Feed</title>
                <image>
                    <url>http://example.com/feed.jpg</url>
                </image>
                <item><title>Episode 123</title></item>
            </channel>
        </rss>
        '''
        tree = etree.fromstring(feed_content).find('channel')

        self.assertEqual(PodcastChannel().parse_cover_url(tree),
                         'http://example.com/feed.jpg')
    def test_update_channel(self):
        feed_content = '''
        <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
            <channel>
                <title>Fake Feed</title>
                <link>http://example.com</link>
                <description>This is a sample feed.</description>
                <copyright>All rights reserved.</copyright>
                <pubDate>Sun, 02 Sep 2012 18:17:35 -0700</pubDate>
                <category>Sample stuff</category>
                <category>News</category>
                <image>
                    <url>http://example.com/feed.jpg</url>
                </image>
                <item><title>Episode 123</title></item>
            </channel>
        </rss>
        '''
        feed_response = Struct(status_code=200,
                               ok=True,
                               content=feed_content,
                               url='http://test.com')
        self.mock.StubOutWithMock(requests, 'get')
        requests.get('http://test.com').AndReturn(feed_response)
        self.mock.StubOutWithMock(PodcastChannel, 'parse_cover_url')
        PodcastChannel.parse_cover_url(mox.IsA(
            etree._Element)).AndReturn('http://example.com/feed.jpg')
        self.mock.StubOutWithMock(PodcastChannel, 'save')
        PodcastChannel.save()
        self.mock.StubOutWithMock(PodcastChannel, 'update_items')
        PodcastChannel.update_items(mox.IsA(etree._Element), download=True)
        self.mock.StubOutWithMock(model_logger, 'info')
        model_logger.info('Updating Channel: Old Title')

        channel = PodcastChannel(url='http://test.com', title='Old Title')

        self.mock.ReplayAll()
        channel.update_channel(download=True)
        self.mock.VerifyAll()

        self.assertEqual(channel.title, 'Fake Feed')
        self.assertEqual(channel.description, 'This is a sample feed.')
        self.assertEqual(channel.cover_url, 'http://example.com/feed.jpg')
        self.assertEqual(channel.website, 'http://example.com')
        self.assertEqual(channel.copyright, 'All rights reserved.')
    def test_update_channel_bad_response(self):
        feed_response = Struct(status_code=404, ok=False, reason='404')
        self.mock.StubOutWithMock(requests, 'get')
        requests.get('http://test.com').AndReturn(feed_response)
        self.mock.StubOutWithMock(model_logger, 'info')
        model_logger.info('Updating Channel: http://test.com')
        self.mock.StubOutWithMock(model_logger, 'error')
        model_logger.error('Failed to retrieve feed. Status 404')
        self.mock.StubOutWithMock(PodcastChannel, 'parse_cover_url')
        self.mock.StubOutWithMock(PodcastChannel, 'save')
        self.mock.StubOutWithMock(PodcastChannel, 'update_items')
        channel = PodcastChannel(url='http://test.com')

        self.mock.ReplayAll()
        channel.update_channel(download=True)
        self.mock.VerifyAll()

        self.assertEqual(channel.title, '')
        self.assertEqual(channel.description, '')
        self.assertEqual(channel.cover_url, '')
    def test_unicode(self):
        channel = PodcastChannel(title='Fake Feed')
        item = PodcastItem(channel=channel, title='Episode 123')

        self.assertEqual(unicode(item), 'Fake Feed - Episode 123')
 def test_unicode_wo_title(self):
     channel = PodcastChannel(url='http://example.com')
     self.assertEqual(unicode(channel), u'http://example.com')
 def test_unicode(self):
     channel = PodcastChannel(url='http://example.com', title='Fake Feed')
     self.assertEqual(unicode(channel), u'Fake Feed')