def test_source_when_typical_then_should_display_stories(self, mock_output, mock_fetch_and_format): news_list = [(create_news()), (create_news())] mock_fetch_and_format.return_value = news_list source_name = "hacker-news" self._runner.invoke(self._cli, ["source", source_name]) mock_output.assert_has_calls([call(news_list), call().write_to(file_name=None)])
def test_fetch_should_call_fetch_method_for_all_sources(self, mock_hn_fetch, mock_reddit_fetch): news1 = create_news() news2 = create_news() mock_hn_fetch.return_value = [news1] mock_reddit_fetch.return_value = [news2] news_list = self._source.fetch() self.assertEqual(2, len(news_list)) self.assertIn(news1, news_list) self.assertIn(news2, news_list) mock_hn_fetch.assert_called_once_with() mock_reddit_fetch.assert_called_once_with()
def test_format(self): news = create_news(source=None) formatter = ListNewsFormatter([news]) output = formatter.format() self.assertEqual( ("\n" + "\t1. Title: %s\n" + "\t Published At: %s\n" + "\t Source: %s\n") % (news.title, news.published_at.strftime('%Y-%m-%dT%H:%M:%SZ'), news.source), output)
def test_format_when_news_has_urls(self): url = "http://example.com/thistest" news = create_news(url=url) formatter = ListNewsFormatter([news]) output = formatter.format() self.assertEqual( ("\n" + "\t1. Title: %s\n" + "\t Published At: %s\n" + "\t URL: %s\n" + "\t Source: %s\n") % (news.title, news.published_at.strftime('%Y-%m-%dT%H:%M:%SZ'), url, news.source), output)
def test_format_when_news_has_tags(self): tags = ["python", "click"] news = create_news(tags=tags) formatter = ListNewsFormatter([news]) output = formatter.format() self.assertEqual( ("\n" + "\t1. Title: %s\n" + "\t Published At: %s\n" + "\t Tags: %s\n" "\t Source: %s\n") % (news.title, news.published_at.strftime('%Y-%m-%dT%H:%M:%SZ'), ", ".join(tags), news.source), output)
def setUp(self): self._news = create_news() self._news_list = [self._news] self._formatter = JsonNewsFormatter(self._news_list)
def test_set_news_list(self): new_news_list = [create_news(), create_news()] self._formatter.news_list = new_news_list self.assertEqual(new_news_list, self._formatter.news_list)
def setUp(self): self._news_list = [create_news()] self._formatter = NewsFormatter(self._news_list)