def test_multi_content_data_source_should_return_data_in_correct_format(self): client = ContentIdRememberingStubClient() id_list = ['cat', 'spoon', 'mouse', 'dog'] data_source = MultiContentDataSource(client=client, name='name') data_source.content_ids = id_list data = data_source.fetch_data() expected_content = {u'apiUrl': u'http://content.guardianapis.com/technology/gamesblog/2013/apr/09/press-start-game-news', u'fields': {u'byline': u'Keith', u'commentable': u'true', u'headline': u'More stuff happened', u'liveBloggingNow': u'false', u'standfirst': u'Stand by your man', u'thumbnail': u'thumb piano', u'trailText': u'Stuff happened'}, u'id': u'content_1', u'sectionId': u'cif', u'sectionName': u'cif name', u'webPublicationDate': u'2013-04-09T07:00:09Z', u'webTitle': u'Toynbee speaks', u'webUrl': u'http://www.theguardian.com/technology/gamesblog/2013/apr/09/press-start-game-news'} expected_data = [] for i in range(4): expected_data.append(expected_content) self.assertEquals(expected_data, data)
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_multi_content_data_source_should_retrieve_content_for_each_of_the_supplied_ids(self): client = ContentIdRememberingStubClient() id_list = ['cat', 'spoon', 'mouse', 'dog'] data_source = MultiContentDataSource(client=client, name='test_thing') data_source.content_ids = id_list data_source.fetch_data() self.assertEquals(set(client.content_ids), set(id_list))
def test_multi_content_data_source_should_retrieve_content_for_each_of_the_supplied_ids( self): client = ContentIdRememberingStubClient() id_list = ['cat', 'spoon', 'mouse', 'dog'] data_source = MultiContentDataSource(client=client, name='test_thing') data_source.content_ids = id_list data_source.fetch_data() self.assertEquals(set(client.content_ids), set(id_list))
def mostPopularByTag(client, ophan_client, keywordTag): return OphanDataSource(client=client, multi_content_data_source=MultiContentDataSource( client=client, name='most_popular_by_tag'), fetcher=MostPopularByTagFetcher( ophan_client, keywordTag=keywordTag), n_items=4)
class MostSharedUS(MostShared): data_sources = { 'v1' : { 'most_shared': MostSharedDataSource( most_shared_fetcher=MostSharedFetcher(ophan_client, country='us'), multi_content_data_source=MultiContentDataSource(client=mr.client, name='most_shared'), shared_count_interpolator=MostSharedCountInterpolator() ), }, }
def test_multi_content_data_source_should_return_data_in_correct_format( self): client = ContentIdRememberingStubClient() id_list = ['cat', 'spoon', 'mouse', 'dog'] data_source = MultiContentDataSource(client=client, name='name') data_source.content_ids = id_list data = data_source.fetch_data() expected_content = { u'apiUrl': u'http://content.guardianapis.com/technology/gamesblog/2013/apr/09/press-start-game-news', u'fields': { u'byline': u'Keith', u'commentable': u'true', u'headline': u'More stuff happened', u'liveBloggingNow': u'false', u'standfirst': u'Stand by your man', u'thumbnail': u'thumb piano', u'trailText': u'Stuff happened' }, u'id': u'content_1', u'sectionId': u'cif', u'sectionName': u'cif name', u'webPublicationDate': u'2013-04-09T07:00:09Z', u'webTitle': u'Toynbee speaks', u'webUrl': u'http://www.theguardian.com/technology/gamesblog/2013/apr/09/press-start-game-news' } expected_data = [] for i in range(4): expected_data.append(expected_content) self.assertEquals(expected_data, data)
class MostShared(handlers.EmailTemplate): recognized_versions = ['v1'] n_items = 6 most_shared_fetcher = MostSharedFetcher(ophan_client) multi_content_data_source = MultiContentDataSource(client=mr.client, name='most_shared') shared_count_interpolator = MostSharedCountInterpolator() most_shared_data_source = MostSharedDataSource( most_shared_fetcher=most_shared_fetcher, multi_content_data_source=multi_content_data_source, shared_count_interpolator=shared_count_interpolator ) data_sources = {} data_sources['v1'] = { 'most_shared': most_shared_data_source } ad_tag = '' ad_config = {} priority_list = {'v1': [('most_shared', n_items)]} template_names = {'v1': 'most-shared'}
def test_multi_content_data_source_should_barf_if_content_ids_is_left_unset(self): data_source = MultiContentDataSource('cheese_client', 'cheese_name') with self.assertRaises(DataSourceException): data_source.fetch_data()
def most_shared(client, ophan_client, country): return MostSharedDataSource( most_shared_fetcher=MostSharedFetcher(ophan_client, country=country), multi_content_data_source=MultiContentDataSource(client=client, name='most_shared'), shared_count_interpolator=MostSharedCountInterpolator() )