def test_email_address_uniqueness(self): """ Test & validates email addresses uniqueness """ # create a user with an email address first user = User.objects.create_user('mike', '*****@*****.**', '2secret') # test against User.email # test a unique email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.assertTrue(form.is_valid()) # test a duplicated email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['email'], ["This email address already in use."]) # test against EmailAddress.email email = EmailAddress(**{'user': user, 'email': '*****@*****.**'}) email.save() # test a duplicated email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['email'], ["This email address already in use."]) # test a unique email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.assertTrue(form.is_valid())
def test_email_address_uniqueness(self): """ Test & validates email addresses uniqueness """ # create a user with an email address first user = User.objects.create_user('mike', '*****@*****.**', '2secret') # test against User.email # test a unique email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.failUnless(form.is_valid()) # test a duplicated email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.failIf(form.is_valid()) self.assertEqual(form.errors['email'],[u"This email address already in use."]) # test against EmailAddress.email email = EmailAddress(**{'user': user, 'email': '*****@*****.**'}) email.save() # test a duplicated email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.failIf(form.is_valid()) self.assertEqual(form.errors['email'],[u"This email address already in use."]) # test a unique email address form = forms.EmailAddressForm(user=user, data={'email': '*****@*****.**'}) self.failUnless(form.is_valid())
def _makeEmailActivation(user, email, type): emailActivations = EmailAddress.objects.filter(user__id=user.id, email=email) if(emailActivations.count() > 0): emailActivation = emailActivations[0] else: emailActivation = EmailAddress() emailActivation.user = user emailActivation.email = email emailActivation.is_primary = type == 'PRIMARY' emailActivation.is_activation_sent = False emailActivation.save() return emailActivation
def _makeEmailActivation(user, email, type): emailActivations = EmailAddress.objects.filter(user__id=user.id, email=email) if emailActivations.count() > 0: emailActivation = emailActivations[0] else: emailActivation = EmailAddress() emailActivation.user = user emailActivation.email = email emailActivation.is_primary = type == "PRIMARY" emailActivation.is_activation_sent = False emailActivation.save() return emailActivation