def test_unicode(self):
     """
     The string representation of a user should include their
     email address.
     """
     user = UserProfileFactory.create(name='Foo Bar', user__email='*****@*****.**').user
     eq_(unicode(user), u'Foo Bar ([email protected])')
Exemplo n.º 2
0
 def test_get_object(self):
     """
     Return the current user's profile.
     """
     self.request.user = UserProfileFactory.create().user
     self.view.request = self.request
     eq_(self.view.get_object(), self.request.user.profile)
Exemplo n.º 3
0
 def test_get_object(self):
     """
     Return the current user's profile.
     """
     self.request.user = UserProfileFactory.create().user
     self.view.request = self.request
     eq_(self.view.get_object(), self.request.user.profile)
Exemplo n.º 4
0
 def test_display_name(self):
     """
     The display_name attribute should use the name from the user's
     profile.
     """
     user = UserProfileFactory.create(name='Foo Bar').user
     eq_(user.display_name, 'Foo Bar')
Exemplo n.º 5
0
 def test_display_name(self):
     """
     The display_name attribute should use the name from the user's
     profile.
     """
     user = UserProfileFactory.create(name='Foo Bar').user
     eq_(user.display_name, 'Foo Bar')
Exemplo n.º 6
0
    def test_get_object_existing_username(self):
        """
        If an existing username is passed in, return that user's profile.
        """
        user = UserProfileFactory.create().user
        self.view.kwargs['username'] = user.profile.username

        eq_(self.view.get_object(), user.profile)
Exemplo n.º 7
0
 def test_profile_email_with_consent(self):
     """
     The email attribute should return the user's email
     if they have granted consent.
     """
     profile = UserProfileFactory.create(consent_to_email=True,
                                         user__email='*****@*****.**')
     eq_(profile.email, '*****@*****.**')
Exemplo n.º 8
0
    def test_get_object_existing_username(self):
        """
        If an existing username is passed in, return that user's profile.
        """
        user = UserProfileFactory.create().user
        self.view.kwargs['username'] = user.profile.username

        eq_(self.view.get_object(), user.profile)
Exemplo n.º 9
0
 def test_success_url_no_privacy_policy(self):
     """
     If the user has not accepted the privacy policy,
     return the url to edit user profile.
     """
     profile = UserProfileFactory.create(privacy_policy_accepted=False)
     self.view.user = profile.user
     eq_(self.view.success_url, reverse_lazy('users.profile.update'))
Exemplo n.º 10
0
 def test_display_email_with_consent(self):
     """
     The display_email attribute should return the user's email
     if they have granted consent.
     """
     user = UserProfileFactory.create(consent_to_email=True,
                                      user__email='*****@*****.**').user
     eq_(user.display_email, '*****@*****.**')
Exemplo n.º 11
0
 def test_profile_email_without_consent(self):
     """
     The email attribute should return 'Email consent denied'
     if they have denied consent.
     """
     profile = UserProfileFactory.create(consent_to_email=False,
                                         user__email='*****@*****.**')
     eq_(profile.email, 'Email consent denied')
Exemplo n.º 12
0
 def test_display_email_without_consent(self):
     """
     The display_email attribute should return 'Email consent denied'
     if they have denied consent.
     """
     user = UserProfileFactory.create(consent_to_email=False,
                                      user__email='*****@*****.**').user
     eq_(user.display_email, 'Email consent denied')
Exemplo n.º 13
0
 def test_success_url_no_privacy_policy(self):
     """
     If the user has not accepted the privacy policy,
     return the url to edit user profile.
     """
     profile = UserProfileFactory.create(privacy_policy_accepted=False)
     self.view.user = profile.user
     eq_(self.view.success_url, reverse_lazy('users.profile.update'))
Exemplo n.º 14
0
    def test_has_profile_and_accepts_privacy_policy(self):
        """
        If the user has created a profile, and has accepted privacy policy
        call the parent class's dispatch method.
        """
        request = Mock()
        request.user = UserProfileFactory.create(privacy_policy_accepted=True).user

        eq_(self.view.dispatch(request), 'fakemixin')
Exemplo n.º 15
0
    def test_has_profile(self):
        """
        If the user has created a profile, and has accepted privacy policy
        call the parent class's dispatch method.
        """
        request = Mock()
        request.user = UserProfileFactory.create(privacy_policy_accepted=True).user

        eq_(self.view.dispatch(request), 'fakemixin')
Exemplo n.º 16
0
 def test_profile_email_without_consent(self):
     """
     The email attribute should return 'Email consent denied'
     if they have denied consent.
     """
     profile = UserProfileFactory.create(
         consent_to_email=False,
         user__email='*****@*****.**')
     eq_(profile.email, 'Email consent denied')
Exemplo n.º 17
0
 def test_profile_email_with_consent(self):
     """
     The email attribute should return the user's email
     if they have granted consent.
     """
     profile = UserProfileFactory.create(
         consent_to_email=True,
         user__email='*****@*****.**')
     eq_(profile.email, '*****@*****.**')
Exemplo n.º 18
0
    def test_get_object_non_existent_username(self):
        """
        If a non-existent username is passed in, throw a 404.
        """
        user = UserProfileFactory.create().user
        self.view.kwargs['username'] = user.profile.username + str(datetime.today())

        with self.assertRaises(Http404):
            self.view.get_object()
Exemplo n.º 19
0
    def test_has_profile(self):
        """
        If the user has created a profile, call the parent class's
        dispatch method.
        """
        request = Mock()
        request.user = UserProfileFactory.create().user

        eq_(self.view.dispatch(request), 'fakemixin')
Exemplo n.º 20
0
 def test_display_email_without_consent(self):
     """
     The display_email attribute should return 'Email consent denied'
     if they have denied consent.
     """
     user = UserProfileFactory.create(
         consent_to_email=False,
         user__email='*****@*****.**').user
     eq_(user.display_email, 'Email consent denied')
Exemplo n.º 21
0
 def test_display_email_with_consent(self):
     """
     The display_email attribute should return the user's email
     if they have granted consent.
     """
     user = UserProfileFactory.create(
         consent_to_email=True,
         user__email='*****@*****.**').user
     eq_(user.display_email, '*****@*****.**')
Exemplo n.º 22
0
    def test_get_object_non_existent_username(self):
        """
        If a non-existent username is passed in, throw a 404.
        """
        user = UserProfileFactory.create().user
        self.view.kwargs['username'] = user.profile.username + str(
            datetime.today())

        with self.assertRaises(Http404):
            self.view.get_object()
Exemplo n.º 23
0
    def test_dispatch_existing_profile(self):
        """
        If the user already has a profile, redirect them to the home page.
        """
        request = Mock()
        request.user = UserProfileFactory.create().user

        with patch('oneanddone.users.views.redirect') as redirect:
            eq_(self.view.dispatch(request), redirect.return_value)
            redirect.assert_called_with('base.home')
Exemplo n.º 24
0
    def test_dispatch_existing_profile(self):
        """
        If the user already has a profile, redirect them to the home page.
        """
        request = Mock()
        request.user = UserProfileFactory.create().user

        with patch('oneanddone.users.views.redirect') as redirect:
            eq_(self.view.dispatch(request), redirect.return_value)
            redirect.assert_called_with('base.home')
Exemplo n.º 25
0
    def test_has_profile_and_not_accepted_privacy_policy(self):
        """
        If the user has created a profile, and has not accepted privacy policy
        redirect them to profile update view.
        """
        request = Mock()
        request.user = UserProfileFactory.create(privacy_policy_accepted=False).user

        with patch('oneanddone.users.mixins.redirect') as redirect:
            eq_(self.view.dispatch(request), redirect.return_value)
            redirect.assert_called_with('users.profile.update')
Exemplo n.º 26
0
    def test_has_profile_and_not_accepted_privacy_policy(self):
        """
        If the user has created a profile, and has not accepted privacy policy
        redirect them to profile update view.
        """
        request = Mock()
        request.user = UserProfileFactory.create(privacy_policy_accepted=False).user

        with patch('oneanddone.users.mixins.redirect') as redirect:
            eq_(self.view.dispatch(request), redirect.return_value)
            redirect.assert_called_with('users.profile.update')
Exemplo n.º 27
0
 def test_success_url_user_ok(self):
     """
     If the user has a profile and has accepted the privacy policy,
     return the parent success_url.
     """
     profile = UserProfileFactory.create(privacy_policy_accepted=True)
     self.view.user = profile.user
     success_url_patch = patch('django_browserid.views.Verify.success_url',
                               new_callable=PropertyMock)
     with success_url_patch as parent_success_url:
         parent_success_url.return_value = str(uuid4())
         eq_(self.view.success_url, parent_success_url.return_value)
         parent_success_url.assert_called_once_with()
Exemplo n.º 28
0
 def test_success_url_user_ok(self):
     """
     If the user has a profile and has accepted the privacy policy,
     return the parent success_url.
     """
     profile = UserProfileFactory.create(privacy_policy_accepted=True)
     self.view.user = profile.user
     success_url_patch = patch('django_browserid.views.Verify.success_url',
                               new_callable=PropertyMock)
     with success_url_patch as parent_success_url:
         parent_success_url.return_value = str(uuid4())
         eq_(self.view.success_url, parent_success_url.return_value)
         parent_success_url.assert_called_once_with()
Exemplo n.º 29
0
 def test_recent_users(self):
     """
     recent_users should return users sorted by most recent task activity
     """
     task = TaskFactory.create()
     user1 = UserProfileFactory.create().user
     user2 = UserProfileFactory.create().user
     user3 = UserProfileFactory.create().user
     user4 = UserFactory.create()
     TaskAttemptFactory.create(user=user4,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.FINISHED,
                               task=task)
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.ABANDONED,
                               task=task)
     eq_(user1.taskattempt_set.all().count(), 1)
     eq_(user2.taskattempt_set.all().count(), 2)
     eq_(user3.taskattempt_set.all().count(), 2)
     eq_(user4.taskattempt_set.all().count(), 1)
     qs = User.recent_users()
     eq_(len(qs), 3)
     eq_(qs[0], user1)
     eq_(qs[1], user2)
     eq_(qs[2], user3)
Exemplo n.º 30
0
 def setUp(self):
     self.user = UserProfileFactory.create(user__is_staff=True, name='Foo bar').user
     self.task = TaskFactory.create(owner=self.user)
Exemplo n.º 31
0
 def setUp(self):
     self.user = UserProfileFactory.create(user__is_staff=True,
                                           name='Foo bar').user
     self.task = TaskFactory.create(owner=self.user)
Exemplo n.º 32
0
 def test_profile_url_with_username(self):
     user = UserProfileFactory.create(username='******')
     eq_(user.profile_url, '/profile/foo/')
Exemplo n.º 33
0
 def test_profile_url_with_no_username(self):
     user = UserProfileFactory.create(username=None)
     profile_url = '/profile/%s/' % user.user.id
     eq_(user.profile_url, profile_url)
Exemplo n.º 34
0
 def test_bugzilla_url_with_bugzilla_email(self):
     email = '*****@*****.**'
     user = UserProfileFactory.create(bugzilla_email=email)
     activity_url = 'https://bugzilla.mozilla.org/page.cgi?'\
         'id=user_activity.html&action=run&from=-14d&who=%s' % email
     eq_(user.bugzilla_url, activity_url)
Exemplo n.º 35
0
 def test_bugzilla_url_with_no_bugzilla_email(self):
     user = UserProfileFactory.create()
     eq_(user.bugzilla_url, None)