added unit test for conflicting first and last names

This commit is contained in:
David Kennedy 2023-12-11 20:49:33 -05:00
parent e7c26d9dc6
commit abae70b96e
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -54,7 +54,7 @@ class OpenIdConnectBackendTestCase(TestCase):
def test_authenticate_with_existing_user_no_name(self): def test_authenticate_with_existing_user_no_name(self):
"""Test that authenticate updates an existing user if it finds one. """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 # 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") 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.email, "john.doe@example.com")
self.assertEqual(user.phone, "123456789") 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): def test_authenticate_with_unknown_user(self):
"""Test that authenticate returns None when no kwargs are supplied""" """Test that authenticate returns None when no kwargs are supplied"""
# Ensure that the authenticate method handles the case when the user is not found # Ensure that the authenticate method handles the case when the user is not found