Commit 5e7cebfe by Marko Jevtic Committed by Jonathan Piacenti

(MCKIN-3367) Preserve user's title upon changing user's name

parent 90a94415
...@@ -545,6 +545,13 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -545,6 +545,13 @@ class UsersApiTests(ModuleStoreTestCase):
# Testing profile updating scenario. # Testing profile updating scenario.
# Must be updated # Must be updated
data['first_name'] = "First Name"
data['last_name'] = "Surname"
response = self.do_post(test_uri, data)
self.assertEqual(response.status_code, 200)
response = self.do_get(test_uri)
self.is_user_profile_created_updated(response, data)
data["country"] = "US" data["country"] = "US"
data["year_of_birth"] = "1990" data["year_of_birth"] = "1990"
data["title"] = "" data["title"] = ""
...@@ -1490,7 +1497,9 @@ class UsersApiTests(ModuleStoreTestCase): ...@@ -1490,7 +1497,9 @@ class UsersApiTests(ModuleStoreTestCase):
def is_user_profile_created_updated(self, response, data): def is_user_profile_created_updated(self, response, data):
"""This function compare response with user profile data """ """This function compare response with user profile data """
fullname = '{} {}'.format(self.test_first_name, self.test_last_name) first_name = data.get('first_name', self.test_first_name)
last_name = data.get('last_name', self.test_last_name)
fullname = '{} {}'.format(first_name, last_name)
self.assertEqual(response.data['full_name'], fullname) self.assertEqual(response.data['full_name'], fullname)
self.assertEqual(response.data['city'], data["city"]) self.assertEqual(response.data['city'], data["city"])
self.assertEqual(response.data['country'], data["country"]) self.assertEqual(response.data['country'], data["country"])
......
...@@ -585,7 +585,7 @@ class UsersDetail(SecureAPIView): ...@@ -585,7 +585,7 @@ class UsersDetail(SecureAPIView):
if gender: if gender:
existing_user_profile.gender = gender existing_user_profile.gender = gender
# Empty title is also allowed # Empty title is also allowed
title = request.DATA.get('title', None) title = request.DATA.get('title', existing_user_profile.title)
existing_user_profile.title = title existing_user_profile.title = title
avatar_url = request.DATA.get('avatar_url') avatar_url = request.DATA.get('avatar_url')
if avatar_url: if avatar_url:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment