feat: only update full name if not verified name enabled

MST-1015
This commit is contained in:
Andy Shultz
2021-09-08 10:24:37 -04:00
parent 1288d964b8
commit f158fedd15
2 changed files with 20 additions and 13 deletions

View File

@@ -21,8 +21,9 @@ from django.test.client import Client, RequestFactory
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.timezone import now
from edx_name_affirmation.toggles import VERIFIED_NAME_FLAG
from opaque_keys.edx.locator import CourseLocator
from waffle.testutils import override_switch
from waffle.testutils import override_flag, override_switch
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
@@ -1256,16 +1257,18 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
# Verify that the user's name wasn't changed
self._assert_user_name(self.user.profile.name)
def test_submit_photos_and_change_name(self):
# Submit the photos, along with a name change
self._submit_photos(
face_image=self.IMAGE_DATA,
photo_id_image=self.IMAGE_DATA,
full_name=self.FULL_NAME
)
@ddt.data(True, False)
def test_submit_photos_and_change_name(self, flag_on):
with override_flag(VERIFIED_NAME_FLAG.name, flag_on):
# Submit the photos, along with a name change
self._submit_photos(
face_image=self.IMAGE_DATA,
photo_id_image=self.IMAGE_DATA,
full_name=self.FULL_NAME
)
# Check that the user's name was changed in the database
self._assert_user_name(self.FULL_NAME)
# Check that the user's name was changed in the database if verified_name is off
self._assert_user_name(self.FULL_NAME, equality=not flag_on)
def test_submit_photos_sends_confirmation_email(self):
self._submit_photos(
@@ -1479,7 +1482,7 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
# Verify that photo submission confirmation email was not sent
assert len(mail.outbox) == 0
def _assert_user_name(self, full_name):
def _assert_user_name(self, full_name, equality=True):
"""Check the user's name.
Arguments:
@@ -1492,7 +1495,10 @@ class TestSubmitPhotosForVerification(MockS3BotoMixin, TestVerificationBase):
request = RequestFactory().get('/url')
request.user = self.user
account_settings = get_account_settings(request)[0]
assert account_settings['name'] == full_name
if equality:
assert account_settings['name'] == full_name
else:
assert not account_settings['name'] == full_name
def _get_post_data(self):
"""Retrieve POST data from the last request. """

View File

@@ -21,6 +21,7 @@ from django.utils.translation import ugettext_lazy
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.views.generic.base import View
from edx_name_affirmation.toggles import is_verified_name_enabled
from edx_rest_api_client.exceptions import SlumberBaseException
from ipware.ip import get_client_ip
from opaque_keys.edx.keys import CourseKey
@@ -846,7 +847,7 @@ class SubmitPhotosView(View):
return response
# If necessary, update the user's full name
if "full_name" in params:
if "full_name" in params and not is_verified_name_enabled():
response = self._update_full_name(request, params["full_name"])
if response is not None:
return response