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


Python UserFactory.create方法代码示例

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


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

示例1: test_basic

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_basic(self):
        # Create users and links with the noted number of clicks.

        # User with clicks in both aggregate and datapoints across many
        # links.
        user1 = UserFactory.create() # Total: 38 clicks
        self._link_with_clicks(user1, 5, [4, 6, 3]) # 18 clicks
        self._link_with_clicks(user1, 1, [8, 9, 2]) # 20 clicks

        # User with clicks in both aggregate and datapoints in 1 link.
        user2 = UserFactory.create() # Total: 49 clicks
        self._link_with_clicks(user2, 13, [12, 11, 13]) # 49 clicks

        # User with no links.
        user3 = UserFactory.create() # Total: 0 clicks

        # User with links that have no aggregate clicks or no datapoint
        # clicks.
        user4 = UserFactory.create() # Total: 9 clicks
        self._link_with_clicks(user4, 1, [2, 2]) # 5 clicks
        self._link_with_clicks(user4, 0, [2]) # 2 clicks
        self._link_with_clicks(user4, 2, []) # 2 clicks

        # This one just sort've rounds out the set I guess.
        user5 = UserFactory.create() # Total: 9 clicks
        self._link_with_clicks(user5, 1, [2, 2, 2]) # 7 clicks
        self._link_with_clicks(user5, 0, [2]) # 2 clicks

        self.command.handle()
        eq_([s.user for s in LeaderboardStanding.objects.order_by('ranking')],
            [user2, user1, user4, user5, user3])
开发者ID:15776950506,项目名称:affiliates,代码行数:33,代码来源:test_management.py

示例2: test_link_failure

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_link_failure(self, create_link):
        """If creating a link fails, still return a 200 OK."""
        create_link.return_value = None
        self.client.fb_login(self.user)
        UserFactory.create(email='[email protected]')

        response = self.client.post(self.url,
                                    {'affiliates_email': '[email protected]'})
        eq_(response.status_code, 200)
开发者ID:15776950506,项目名称:affiliates,代码行数:11,代码来源:test_views.py

示例3: test_link_success

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_link_success(self, create_link, send_activation_email):
        """
        If creating a link succeeds, send an activation email and return a 200
        OK.
        """
        link = FacebookAccountLinkFactory.create()
        create_link.return_value = link
        self.client.fb_login(self.user)
        UserFactory.create(email='[email protected]')

        response = self.client.post(self.url,
                                    {'affiliates_email': '[email protected]'})
        eq_(response.status_code, 200)
        ok_(send_activation_email.called)
        eq_(send_activation_email.call_args[0][1], link)
开发者ID:15776950506,项目名称:affiliates,代码行数:17,代码来源:test_views.py

示例4: test_latest_newsitem

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_latest_newsitem(self):
        """
        Pass the most-recently-created visible NewsItem to the template
        context.
        """
        old_newsitem = NewsItemFactory.create(visible=True)
        old_newsitem.created = aware_datetime(2014, 1, 1)
        old_newsitem.save()

        non_visible_newsitem = NewsItemFactory.create(visible=False)
        non_visible_newsitem.created = aware_datetime(2014, 1, 5)
        non_visible_newsitem.save()

        visible_newsitem = NewsItemFactory.create(visible=True)
        visible_newsitem.created = aware_datetime(2014, 1, 4)
        visible_newsitem.save()

        request = Mock(user=UserFactory.create())
        with patch('affiliates.base.views.render') as render:
            views.dashboard(request)

        render.assert_called_with(request, 'base/dashboard.html', {
            'newsitem': visible_newsitem,
            'milestones': ANY,
            'links': ANY,
        })
开发者ID:Acidburn0zzz,项目名称:affiliates,代码行数:28,代码来源:test_views.py

示例5: test_not_created

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_not_created(self):
        """If user is not new, don't bother with permissions."""
        user = UserFactory.create()
        user.user_permissions.clear()

        add_default_permissions(User, created=False, instance=user)
        ok_(self.can_share_website not in user.user_permissions.all())
开发者ID:hoosteeno,项目名称:affiliates,代码行数:9,代码来源:test_models.py

示例6: test_process_request_clicks_and_downloads

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_process_request_clicks_and_downloads(self):
        """
        If there were any clicks or downloads since the user's last
        visit, update their last_visit date and log a message.
        """
        self.request.user = UserFactory.create(userprofile__last_visit=aware_date(2014, 1, 1))

        # Date of last visit not included.
        DataPointFactory.create(
            link__user=self.request.user, date=aware_date(2014, 1, 1), link_clicks=3, firefox_downloads=9
        )

        # Current date and dates between are included.
        DataPointFactory.create(
            link__user=self.request.user, date=aware_date(2014, 1, 2), link_clicks=4, firefox_downloads=7
        )
        DataPointFactory.create(
            link__user=self.request.user, date=aware_date(2014, 1, 3), link_clicks=1, firefox_downloads=2
        )

        with patch("affiliates.links.middleware.timezone.now") as mock_now:
            mock_now.return_value = aware_datetime(2014, 1, 3)
            eq_(self.middleware.process_request(self.request), None)
            ok_(self.messages.info.called)

        message = self.messages.info.call_args[0][1]
        ok_("5" in message and "9" in message)

        profile = UserProfile.objects.get(user=self.request.user)
        eq_(profile.last_visit, aware_date(2014, 1, 3))
开发者ID:Balachan,项目名称:affiliates,代码行数:32,代码来源:test_middleware.py

示例7: test_create_link

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_create_link(self):
        """
        create_link should create a Link object using this banner's
        description and generated code.
        """
        banner = Banner(destination="https://www.mozilla.org")
        banner.generate_banner_code = Mock(
            return_value="""
            <a href="{href}">Link!</a>
        """
        )
        banner.get_banner_type = Mock(return_value="generic_banner")
        user = UserFactory.create()
        variation = TextBannerVariationFactory.create()

        with patch.object(Link, "get_referral_url") as get_referral_url:
            get_referral_url.return_value = "asdf"
            link = banner.create_link(user, variation)

        ok_(isinstance(link, Link))
        eq_(link.user, user)
        eq_(link.banner_variation, variation)
        self.assertHTMLEqual(
            link.html,
            """
            <a href="asdf">Link!</a>
        """,
        )
        banner.generate_banner_code.assert_called_with(variation)
开发者ID:craigcook,项目名称:affiliates,代码行数:31,代码来源:test_models.py

示例8: test_user

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
 def test_user(self):
     """Passing a user returns the gravatar url for that user's email."""
     user = UserFactory.create(email='[email protected]')
     url = gravatar(user)
     eq_(url,
         'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80&d={default}'
         .format(default=self.default))
开发者ID:15776950506,项目名称:affiliates,代码行数:9,代码来源:test_helpers.py

示例9: test_post

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_post(self):
        user = UserFactory.create()
        request = Mock(user=user)
        self.view.get_object = Mock(return_value=user.userprofile)

        # Defer to the parent's post.
        with patch('affiliates.users.views.UpdateView.post') as super_post:
            eq_(self.view.post(request, user.pk), super_post.return_value)
            super_post.assert_called_with(request, user.pk)
开发者ID:15776950506,项目名称:affiliates,代码行数:11,代码来源:test_views.py

示例10: test_milestone_date

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_milestone_date(self):
        user = UserFactory.create()
        display = MilestoneDisplay(user)

        DataPointFactory.create(link_clicks=4, date=aware_date(2014, 1, 1), link__user=user)
        DataPointFactory.create(link_clicks=3, date=aware_date(2014, 1, 2), link__user=user)
        DataPointFactory.create(link_clicks=2, date=aware_date(2014, 1, 3), link__user=user)

        eq_(display.milestone_date('link_clicks', 10, 4), aware_date(2014, 1, 2))
开发者ID:15776950506,项目名称:affiliates,代码行数:11,代码来源:test_milestones.py

示例11: test_post_user_mismatch

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_post_user_mismatch(self):
        """
        If the user being edited doesn't match the current user,
        redirect to the profile page for the user being edited without
        making any changes.
        """
        request_user = UserFactory.create()
        request = Mock(user=request_user)

        edited_user = UserFactory.create(display_name='Bob')
        self.view.get_object = Mock(return_value=edited_user.userprofile)

        # Redirect should be called and given the profile, while the
        # parent's post should not be called.
        with patch('affiliates.users.views.UpdateView.post') as super_post:
            with patch('affiliates.users.views.redirect') as redirect:
                eq_(self.view.post(request, edited_user.pk), redirect.return_value)
                redirect.assert_called_with(edited_user.userprofile)
                ok_(not super_post.called)
开发者ID:15776950506,项目名称:affiliates,代码行数:21,代码来源:test_views.py

示例12: test_milestone_date_not_reached

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_milestone_date_not_reached(self):
        """
        If the milestone hasn't been reached by the user, return None.
        """
        user = UserFactory.create()
        display = MilestoneDisplay(user)

        DataPointFactory.create(link_clicks=4, date=aware_date(2014, 1, 1), link__user=user)

        eq_(display.milestone_date('link_clicks', 8, 2), None)
开发者ID:15776950506,项目名称:affiliates,代码行数:12,代码来源:test_milestones.py

示例13: test_permission_granted

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_permission_granted(self):
        """
        Newly created users should be granted the can_share_website
        permission.
        """
        user = UserFactory.create()
        user.user_permissions.clear()

        add_default_permissions(User, created=True, instance=user)
        ok_(self.can_share_website in user.user_permissions.all())
开发者ID:hoosteeno,项目名称:affiliates,代码行数:12,代码来源:test_models.py

示例14: test_create_link_active_link

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_create_link_active_link(self):
        """If an active link already exists, create_link should return False."""
        link = FacebookAccountLinkFactory.create(is_active=True)
        result = self.manager.create_link(link.facebook_user,
                                          link.affiliates_user.email)
        eq_(result, False)

        # Test an active link with a different email address.
        user = UserFactory.create()
        result = self.manager.create_link(link.facebook_user, user.email)
        eq_(result, False)
开发者ID:15776950506,项目名称:affiliates,代码行数:13,代码来源:test_managers.py

示例15: test_process_request_less_than_one_day

# 需要导入模块: from affiliates.users.tests import UserFactory [as 别名]
# 或者: from affiliates.users.tests.UserFactory import create [as 别名]
    def test_process_request_less_than_one_day(self):
        """
        If it has been less than one day since the user's last visit,
        return None and do not log a message.
        """
        self.request.user = UserFactory.create(userprofile__last_visit=aware_date(2014, 1, 1))

        with patch("affiliates.links.middleware.timezone.now") as mock_now:
            mock_now.return_value = aware_datetime(2014, 1, 1)
            eq_(self.middleware.process_request(self.request), None)
            ok_(not self.messages.info.called)
开发者ID:Balachan,项目名称:affiliates,代码行数:13,代码来源:test_middleware.py


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