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_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.')