def test_set_primary_email(self): """ Calling the set_as_primary method in the SecondaryEmail removes it from SecondaryEmail, replaces the current address on the User model, and adds the replaced address to the SecondaryEmail table. """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) new_primary = secondary_email.email for email in [old_primary, new_primary]: # Emails must be verified to make them primary. activation = ActivationProfile.objects.get_or_create(user=self.user, email=email)[0] ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(email=new_primary) secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=new_primary) old_email = SecondaryEmail.objects.get(email=old_primary) self.assertTrue(old_email.verified) user = User.objects.get(email=new_primary)
def test_set_primary_email(self): """ Calling the set_as_primary method in the SecondaryEmail removes it from SecondaryEmail, replaces the current address on the User model, and adds the replaced address to the SecondaryEmail table. """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) new_primary = secondary_email.email for email in [old_primary, new_primary]: # Emails must be verified to make them primary. activation = ActivationProfile.objects.get_or_create( user=self.user, email=email)[0] ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(email=new_primary) secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=new_primary) old_email = SecondaryEmail.objects.get(email=old_primary) self.assertTrue(old_email.verified) user = User.objects.get(email=new_primary)
def test_maintain_verification_state(self): """ For security reasons, the state of verification of the user email should be the same as it is when it is transferred into SecondaryEmail """ old_primary = self.user.email self.user.is_active = False self.user.save() secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get(user=self.user, email=secondary_email.email) new_primary = secondary_email.email secondary_email.set_as_primary() old_email = SecondaryEmail.objects.get(email=old_primary) self.assertFalse(old_email.verified) user = User.objects.get(email=new_primary)
def test_maintain_verification_state(self): """ For security reasons, the state of verification of the user email should be the same as it is when it is transferred into SecondaryEmail """ old_primary = self.user.email self.user.is_active = False self.user.save() secondary_email = SecondaryEmailFactory(user=self.user) activation = ActivationProfile.objects.get(user=self.user, email=secondary_email.email) ActivationProfile.objects.activate_user(activation.activation_key) secondary_email = SecondaryEmail.objects.get( user=self.user, email=secondary_email.email) new_primary = secondary_email.email secondary_email.set_as_primary() old_email = SecondaryEmail.objects.get(email=old_primary) self.assertFalse(old_email.verified) user = User.objects.get(email=new_primary)
def test_unverified_primary_email(self): """ Only verified emails can be set as the primary email """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) primary = secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=old_primary) self.assertFalse(primary) user = User.objects.get(email=old_primary) self.assertEqual(user.email, old_primary)
def test_unverified_primary_email(self): """ Only verified emails can be set as the primary email """ old_primary = self.user.email secondary_email = SecondaryEmailFactory(user=self.user) primary = secondary_email.set_as_primary() with self.assertRaises(SecondaryEmail.DoesNotExist): SecondaryEmail.objects.get(email=old_primary) self.assertFalse(primary) user = User.objects.get(email=old_primary) self.assertEqual(user.email, old_primary)