def test_short_url_must_be_specified_as_field_for_most_commented(self): class StubClient(object): actual_criteria = None def content_query(self, id, **criteria): self.actual_criteria = criteria return [] class StubFetcher(object): def fetch_most_commented(self, page_size): return [('yahoo', 3)] class StubInterpolator(object): def interpolate(self, content_list, comment_count_list): return [] stub_fetcher = StubFetcher() stub_client = StubClient() multi_content_data_source = MultiContentDataSource(client=stub_client, name='name') multi_content_data_source.content_ids = ['stuff'] most_commented_data_source = MostCommentedDataSource( multi_content_data_source=multi_content_data_source, comment_count_interpolator=StubInterpolator(), n_items=0, discussion_fetcher=stub_fetcher) most_commented_data_source.fetch_data() self.assertTrue('shortUrl' in stub_client.actual_criteria['show-fields'].split(','))
def test_should_return_interpolated_content(self): multi_content_data_source_stub = IdRememberingMultiContentDataSourceStub('client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource(n_items=12, multi_content_data_source=multi_content_data_source_stub, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) self.assertEquals(data_source.fetch_data(), list('Interpolated content'))
def test_data_source_should_fetch_each_piece_of_content_from_api(self): multi_content_data_source_stub = IdRememberingMultiContentDataSourceStub('client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource(n_items=12, multi_content_data_source=multi_content_data_source_stub, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertTrue(multi_content_data_source_stub.fetch_all_was_called)
def test_should_fetch_specified_number_of_items(self): multi_content_data_source = IdRememberingMultiContentDataSourceStub('client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource(n_items=23, multi_content_data_source=multi_content_data_source, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertEquals(discussion_fetcher.actual_page_size, 23)
def test_data_source_should_retrieve_most_commented_pieces_of_content(self): multi_content_data_source = IdRememberingMultiContentDataSourceStub('client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource(n_items=23, multi_content_data_source=multi_content_data_source, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertEquals(set(multi_content_data_source.content_ids), set(['cheese', 'egg', 'mouse']))
def test_data_source_should_fetch_each_piece_of_content_from_api(self): multi_content_data_source_stub = IdRememberingMultiContentDataSourceStub( 'client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource( n_items=12, multi_content_data_source=multi_content_data_source_stub, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertTrue(multi_content_data_source_stub.fetch_all_was_called)
def test_should_return_interpolated_content(self): multi_content_data_source_stub = IdRememberingMultiContentDataSourceStub( 'client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource( n_items=12, multi_content_data_source=multi_content_data_source_stub, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) self.assertEquals(data_source.fetch_data(), list('Interpolated content'))
def test_should_fetch_specified_number_of_items(self): multi_content_data_source = IdRememberingMultiContentDataSourceStub( 'client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource( n_items=23, multi_content_data_source=multi_content_data_source, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertEquals(discussion_fetcher.actual_page_size, 23)
def test_data_source_should_retrieve_most_commented_pieces_of_content( self): multi_content_data_source = IdRememberingMultiContentDataSourceStub( 'client') discussion_fetcher = StubDiscussionFetcher() discussion_fetcher.most_commented_short_urls_with_counts = most_commented_short_urls_with_counts data_source = MostCommentedDataSource( n_items=23, multi_content_data_source=multi_content_data_source, discussion_fetcher=discussion_fetcher, comment_count_interpolator=CommentCountInterpolatorStub()) data_source.fetch_data() self.assertEquals(set(multi_content_data_source.content_ids), set(['cheese', 'egg', 'mouse']))