def test_subscribe(self): self.mock.StubOutWithMock(PodcastChannel, 'update_channel') PodcastChannel.update_channel() self.mock.ReplayAll() sub_channel = PodcastChannel.subscribe('http://test.com') self.mock.VerifyAll() self.assertEqual(sub_channel.url, 'http://test.com')
def test_subscribe(self): self.mock.StubOutWithMock(PodcastChannel, 'update_channel') PodcastChannel.update_channel() self.mock.ReplayAll() sub_channel = PodcastChannel.subscribe('http://test.com') self.mock.VerifyAll() self.assertEqual(sub_channel.url, 'http://test.com')
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_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_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()
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()
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(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_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, '')