def test_can_create_variant_for_unconfirmed_email(self): user = BadgeUser.objects.first() new_email_address = "*****@*****.**" new_email = CachedEmailAddress.objects.create(email=new_email_address, user=user) new_variant = EmailAddressVariant(email=new_email_address.upper(), canonical_email=new_email) new_variant.save() self.assertFalse(new_variant.verified) verified_emails = [e.email for e in user.emailaddress_set.filter(verified=True)] \ + [e.email for e in user.cached_email_variants() if e.verified] self.assertTrue(new_variant not in verified_emails)
def cannot_link_variant_of_case_insensitive_nonmatch(self): first_email = CachedEmailAddress.objects.get(email="*****@*****.**") self.assertIsNotNone(first_email.pk) variant_email = "*****@*****.**" variant = EmailAddressVariant(email=variant_email, canonical_email=first_email) try: variant.save() except ValidationError as e: self.assertEqual(e.message, "New EmailAddressVariant does not match stored email address.") else: raise self.fail("ValidationError expected on nonmatch.")
def test_can_create_variants(self): user = self.setup_user(authenticate=False) first_email = CachedEmailAddress.objects.create(email="*****@*****.**", verified=True, user=user) self.assertIsNotNone(first_email.pk) first_variant_email = "*****@*****.**" second_variant_email = "*****@*****.**" first_variant = EmailAddressVariant(email=first_variant_email, canonical_email=first_email) first_variant.save() self.assertEqual(first_variant.canonical_email, first_email) second_variant = first_email.add_variant(second_variant_email) self.assertEqual(second_variant.canonical_email, first_email) self.assertEqual(len(first_email.emailaddressvariant_set.all()), 2) self.assertEqual(len(first_email.cached_variants()), 2)
def test_can_create_variants(self): user = self.setup_user(authenticate=False, eduid="urn:mace:eduid.nl:1.0:d57b4355-c7c6-4924-a944-6172e31e9bbc:27871c14-b952-4d7e-85fd-6329ac5c6f19") first_email = CachedEmailAddress.objects.create(email="*****@*****.**", verified=True, user=user) self.assertIsNotNone(first_email.pk) first_variant_email = "*****@*****.**" second_variant_email = "*****@*****.**" first_variant = EmailAddressVariant(email=first_variant_email, canonical_email=first_email) first_variant.save() self.assertEqual(first_variant.canonical_email, first_email) second_variant = first_email.add_variant(second_variant_email) self.assertEqual(second_variant.canonical_email, first_email) self.assertEqual(len(first_email.emailaddressvariant_set.all()), 2) self.assertEqual(len(first_email.cached_variants()), 2)