mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-06 01:35:22 +02:00
Unit tests to asert that updating a contact's first and last names (but not an email) propagate to the linked user
This commit is contained in:
parent
abae70b96e
commit
48f69c8966
1 changed files with 47 additions and 0 deletions
|
@ -654,3 +654,50 @@ class TestUser(TestCase):
|
|||
"""A new user who's neither transitioned nor invited should
|
||||
return True when tested with class method needs_identity_verification"""
|
||||
self.assertTrue(User.needs_identity_verification(self.user.email, self.user.username))
|
||||
|
||||
|
||||
class TestContact(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.email = "mayor@igorville.gov"
|
||||
self.user, _ = User.objects.get_or_create(email=self.email, first_name="Rachid", last_name="Mrad")
|
||||
self.contact, _ = Contact.objects.get_or_create(user=self.user)
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
Contact.objects.all().delete()
|
||||
User.objects.all().delete()
|
||||
|
||||
def test_saving_contact_updates_user_first_last_names(self):
|
||||
"""When a contact is updated, we propagate the changes to the linked user if it exists."""
|
||||
# User and Contact are created and linked as expected
|
||||
self.assertEqual(self.contact.first_name, "Rachid")
|
||||
self.assertEqual(self.contact.last_name, "Mrad")
|
||||
self.assertEqual(self.user.first_name, "Rachid")
|
||||
self.assertEqual(self.user.last_name, "Mrad")
|
||||
|
||||
self.contact.first_name = "Joey"
|
||||
self.contact.last_name = "Baloney"
|
||||
self.contact.save()
|
||||
|
||||
# Refresh the user object to reflect the changes made in the database
|
||||
self.user.refresh_from_db()
|
||||
|
||||
# Updating the contact's first and last names propagate to the user
|
||||
self.assertEqual(self.contact.first_name, "Joey")
|
||||
self.assertEqual(self.contact.last_name, "Baloney")
|
||||
self.assertEqual(self.user.first_name, "Joey")
|
||||
self.assertEqual(self.user.last_name, "Baloney")
|
||||
|
||||
def test_saving_contact_does_not_update_user_email(self):
|
||||
"""When a contact's email is updated, the change is not propagated to the lined user."""
|
||||
self.contact.email = "joey.baloney@diaperville.com"
|
||||
self.contact.save()
|
||||
|
||||
# Refresh the user object to reflect the changes made in the database
|
||||
self.user.refresh_from_db()
|
||||
|
||||
# Updating the contact's email does not propagate
|
||||
self.assertEqual(self.contact.email, "joey.baloney@diaperville.com")
|
||||
self.assertEqual(self.user.email, "mayor@igorville.gov")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue