def test_subscribe(self): self.mock.StubOutWithMock(PodcastChannel, 'subscribe') PodcastChannel.subscribe('newurl.com') self.mock.ReplayAll() call_command('podcast', 'newurl.com', subscribe=True, stdout=self.stdout, stderr=self.stderr) self.mock.VerifyAll() self.assertEqual(len(self.stderr.lines), 0) self.assertEqual(len(self.stdout.lines), 0)
def test_subscribe_failed_request(self): self.mock.StubOutWithMock(PodcastChannel, 'subscribe') PodcastChannel.subscribe('newurl.com').AndRaise( requests.exceptions.RequestException) self.mock.ReplayAll() call_command('podcast', 'newurl.com', subscribe=True, stdout=self.stdout, stderr=self.stderr) self.mock.VerifyAll() self.assertEqual(len(self.stderr.lines), 1) self.assertEqual(len(self.stdout.lines), 0) self.assertEqual( self.stderr.lines[0], '"newurl.com" is not a valid url. Skipping.\n')
def test_subscribe_failed_request(self): self.mock.StubOutWithMock(PodcastChannel, 'subscribe') PodcastChannel.subscribe('newurl.com').AndRaise( requests.exceptions.RequestException) self.mock.ReplayAll() call_command('podcast', 'newurl.com', subscribe=True, stdout=self.stdout, stderr=self.stderr) self.mock.VerifyAll() self.assertEqual(len(self.stderr.lines), 1) self.assertEqual(len(self.stdout.lines), 0) self.assertEqual(self.stderr.lines[0], '"newurl.com" is not a valid url. Skipping.\n')
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 subscribe(self, *args, **options): for url in args: try: PodcastChannel.subscribe(url) except RequestException: self.stderr.write('"%s" is not a valid url. Skipping.' % url)