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


Python LinkFactory.create_batch方法代码示例

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


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

示例1: test_creation_milestone_close_to_next_milestone

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:16,代码来源:test_milestones.py

示例2: test_basic

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:42,代码来源:test_management.py

示例3: test_not_authenticated

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:25,代码来源:test_views.py

示例4: test_success

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:17,代码来源:test_management.py

示例5: test_default_yesterday

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_default_yesterday(self):
        """When no date is given, fetch data for the two days ago."""
        link1, link2 = LinkFactory.create_batch(2)
        self.service.get_clicks_for_date.return_value = {
            unicode(link1.pk): '4',
            unicode(link2.pk): '7'
        }
        two_days_ago = aware_date(2014, 1, 1)

        with patch.object(collect_ga_data, 'timezone') as mock_timezone:
            mock_timezone.now.return_value = aware_date(2014, 1, 3)
            self.command.execute()

        self.service.get_clicks_for_date.assert_called_with(two_days_ago)
        eq_(link1.datapoint_set.get(date=two_days_ago).link_clicks, 4)
        eq_(link2.datapoint_set.get(date=two_days_ago).link_clicks, 7)
开发者ID:15776950506,项目名称:affiliates,代码行数:18,代码来源:test_management.py

示例6: test_integrity_error_bulk_create

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_integrity_error_bulk_create(self):
        """
        If an IntegrityError is raised during bulk_create, raise a
        CommandError.
        """
        link1, link2 = LinkFactory.create_batch(2)
        self.service.get_clicks_for_date.return_value = {
            unicode(link1.pk): '4',
            unicode(link2.pk): '7'
        }

        with patch.object(collect_ga_data, 'DataPoint') as MockDataPoint:
            MockDataPoint.objects.bulk_create.side_effect = IntegrityError

            with self.assertRaises(CommandError):
                self.command.execute()
开发者ID:hoosteeno,项目名称:affiliates,代码行数:18,代码来源:test_management.py

示例7: test_creation_milestone_no_previous_links_created

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:18,代码来源:test_milestones.py

示例8: test_creation_milestone_no_next_milestone

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_creation_milestone_no_next_milestone(self):
        """
        If there is no next milestone, show the date of their last
        milestone.
        """
        links = LinkFactory.create_batch(4, banner_type='test', user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 1, 8)
        links[2].created = aware_datetime(2014, 1, 2, 5)  # Winner!
        links[3].created = aware_datetime(2014, 1, 3, 5)
        for link in links:
            link.save()

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

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

示例9: test_creation_milestone_far_from_next_milestone

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_creation_milestone_far_from_next_milestone(self):
        """
        If the user isn't close to the next milestone, show the date of
        their last milestone.
        """
        variation = TextBannerVariationFactory.create()
        links = LinkFactory.create_batch(4, banner_variation=variation, user=self.user)
        links[0].created = aware_datetime(2014, 1, 1, 5)
        links[1].created = aware_datetime(2014, 1, 1, 8)
        links[2].created = aware_datetime(2014, 1, 2, 5)  # Winner!
        links[3].created = aware_datetime(2014, 1, 3, 5)
        for link in links:
            link.save()

        self.display.surrounding_milestones.return_value = (3, 10)

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

示例10: test_get_queryset

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    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,代码行数:20,代码来源:test_views.py

示例11: test_date_argument_today

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_date_argument_today(self):
        """
        If the date argument is the word 'today', set the query date to
        the current date.
        """
        link1, link2 = LinkFactory.create_batch(2)
        self.service.get_clicks_for_date.return_value = {
            unicode(link1.pk): '4',
            unicode(link2.pk): '7'
        }
        today = aware_datetime(2014, 1, 2).date()

        with patch.object(collect_ga_data, 'timezone') as mock_timezone:
            mock_timezone.now.return_value = aware_datetime(2014, 1, 2)
            self.command.execute('today')

        self.service.get_clicks_for_date.assert_called_with(today)
        eq_(link1.datapoint_set.get(date=today).link_clicks, 4)
        eq_(link2.datapoint_set.get(date=today).link_clicks, 7)
开发者ID:15776950506,项目名称:affiliates,代码行数:21,代码来源:test_management.py

示例12: test_date_argument

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_date_argument(self):
        """
        If a date argument is given, parse it as DD-MM-YYYY and use it
        as the query date.
        """
        link1, link2 = LinkFactory.create_batch(2)
        self.service.get_clicks_for_date.return_value = {
            unicode(link1.pk): '4',
            unicode(link2.pk): '7'
        }
        query_date = aware_datetime(2014, 1, 1).date()

        # Create pre-existing data to check that it is replaced.
        DataPointFactory.create(link=link1, date=query_date, link_clicks=18)
        DataPointFactory.create(link=link2, date=query_date, link_clicks=14)

        self.command.execute('01-01-2014')

        # There must only be one datapoint for the query date, and the
        # link_clicks must match the new data.
        self.service.get_clicks_for_date.assert_called_with(query_date)
        eq_(link1.datapoint_set.get(date=query_date).link_clicks, 4)
        eq_(link2.datapoint_set.get(date=query_date).link_clicks, 7)
开发者ID:15776950506,项目名称:affiliates,代码行数:25,代码来源:test_management.py

示例13: test_links

# 需要导入模块: from affiliates.links.tests import LinkFactory [as 别名]
# 或者: from affiliates.links.tests.LinkFactory import create_batch [as 别名]
    def test_links(self):
        banner = TextBannerFactory.create()
        link1, link2 = LinkFactory.create_batch(2, banner_variation__banner=banner)

        eq_(set(banner.links), set([link1, link2]))
开发者ID:stevenjenn,项目名称:affiliates,代码行数:7,代码来源:test_models.py


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