Example #1
0
    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_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_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_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(','))
Example #5
0
 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))
Example #6
0
    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)