def test_should_be_able_to_specify_a_section_in_most_popular(self):
        target_section = 'commentisfree'
        fetcher = MostSharedFetcher(self.stub_client, section=target_section)
        params = fetcher.build_params(120)

        self.assertTrue('section' in params, 'Section is not present in the params')
        self.assertEquals(target_section, params['section'])
    def test_should_be_able_to_specify_a_section_in_most_popular(self):
        target_section = 'commentisfree'
        fetcher = MostSharedFetcher(self.stub_client, section=target_section)
        params = fetcher.build_params(120)

        self.assertTrue('section' in params,
                        'Section is not present in the params')
        self.assertEquals(target_section, params['section'])
    def test_most_shared_fetcher_should_return_list_of_paths_and_share_counts(self):
        stub_client = StubClient()
        fetcher = MostSharedFetcher(stub_client)
        actual_data = fetcher.fetch_most_shared(age=12000)

        expected_data = [(u'/lifeandstyle/2012/feb/01/top-five-regrets-of-the-dying', 24037),
                         (u'/world/2013/jun/03/turkey-new-york-times-ad', 19086)]
        self.assertEquals(expected_data, actual_data)
    def test_most_shared_fetcher_should_return_list_of_paths_and_share_counts(
            self):
        stub_client = StubClient()
        fetcher = MostSharedFetcher(stub_client)
        actual_data = fetcher.fetch_most_shared(age=12000)

        expected_data = [
            (u'/lifeandstyle/2012/feb/01/top-five-regrets-of-the-dying',
             24037), (u'/world/2013/jun/03/turkey-new-york-times-ad', 19086)
        ]
        self.assertEquals(expected_data, actual_data)
Example #5
0
class CommentIsFree(handlers.EmailTemplate):
    recognized_versions = ['v1']

    most_shared_data_source = ds.MostSharedDataSource(
        most_shared_fetcher=MostSharedFetcher(ophan_client,
                                              section='commentisfree',
                                              country='au'),
        multi_content_data_source=ds.MultiContentDataSource(
            client=mr.client, name='most_shared'),
        shared_count_interpolator=ds.MostSharedCountInterpolator(),
        result_decorator=partial(add_comment_counts, discussion_client))

    data_sources = immutable.make_dict({
        'v1': {
            'cif_most_shared': most_shared_data_source,
        },
    })

    priority_list = immutable.make_dict({
        'v1': [
            ('cif_most_shared', 5),
        ],
    })

    template_names = immutable.make_dict({
        'v1': 'au/comment-is-free/v1',
    })
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()
			),
		},
	}
Example #7
0
class CommentIsFree(handlers.EmailTemplate):
    recognized_versions = immutable.make_list('v1', 'v2', 'v3')

    ad_tag = 'email-speakers-corner'
    ad_config = {'leaderboard': 'Top'}

    ophan_client = OphanClient(mr.ophan_base_url, mr.ophan_key)
    most_shared_data_source = ds.MostSharedDataSource(
        most_shared_fetcher=MostSharedFetcher(ophan_client,
                                              section='commentisfree'),
        multi_content_data_source=ds.MultiContentDataSource(
            client=client, name='most_shared'),
        shared_count_interpolator=ds.MostSharedCountInterpolator())

    discussion_client = DiscussionClient(mr.discussion_base_url)
    most_commented_data_source = ds.MostCommentedDataSource(
        discussion_fetcher=DiscussionFetcher(discussion_client,
                                             'commentisfree'),
        multi_content_data_source=ds.MultiContentDataSource(
            client=client, name='most_commented'),
        comment_count_interpolator=ds.CommentCountInterpolator())

    data_sources = immutable.make_dict({
        'v1': {
            'uk_opinion_front':
            container.for_id('uk/commentisfree/regular-stories'),
            'cif_cartoon':
            ds.CommentIsFreeCartoonDataSource(client),
        },
        'v3': {
            'cif_most_shared': most_shared_data_source,
            'cif_cartoon': ds.CommentIsFreeCartoonDataSource(client),
        },
        'v2': {
            'cif_most_commented': most_commented_data_source,
            'cif_cartoon': ds.CommentIsFreeCartoonDataSource(client),
        }
    })

    priority_list = {
        'v3': [('cif_cartoon', 1), ('cif_most_shared', 5)],
        'v2': [('cif_cartoon', 1), ('cif_most_commented', 5)],
        'v1': [
            ('uk_opinion_front', 10),
            ('cif_cartoon', 1),
        ],
    }

    template_names = immutable.make_dict({
        'v3': 'comment-is-free/v3',
        'v2': 'comment-is-free/v2',
        'v1': 'comment-is-free/v1',
    })
class TestMostSharedUrlBuilding(unittest.TestCase):
    def setUp(self):
        self.stub_client = StubClient()
        self.fetcher = MostSharedFetcher(self.stub_client)

    def test_should_be_able_to_specify_countries_in_most_popular(self):
        fetcher = MostSharedFetcher(self.stub_client, country='us')
        params = fetcher.build_params(120)

        self.assertTrue('country' in params, 'Country not present in params')
        self.assertEquals('us', params['country'])

    def test_should_be_able_to_specify_a_section_in_most_popular(self):
        target_section = 'commentisfree'
        fetcher = MostSharedFetcher(self.stub_client, section=target_section)
        params = fetcher.build_params(120)

        self.assertTrue('section' in params,
                        'Section is not present in the params')
        self.assertEquals(target_section, params['section'])

    def test_should_build_correct_url_for_ophan_call(self):

        self.fetcher.fetch_most_shared(age=12000)

        parsed_url = urlparse.urlparse(self.stub_client.actual_url)
        self.assertEquals(parsed_url[2], 'base/api/viral')

        params = urlparse.parse_qs(parsed_url[4])

        for key, value in [
            ('mins', '200'),
            ('referrer', 'social media'),
            ('api-key', 'iamakeyandigetinforfree'),
        ]:
            self.assertTrue(
                key in params,
                "{key} not present in parameters: {param_string}".format(
                    key=key, param_string=params.keys()))
            self.assertEquals(value, params[key][0])
Example #9
0
class Opinion(handlers.EmailTemplate):
    recognized_versions = ['v1', 'v2', 'v3']

    most_shared_data_source = ds.MostSharedDataSource(
        most_shared_fetcher=MostSharedFetcher(ophan_client,
                                              section='commentisfree',
                                              country='us'),
        multi_content_data_source=ds.MultiContentDataSource(
            client=mr.client, name='most_shared'),
        shared_count_interpolator=ds.MostSharedCountInterpolator(),
        result_decorator=partial(add_comment_counts, discussion_client))

    latest_us_opinion = dss.general.ItemDataSource('us/commentisfree',
                                                   production_office='us')

    data_sources = immutable.make_dict({
        'v1': {
            'cif_most_shared': most_shared_data_source,
        },
        'v2': {
            'cif_most_shared': most_shared_data_source,
            'us_opinion':
            container.for_id('us-alpha/contributors/feature-stories')
        },
        'v3': {
            'cif_most_shared': most_shared_data_source,
            'latest_us_opinion': latest_us_opinion,
        }
    })

    priority_list = immutable.make_dict({
        'v1': [
            ('cif_most_shared', 5),
        ],
        'v2': [
            ('us_opinion', 3),
            ('cif_most_shared', 5),
        ],
        'v3': [
            ('cif_most_shared', 2),
            ('latest_us_opinion', 3),
        ]
    })

    template_names = immutable.make_dict({
        'v1': 'us/opinion/v1',
        'v2': 'us/opinion/v2',
        'v3': 'us/opinion/v3',
    })
class TestMostSharedUrlBuilding(unittest.TestCase):

    def setUp(self):
        self.stub_client = StubClient()
        self.fetcher = MostSharedFetcher(self.stub_client)

    def test_should_be_able_to_specify_countries_in_most_popular(self):
        fetcher = MostSharedFetcher(self.stub_client, country='us')
        params = fetcher.build_params(120)

        self.assertTrue('country' in params, 'Country not present in params')
        self.assertEquals('us', params['country'])

    def test_should_be_able_to_specify_a_section_in_most_popular(self):
        target_section = 'commentisfree'
        fetcher = MostSharedFetcher(self.stub_client, section=target_section)
        params = fetcher.build_params(120)

        self.assertTrue('section' in params, 'Section is not present in the params')
        self.assertEquals(target_section, params['section'])

    def test_should_build_correct_url_for_ophan_call(self):

        self.fetcher.fetch_most_shared(age=12000)

        parsed_url = urlparse.urlparse(self.stub_client.actual_url)
        self.assertEquals(parsed_url[2], 'base/api/viral')

        params = urlparse.parse_qs(parsed_url[4])

        for key, value in [('mins', '200'),
            ('referrer', 'social media'),
            ('api-key', 'iamakeyandigetinforfree'),]:
            self.assertTrue(key in params, "{key} not present in parameters: {param_string}".format(key=key,
                param_string=params.keys()))
            self.assertEquals(value, params[key][0])
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_should_be_able_to_specify_countries_in_most_popular(self):
        fetcher = MostSharedFetcher(self.stub_client, country='us')
        params = fetcher.build_params(120)

        self.assertTrue('country' in params, 'Country not present in params')
        self.assertEquals('us', params['country'])
 def setUp(self):
     self.stub_client = StubClient()
     self.fetcher = MostSharedFetcher(self.stub_client)
 def setUp(self):
     self.stub_client = StubClient()
     self.fetcher = MostSharedFetcher(self.stub_client)
Example #15
0
class DailyEmailUS(handlers.EmailTemplate):
    minify = True
    cache_bust = False

    recognized_versions = immutable.make_list('v1', 'v3', 'v6', 'v7', 'v2015',
                                              'v2015_v2', 'v2015_v3',
                                              'v2015_v4', 'categories_us')

    ad_tag = 'email-guardian-today-us'
    ad_config = {'leaderboard_v1': 'Top', 'leaderboard_v2': 'Bottom'}

    base_data_sources = immutable.make_dict({
        'business':
        ds.BusinessDataSource(clientUS),
        'technology':
        dss.technology.TechnologyDataSource(clientUS),
        'sport':
        dss.us.SportUSDataSource(clientUS),
        'comment':
        ds.CommentIsFreeDataSource(clientUS),
        'culture':
        ds.CultureDataSource(clientUS),
        'top_stories':
        ds.TopStoriesDataSource(clientUS),
        'video':
        ds.VideoDataSource(clientUS),
    })

    most_shared_us = ds.MostSharedDataSource(
        most_shared_fetcher=MostSharedFetcher(ophan_client, country='us'),
        multi_content_data_source=ds.MultiContentDataSource(
            client=clientUS, name='most_shared_us'),
        shared_count_interpolator=ds.MostSharedCountInterpolator())

    breaking = container.for_front('us',
                                   'breaking',
                                   additional_capi_params=immutable.make_dict(
                                       {"show-elements": "image"}))
    canonical = container.for_front('us',
                                    'canonical',
                                    additional_capi_params=immutable.make_dict(
                                        {"show-elements": "image"}))
    special = container.for_front('us',
                                  'special',
                                  additional_capi_params=immutable.make_dict(
                                      {"show-elements": "image"}))

    data_sources = immutable.make_dict({
        'v1':
        base_data_sources,
        'v3':
        base_data_sources,
        'v6':
        base_data_sources.using(most_shared_us=most_shared_us),
        'v7':
        base_data_sources.using(most_shared_us=most_shared_us),
        'v2015':
        base_data_sources.using(most_shared_us=most_shared_us),
        'v2015_v2':
        base_data_sources.using(most_shared_us=most_shared_us),
        'v2015_v3':
        base_data_sources.using(most_shared_us=most_shared_us),
        'v2015_v4':
        base_data_sources.using(most_shared_us=most_shared_us),
        'categories_us':
        base_data_sources.using(breaking=breaking,
                                canonical=canonical,
                                special=special,
                                most_shared_us=most_shared_us)
    })

    base_priorities = immutable.make_list(
        ('top_stories', 6),
        ('video', 3),
        ('sport', 3),
        ('comment', 3),
        ('culture', 3),
        ('business', 2),
        ('technology', 2),
    )

    priority_list = immutable.make_dict({
        'v1':
        base_priorities,
        'v3':
        base_priorities,
        'v6':
        base_priorities.cons(('most_shared_us', 6), ),
        'v7':
        base_priorities.without(('business', 2)).cons(
            ('most_shared_us', 6)).cons(('business', 3)),
        'v2015':
        base_priorities.cons(('most_shared_us', 6)),
        'v2015_v2':
        base_priorities.cons(('most_shared_us', 6)),
        'v2015_v3':
        base_priorities.cons(('most_shared_us', 6)),
        'v2015_v4':
        base_priorities.cons(('most_shared_us', 6)),
        'categories_us':
        immutable.make_list(('breaking', 5), ('canonical', 6), ('special', 1),
                            ('most_shared_us', 6)).concat(base_priorities)
    })

    template_names = immutable.make_dict({
        'v1':
        'us/daily/v1',
        'v3':
        'us/daily/v3',
        'v6':
        'us/daily/v6',
        'v7':
        'us/daily/v7',
        'v2015':
        'us/daily/v2015',
        'v2015_v2':
        'us/daily/v2015_v2',
        'v2015_v3':
        'us/daily/v2015_v3',
        'v2015_v4':
        'us/daily/v2015_v4',
        'categories_us':
        'us/daily/categories_us'
    })
    def test_should_be_able_to_specify_countries_in_most_popular(self):
        fetcher = MostSharedFetcher(self.stub_client, country='us')
        params = fetcher.build_params(120)

        self.assertTrue('country' in params, 'Country not present in params')
        self.assertEquals('us', params['country'])
Example #17
0
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()
	)