Exemple #1
0
 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
Exemple #2
0
    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')
Exemple #3
0
    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"
            ]))
Exemple #4
0
    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"
Exemple #5
0
 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'
Exemple #6
0
    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'
import webapp2

from guardianapi.apiClient import ApiClient

import configuration
import handlers

# TODO: Hide me away somewhere warm and secret.
api_key = configuration.read('CAPI_KEY')
ophan_key = configuration.read('OPHAN_API_KEY')
base_url=configuration.read('CAPI_BASE_URL', 'https://content.guardianapis.com/')
ophan_base_url = configuration.read('OPHAN_BASE_URL')
discussion_base_url = 'https://discussion.guardianapis.com/discussion-api'

client = ApiClient(base_url, api_key, edition="uk")
clientUS = ApiClient(base_url, api_key, edition='us')
clientAUS = ApiClient(base_url, api_key, edition='au')

# Super dirty
# import now after the common functionality of this module is defined
# The result of script execution flow

import email_definitions as emails

app = webapp2.WSGIApplication([('/daily-email/(.+)', emails.uk.DailyEmail),
                               ('/daily-email-us/(.+)', emails.us.DailyEmailUS),
                               ('/daily-email-aus/(.+)', emails.au.DailyEmailAUS),
                               ('/australian-politics/(.+)', emails.au.Politics),
                               ('/australian-cif/(.+)', emails.au.CommentIsFree),
                               ('/australia-morning/(.+)', emails.au.Morning),
Exemple #8
0
DEBUG = False
DEFAULT_PAGE_SIZE = str(10)


class UrlCapturingFetcher(object):
    def get(self, url):
        self.actual_url = url
        return (
            None,
            '{"response": {"results": [], "editorsPicks": [], "mostViewed": []}}'
        )


fetcher = UrlCapturingFetcher()
url_capturing_client = ApiClient('http://content.guardianapis.com/',
                                 API_KEY,
                                 fetcher=fetcher)


class TestDataSources(unittest.TestCase):
    def quote_params(self, query_params):
        quoted_params = {}
        for key in query_params.keys():
            new_key = key.replace('_', '-')
            new_value = urllib.quote_plus(query_params[key])
            quoted_params[new_key] = new_value
        return quoted_params

    def compare_tags(self, expected_tags, actual_tags):
        actual_tag_set = set(actual_tags.split('%2C'))
        expected_tag_set = set(expected_tags.split('%2C'))
Exemple #9
0
import pysistence as immutable

import mail_renderer as mr
import handlers

import data_source as ds
import data_sources as dss

from guardianapi.apiClient import ApiClient

from container_api import container

client = ApiClient(mr.base_url, mr.api_key, edition="uk")


class FilmToday(handlers.EmailTemplate):
    recognized_versions = ['v1', 'v2', 'v3', 'v4']

    ad_tag = 'email-film-today'
    ad_config = immutable.make_dict({'leaderboard': 'Top'})

    film_today_latest = immutable.make_dict(
        {'film_today_latest': ds.FilmTodayLatestDataSource(client)})

    film_front = immutable.make_dict({
        'film_front':
        container.for_id('6d84cd8d-d159-4e9a-ba2f-8852528d2d03')
    })

    data_sources = immutable.make_dict({
        'v1': film_today_latest,