当前位置: 首页>>代码示例>>Python>>正文


Python tests.LinkFactory类代码示例

本文整理汇总了Python中affiliates.links.tests.LinkFactory的典型用法代码示例。如果您正苦于以下问题:Python LinkFactory类的具体用法?Python LinkFactory怎么用?Python LinkFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LinkFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic

    def test_basic(self):
        """
        Aggregate any datapoints older than 90 days into the totals
        stored on their links.
        """
        link1 = LinkFactory.create(aggregate_link_clicks=7, aggregate_firefox_downloads=10)
        link1_old_datapoint = DataPointFactory.create(link=link1, date=aware_date(2014, 1, 1),
                                                      link_clicks=8, firefox_downloads=4)
        link1_new_datapoint = DataPointFactory.create(link=link1, date=aware_date(2014, 3, 1),
                                                      link_clicks=2, firefox_downloads=7)

        link2 = LinkFactory.create(aggregate_link_clicks=7, aggregate_firefox_downloads=10)
        link2_old_datapoint1 = DataPointFactory.create(link=link2, date=aware_date(2014, 1, 1),
                                                       link_clicks=8, firefox_downloads=4)
        link2_old_datapoint2 = DataPointFactory.create(link=link2, date=aware_date(2013, 12, 30),
                                                       link_clicks=2, firefox_downloads=7)

        self.command.handle()

        # link1 should have 7+8=15 clicks, 10+4=14 downloads, and the
        # new datapoint should still exist.
        link1 = Link.objects.get(pk=link1.pk)
        eq_(link1.aggregate_link_clicks, 15)
        eq_(link1.aggregate_firefox_downloads, 14)
        ok_(not DataPoint.objects.filter(pk=link1_old_datapoint.pk).exists())
        ok_(DataPoint.objects.filter(pk=link1_new_datapoint.pk).exists())

        # link2 should have 7+8+2=17 clicks, 10+4+7=21 downloads, and the
        # old datapoints should not exist.
        link2 = Link.objects.get(pk=link2.pk)
        eq_(link2.aggregate_link_clicks, 17)
        eq_(link2.aggregate_firefox_downloads, 21)
        ok_(not DataPoint.objects.filter(pk=link2_old_datapoint1.pk).exists())
        ok_(not DataPoint.objects.filter(pk=link2_old_datapoint2.pk).exists())
开发者ID:Balachan,项目名称:affiliates,代码行数:34,代码来源:test_management.py

示例2: test_not_authenticated

    def test_not_authenticated(self):
        """
        If the current user isn't authenticated, render the home
        page with the correct stats.
        """
        request = self.factory.get('/')
        request.user = Mock()
        request.user.is_authenticated.return_value = False

        # User count = 27 + 8 autogenerated via related factory
        # Click count = 64
        # Link count = 3 + 5 autogenerated via related factory
        UserFactory.create_batch(27)
        for clicks in (4, 6, 9, 10):
            DataPointFactory.create(link_clicks=clicks, date=date(2014, 4, 26))
        for clicks in (25, 5, 5):
            LinkFactory.create(aggregate_link_clicks=clicks)

        # Create a link with multiple datapoints to test for a faulty
        # join that would screw up the totals.
        link = LinkFactory.create()
        DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 26))
        DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 27))

        with patch('affiliates.base.views.render') as render:
            eq_(views.home(request), render.return_value)
            render.assert_called_with(request, 'base/home.html', {
                'affiliate_count': 35,
                'link_count': 8,
                'click_count': 78
            })
开发者ID:Balachan,项目名称:affiliates,代码行数:31,代码来源:test_views.py

示例3: test_links_filters

    def test_links_filters(self):
        category = CategoryFactory.create()
        user = UserFactory.create()

        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(
            banner__category=category)

        text_link = LinkFactory.create(banner_variation=text_banner_variation, user=user)
        LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(list(category.links(user=user)), [text_link])
开发者ID:stevenjenn,项目名称:affiliates,代码行数:12,代码来源:test_models.py

示例4: test_creation_milestone_close_to_next_milestone

    def test_creation_milestone_close_to_next_milestone(self):
        """
        If the user is within 1 link of the next milestone, return
        yesterday's date with the close_to_milestone message.
        """
        LinkFactory.create_batch(2, banner_type='test', user=self.user)
        self.display.surrounding_milestones.return_value = (None, 3)

        with patch('affiliates.base.milestones.date_yesterday') as date_yesterday:
            milestone = self.display.creation_milestone('test', self.messages)
            eq_(milestone, (date_yesterday.return_value, 'close_to_milestone_3'))

            self.display.surrounding_milestones.assert_called_with(
                2, self.display.creation_milestones)
开发者ID:hoosteeno,项目名称:affiliates,代码行数:14,代码来源:test_milestones.py

示例5: test_manager_total_link_clicks

    def test_manager_total_link_clicks(self):
        for clicks in (4, 6, 9, 10):  # = 29 clicks
            DataPointFactory.create(link_clicks=clicks, date=date(2014, 4, 26))
        for clicks in (25, 5, 5):  # = 35 clicks
            LinkFactory.create(aggregate_link_clicks=clicks)

        # Create a link with multiple datapoints to test for a faulty
        # join that would screw up the totals.
        link = LinkFactory.create()
        DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 26))
        DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 27))


        # 29 + 35 + 7 + 7 = 78 clicks
        eq_(Link.objects.total_link_clicks(), 78)
开发者ID:15776950506,项目名称:affiliates,代码行数:15,代码来源:test_models.py

示例6: test_get_queryset

    def test_get_queryset(self):
        """
        Available links should be limited to those owned by the current
        user.
        """
        request = self.factory.get('/')
        request.user = UserFactory.create()

        link1, link2 = LinkFactory.create_batch(2, user=request.user)
        unowned_link = LinkFactory.create()

        view = views.LinkDetailView()
        view.request = request
        qs = view.get_queryset()

        ok_(link1 in qs)
        ok_(link2 in qs)
        ok_(unowned_link not in qs)
开发者ID:glogiotatidis,项目名称:affiliates,代码行数:18,代码来源:test_views.py

示例7: test_add_click

    def test_add_click(self):
        request = self.factory.get('/')
        link = LinkFactory.create()

        with patch('affiliates.links.views.add_click') as add_click:
            with patch('affiliates.links.views.timezone') as timezone:
                timezone.now.return_value = aware_datetime(2014, 4, 7)

                self.view(request, pk=link.pk)
                add_click.delay.assert_called_with(link.id, date(2014, 4, 7))
开发者ID:15776950506,项目名称:affiliates,代码行数:10,代码来源:test_views.py

示例8: _link_with_clicks

 def _link_with_clicks(self, user, aggregate_link_clicks, link_click_counts):
     """
     Create a link with a specific number of aggregate links and
     datapoints with the given click counts.
     """
     start_date = aware_date(2014, 4, 1)
     link = LinkFactory.create(user=user, aggregate_link_clicks=aggregate_link_clicks)
     for link_clicks in link_click_counts:
         DataPointFactory.create(link=link, link_clicks=link_clicks, date=start_date)
         start_date += timedelta(1)
开发者ID:15776950506,项目名称:affiliates,代码行数:10,代码来源:test_management.py

示例9: test_rate_limiting

    def test_rate_limiting(self):
        request = self.factory.get('/')
        link = LinkFactory.create()


        with patch('affiliates.links.views.cache') as cache_patch:
            with patch('affiliates.links.views.add_click') as add_click:
                cache_patch.get.return_value = 3
                self.view(request, pk=link.pk)
                ok_(not add_click.delay.called)
开发者ID:glogiotatidis,项目名称:affiliates,代码行数:10,代码来源:test_views.py

示例10: test_get_metric_total

    def test_get_metric_total(self):
        """
        _get_metric_total should combine the aggregate data on the link
        and the data stored in multiple data points.
        """
        link = LinkFactory.create(aggregate_link_clicks=58)
        DataPointFactory.create(link=link, link_clicks=5, date=aware_date(2014, 1, 1))
        DataPointFactory.create(link=link, link_clicks=2, date=aware_date(2014, 1, 2))
        DataPointFactory.create(link=link, link_clicks=87, date=aware_date(2014, 1, 3))

        eq_(link._get_metric_total('link_clicks'), 58 + 5 + 2 + 87)
开发者ID:Balachan,项目名称:affiliates,代码行数:11,代码来源:test_models.py

示例11: test_links

    def test_links(self):
        """
        links should return a queryset of links related to any type of
        banner variation within the category.
        """
        category = CategoryFactory.create()

        # Test against several variations, and multiple variations.
        image_banner_variation1 = ImageBannerVariationFactory.create(banner__category=category)
        image_banner_variation2 = ImageBannerVariationFactory.create(banner__category=category)
        text_banner_variation = TextBannerVariationFactory.create(banner__category=category)
        upgrade_banner_variation = FirefoxUpgradeBannerVariationFactory.create(banner__category=category)

        # Create links from the variations.
        image_link1 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link2 = LinkFactory.create(banner_variation=image_banner_variation1)
        image_link3 = LinkFactory.create(banner_variation=image_banner_variation2)
        text_link = LinkFactory.create(banner_variation=text_banner_variation)
        upgrade_link = LinkFactory.create(banner_variation=upgrade_banner_variation)

        eq_(set([image_link1, image_link2, image_link3, text_link, upgrade_link]), set(category.links))
开发者ID:craigcook,项目名称:affiliates,代码行数:21,代码来源:test_models.py

示例12: test_basic

    def test_basic(self):
        category = CategoryFactory.create()
        banner1, banner2 = TextBannerFactory.create_batch(2, category=category)
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner1)
        link3, link4 = LinkFactory.create_batch(2, banner_variation__banner=banner2)

        # Set datapoint totals.
        self._datapoint(link1, 4)
        self._datapoint(link1, 4)
        self._datapoint(link2, 3)
        self._datapoint(link2, 3)
        self._datapoint(link3, 2)
        self._datapoint(link3, 2)
        self._datapoint(link4, 1)
        self._datapoint(link4, 1)

        # Assert that data hasn't been denormalized yet.
        eq_(link1.link_clicks, 0)
        eq_(link2.link_clicks, 0)
        eq_(link3.link_clicks, 0)
        eq_(link4.link_clicks, 0)
        eq_(banner1.link_clicks, 0)
        eq_(banner2.link_clicks, 0)
        eq_(category.link_clicks, 0)

        self.command.handle()

        # Re-fetch data now that is has updated
        category = Category.objects.get(pk=category.pk)
        banner1, banner2 = TextBanner.objects.order_by('id')
        link1, link2, link3, link4 = Link.objects.order_by('id')

        # Assert that counts are now denormalized.
        eq_(link1.link_clicks, 8)
        eq_(link2.link_clicks, 6)
        eq_(link3.link_clicks, 4)
        eq_(link4.link_clicks, 2)
        eq_(banner1.link_clicks, 14)
        eq_(banner2.link_clicks, 6)
        eq_(category.link_clicks, 20)
开发者ID:15776950506,项目名称:affiliates,代码行数:40,代码来源:test_management.py

示例13: test_not_authenticated

    def test_not_authenticated(self):
        """
        If the current user isn't authenticated, render the home
        page with the correct stats.
        """
        request = self.factory.get('/')
        request.user = Mock()
        request.user.is_authenticated.return_value = False

        # User count = 27 + 3 autogenerated via related factory
        # Link count = 3 autogenerated via related factory
        UserFactory.create_batch(27)
        LinkFactory.create_batch(3)


        with patch('affiliates.base.views.render') as render:
            with patch.object(Link.objects, 'total_link_clicks', return_value=64):
                eq_(views.home(request), render.return_value)
                render.assert_called_with(request, 'base/home.html', {
                    'affiliate_count': 30,
                    'link_count': 3,
                    'click_count': 64
                })
开发者ID:Acidburn0zzz,项目名称:affiliates,代码行数:23,代码来源:test_views.py

示例14: test_success

    def test_success(self):
        link1, link2 = LinkFactory.create_batch(2)
        self.service.get_clicks_for_date.return_value = {
            unicode(link1.pk): '4',
            unicode(link2.pk): '7'
        }
        yesterday = aware_datetime(2014, 1, 1).date()

        with patch.object(collect_ga_data, 'date_yesterday') as date_yesterday:
            date_yesterday.return_value = yesterday
            self.command.execute()

        self.service.get_clicks_for_date.assert_called_with(yesterday)
        ok_(link1.datapoint_set.filter(date=yesterday, link_clicks=4).exists())
        ok_(link2.datapoint_set.filter(date=yesterday, link_clicks=7).exists())
开发者ID:hoosteeno,项目名称:affiliates,代码行数:15,代码来源:test_management.py

示例15: test_creation_milestone_no_previous_links_created

    def test_creation_milestone_no_previous_links_created(self):
        """
        If there is no previous milestone, but the user has created at
        least one link (which is normally impossible, as the default
        milestones start at 1), show when their last link was created.
        """
        links = LinkFactory.create_batch(2, banner_type='test', user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 2, 8)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (None, 5)

        milestone = self.display.creation_milestone('test', self.messages)
        eq_(milestone, (aware_date(2014, 1, 2), 'link_created'))
开发者ID:hoosteeno,项目名称:affiliates,代码行数:16,代码来源:test_milestones.py


注:本文中的affiliates.links.tests.LinkFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。