From e5ea81b1844d811b6a3ba9891dcb077c2cdc4759 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Thu, 10 Nov 2016 10:45:09 +0000 Subject: [PATCH] Fix pep issues and refactor tests --- app/main/views/user_profile.py | 6 +++--- tests/app/main/views/test_user_profile.py | 10 ++++++---- tests/conftest.py | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 041b0a817..4107e53cd 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -48,7 +48,7 @@ def user_profile_name(): if form.validate_on_submit(): user_api_client.update_user_attribute(current_user.id, - name=form.new_name.data) + name=form.new_name.data) return redirect(url_for('.user_profile')) return render_template( @@ -115,7 +115,7 @@ def user_profile_email_confirm(token): user_id = token_data['user_id'] new_email = token_data['email'] user_api_client.update_user_attribute(user_id, - email_address=new_email) + email_address=new_email) session.pop(NEW_EMAIL, None) return redirect(url_for('.user_profile')) @@ -181,7 +181,7 @@ def user_profile_mobile_number_confirm(): del session[NEW_MOBILE] del session[NEW_MOBILE_PASSWORD_CONFIRMED] user_api_client.update_user_attribute(current_user.id, - mobile_number=mobile_number) + mobile_number=mobile_number) return redirect(url_for('.user_profile')) return render_template( diff --git a/tests/app/main/views/test_user_profile.py b/tests/app/main/views/test_user_profile.py index c2711ae05..09bd83f95 100644 --- a/tests/app/main/views/test_user_profile.py +++ b/tests/app/main/views/test_user_profile.py @@ -32,8 +32,8 @@ def test_should_show_name_page(app_, def test_should_redirect_after_name_change(app_, api_user_active, mock_login, - mock_update_user, - mock_get_user): + mock_get_user, + mock_update_user_attribute): with app_.test_request_context(): with app_.test_client() as client: client.login(api_user_active) @@ -46,7 +46,7 @@ def test_should_redirect_after_name_change(app_, assert response.location == url_for( 'main.user_profile', _external=True) api_user_active.name = new_name - assert mock_update_user.called + assert mock_update_user_attribute.called def test_should_show_email_page(app_, @@ -116,7 +116,8 @@ def test_should_render_change_email_continue_after_authenticate_email(app_, def test_should_redirect_to_user_profile_when_user_confirms_email_link(app_, api_user_active, - mock_login + mock_login, + mock_update_user_attribute ): with app_.test_request_context(): with app_.test_client() as client: @@ -218,6 +219,7 @@ def test_should_redirect_after_mobile_number_confirm(app_, api_user_active, mock_login, mock_get_user, + mock_update_user_attribute, mock_check_verify_code): with app_.test_request_context(): with app_.test_client() as client: diff --git a/tests/conftest.py b/tests/conftest.py index d96f2c6e0..e7eea554d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -760,6 +760,14 @@ def mock_update_user(mocker, api_user_active): return mocker.patch('app.user_api_client.update_user', side_effect=_update) +@pytest.fixture(scope='function') +def mock_update_user_attribute(mocker, api_user_active): + def _update(user_id, **kwargs): + return api_user_active + + return mocker.patch('app.user_api_client.update_user_attribute', side_effect=_update) + + @pytest.fixture(scope='function') def mock_is_email_unique(mocker): return mocker.patch('app.user_api_client.is_email_unique', return_value=True)