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])')
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)
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')
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)
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, '*****@*****.**')
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'))
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, '*****@*****.**')
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')
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')
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')
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')
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')
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, '*****@*****.**')
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()
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')
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')
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, '*****@*****.**')
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()
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')
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')
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()
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)
def setUp(self): self.user = UserProfileFactory.create(user__is_staff=True, name='Foo bar').user self.task = TaskFactory.create(owner=self.user)
def test_profile_url_with_username(self): user = UserProfileFactory.create(username='******') eq_(user.profile_url, '/profile/foo/')
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)
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)
def test_bugzilla_url_with_no_bugzilla_email(self): user = UserProfileFactory.create() eq_(user.bugzilla_url, None)