API - update user email when email sending is disabled (admin)

This commit is contained in:
Sam 2022-04-24 10:08:15 +02:00
parent fab9c00726
commit 1f098fb2ce
2 changed files with 25 additions and 3 deletions

View File

@ -1214,27 +1214,48 @@ class TestUpdateUser(ApiTestCaseMixin):
user_email_updated_to_new_address_mock.send.assert_not_called()
def test_it_updates_user_email(
def test_it_updates_user_email_to_confirm_when_email_sending_is_enabled(
self, app: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app, user_1_admin.email
)
new_email = 'new.' + user_2.email
user_2_email = user_2.email
user_2_confirmation_token = user_2.confirmation_token
response = client.patch(
f'/api/users/{user_2.username}',
content_type='application/json',
data=json.dumps(dict(new_email='new.' + user_2.email)),
data=json.dumps(dict(new_email=new_email)),
headers=dict(Authorization=f'Bearer {auth_token}'),
)
assert response.status_code == 200
assert user_2.email == user_2_email
assert user_2.email_to_confirm == 'new.' + user_2.email
assert user_2.email_to_confirm == new_email
assert user_2.confirmation_token != user_2_confirmation_token
def test_it_updates_user_email_when_email_sending_is_disabled(
self, app_wo_email_activation: Flask, user_1_admin: User, user_2: User
) -> None:
client, auth_token = self.get_test_client_and_auth_token(
app_wo_email_activation, user_1_admin.email
)
new_email = 'new.' + user_2.email
response = client.patch(
f'/api/users/{user_2.username}',
content_type='application/json',
data=json.dumps(dict(new_email=new_email)),
headers=dict(Authorization=f'Bearer {auth_token}'),
)
assert response.status_code == 200
assert user_2.email == new_email
assert user_2.email_to_confirm is None
assert user_2.confirmation_token is None
def test_it_calls_email_updated_to_new_address_when_password_reset_is_successful( # noqa
self,
app: Flask,

View File

@ -526,6 +526,7 @@ def update_user(auth_user: User, user_name: str) -> Union[Dict, HttpResponse]:
activate=user_data.get('activate', False),
reset_password=reset_password,
new_email=new_email,
with_confirmation=current_app.config['CAN_SEND_EMAILS'],
)
if current_app.config['CAN_SEND_EMAILS']: