def test_an_editors_picks_data_source_should_should_not_barf_if_there_are_no_normal_results_in_the_response( self): fetcher = ApiStubFetcher() client = ApiClient('http://content.guardianapis.com/', API_KEY, fetcher=fetcher) data_source = SportDataSource(client) data = data_source.fetch_data() assert len(data) == 1
def test_a_search_data_source_should_know_how_to_process_response(self): fetcher = ApiStubFetcher() client = ApiClient('http://somewhere.com/', API_KEY, fetcher=fetcher) data_source = SearchDataSource(client) data = data_source.fetch_data() assert len(data) == 2 result = data[1] assert result.has_key('id') assert result.has_key('apiUrl') assert result.has_key('webPublicationDate') assert result.has_key('sectionName') assert result.has_key('webTitle') assert result.has_key('fields') assert result.has_key('sectionName')
def test_if_most_viewed_are_included_these_alone_should_be_returned(self): class TestMostViwedDataSource(ItemDataSource): def __init__(self, client): ItemDataSource.__init__(self, client, show_most_viewed=True) fetcher = ApiStubFetcher() client = ApiClient('http://somewhere.com/', API_KEY, fetcher=fetcher) data_source = TestMostViwedDataSource(client) data = data_source.fetch_data() self.assertEquals(len(data), 2) filtered_data = set([result['id'] for result in data]) self.assertEquals( filtered_data, set([ "uk/2012/dec/18/antarctic-territory-queen-cabinet", "world/2012/dec/17/white-house-obama-gun-control-newtown" ]))
def test_a_content_datasource_should_know_how_to_process_response(self): fetcher = ApiStubFetcher() client = ApiClient('http://somewhere.com/', API_KEY, fetcher=fetcher) data_source = ContentDataSource(client, 'i/am/a/short/url') data = data_source.fetch_data() assert len(data) == 1 result = data[0] assert result['id'] == 'content_1' assert result['sectionName'] == 'cif name' assert result['sectionId'] == 'cif' assert result['webTitle'] == 'Toynbee speaks' assert result['fields']['trailText'] == 'Stuff happened' assert result['fields']['headline'] == 'More stuff happened' assert result['fields']['thumbnail'] == "thumb piano" assert result['fields']['standfirst'] == "Stand by your man" assert result['fields']['byline'] == "Keith" assert result['fields']['liveBloggingNow'] == "false"
def test_should_append_blog_item_to_content_where_there_is_one_blog_entry( self): fetcher = ApiStubFetcher() client = ApiClient('http://content.guardianapis.com/', API_KEY, fetcher=fetcher) blog_data_source = ItemDataSource(client, '/i/want/a/blog/item') section_data_source = ItemDataSource(client, '/i/want/a/section') data_source = ItemPlusBlogDataSource(section_data_source, blog_data_source) data = data_source.fetch_data() assert len(data) == 4 result = data[0] assert result['id'] == 'blog id' assert result['sectionName'] == 'blog section name' assert result['sectionId'] == 'blog section id' result = data[1] assert result['id'] == 'section id' assert result['sectionName'] == 'Politics' assert result['sectionId'] == 'politics'
def test_an_editors_picks_data_source_should_know_how_to_process_response( self): class TestEditorsPicksDataSource(ItemDataSource): def __init__(self, client): ItemDataSource.__init__(self, client, show_editors_picks=True) fetcher = ApiStubFetcher() client = ApiClient('http://somewhere.com/', API_KEY, fetcher=fetcher) data_source = TestEditorsPicksDataSource(client) data = data_source.fetch_data() assert len(data) == 4 result = data[2] assert result.has_key('id') assert result.has_key('apiUrl') assert result.has_key('webPublicationDate') assert result.has_key('sectionName') assert result.has_key('webTitle') assert result.has_key('fields') assert result.has_key('sectionName') result = data[3] assert result[ 'id'] == 'sport/video/2013/jan/09/relay-runners-start-brawl-video'