mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
added unit test for conflicting first and last names
This commit is contained in:
parent
e7c26d9dc6
commit
abae70b96e
1 changed files with 20 additions and 1 deletions
|
@ -54,7 +54,7 @@ class OpenIdConnectBackendTestCase(TestCase):
|
|||
|
||||
def test_authenticate_with_existing_user_no_name(self):
|
||||
"""Test that authenticate updates an existing user if it finds one.
|
||||
For this test, given_name and family_name are supplied"""
|
||||
For this test, given_name and family_name are not supplied"""
|
||||
# Create an existing user with the same username and with first and last names
|
||||
existing_user = User.objects.create_user(username="test_user",first_name="John",last_name="Doe")
|
||||
|
||||
|
@ -75,6 +75,25 @@ class OpenIdConnectBackendTestCase(TestCase):
|
|||
self.assertEqual(user.email, "john.doe@example.com")
|
||||
self.assertEqual(user.phone, "123456789")
|
||||
|
||||
def test_authenticate_with_existing_user_different_name(self):
|
||||
"""Test that authenticate updates an existing user if it finds one.
|
||||
For this test, given_name and family_name are supplied and overwrite"""
|
||||
# Create an existing user with the same username and with first and last names
|
||||
existing_user = User.objects.create_user(username="test_user",first_name="WillBe",last_name="Replaced")
|
||||
|
||||
# Ensure that the authenticate method updates the existing user
|
||||
# and preserves existing first and last names
|
||||
user = self.backend.authenticate(request=None, **self.kwargs)
|
||||
self.assertIsNotNone(user)
|
||||
self.assertIsInstance(user, User)
|
||||
self.assertEqual(user, existing_user) # The same user instance should be returned
|
||||
|
||||
# Verify that user fields are correctly updated
|
||||
self.assertEqual(user.first_name, "John")
|
||||
self.assertEqual(user.last_name, "Doe")
|
||||
self.assertEqual(user.email, "john.doe@example.com")
|
||||
self.assertEqual(user.phone, "123456789")
|
||||
|
||||
def test_authenticate_with_unknown_user(self):
|
||||
"""Test that authenticate returns None when no kwargs are supplied"""
|
||||
# Ensure that the authenticate method handles the case when the user is not found
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue