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


Python tests.UserFactory类代码示例

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


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

示例1: 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

示例2: test_basic

    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,代码行数:31,代码来源:test_management.py

示例3: test_link_failure

    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,代码行数:9,代码来源:test_views.py

示例4: test_link_success

    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,代码行数:15,代码来源:test_views.py

示例5: test_not_created

    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,代码行数:7,代码来源:test_models.py

示例6: test_latest_newsitem

    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,代码行数:26,代码来源:test_views.py

示例7: test_process_request_clicks_and_downloads

    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,代码行数:30,代码来源:test_middleware.py

示例8: test_create_link

    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,代码行数:29,代码来源:test_models.py

示例9: test_user

 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,代码行数:7,代码来源:test_helpers.py

示例10: test_post

    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,代码行数:9,代码来源:test_views.py

示例11: test_milestone_date

    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,代码行数:9,代码来源:test_milestones.py

示例12: test_post_user_mismatch

    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,代码行数:19,代码来源:test_views.py

示例13: test_permission_granted

    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,代码行数:10,代码来源:test_models.py

示例14: test_milestone_date_not_reached

    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,代码行数:10,代码来源:test_milestones.py

示例15: test_affiliates_email_validation

    def test_affiliates_email_validation(self):
        """
        The affiliates_email field is only valid if an Affiliates user exists
        with the specified email address.
        """
        form = FacebookAccountLinkForm({'affiliates_email': '[email protected]'})
        eq_(form.is_valid(), False)

        user = UserFactory.create()
        form = FacebookAccountLinkForm({'affiliates_email': user.email})
        eq_(form.is_valid(), True)
开发者ID:15776950506,项目名称:affiliates,代码行数:11,代码来源:test_forms.py


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