Apply suggestions from code review

Co-authored-by: Ben Thorner <benthorner@users.noreply.github.com>
This commit is contained in:
Pea Tyczynska
2022-03-03 14:09:07 +00:00
committed by Leo Hemsted
parent 8112930e24
commit ae4fc977c1
2 changed files with 4 additions and 33 deletions

View File

@@ -64,7 +64,7 @@ def verify_email(token):
session['user_details'] = {"email": user.email_address, "id": user.id}
if user.auth_type == 'email_auth':
if user.email_auth:
try:
return activate_user(user.id)
finally:

View File

@@ -1,6 +1,5 @@
import json
import uuid
from datetime import datetime
from unittest.mock import Mock
from flask import session as flask_session
@@ -9,6 +8,7 @@ from itsdangerous import SignatureExpired
from notifications_python_client.errors import HTTPError
from app.main.views.verify import activate_user
from tests.conftest import create_user
def test_should_return_verify_template(
@@ -110,12 +110,6 @@ def test_verify_email_redirects_to_verify_if_token_valid(
token_data = {"user_id": api_user_pending['id'], "secret_code": 'UNUSED'}
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
with client_request.session_transaction() as session:
session['user_details'] = {
'email_address': api_user_pending['email_address'],
'id': api_user_pending['id'],
}
client_request.get(
'main.verify_email',
token='notreal',
@@ -137,35 +131,12 @@ def test_verify_email_doesnt_verify_sms_if_user_on_email_auth(
mock_activate_user,
fake_uuid,
):
pending_user_with_email_auth = {
'id': fake_uuid,
'name': 'Test User',
'password': 'somepassword',
'email_address': 'test@user.gov.uk',
'mobile_number': '07700 900762',
'state': 'pending',
'failed_login_count': 0,
'permissions': {},
'platform_admin': False,
'auth_type': 'email_auth',
'password_changed_at': str(datetime.utcnow()),
'services': [],
'organisations': [],
'current_session_id': None,
'logged_in_at': None,
'email_access_validated_at': None,
'can_use_webauthn': False,
}
pending_user_with_email_auth = create_user(auth_type='email_auth', state='pending', id=fake_uuid)
mocker.patch('app.user_api_client.get_user', return_value=pending_user_with_email_auth)
token_data = {"user_id": pending_user_with_email_auth['id'], "secret_code": 'UNUSED'}
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
with client_request.session_transaction() as session:
session['user_details'] = {
'email_address': pending_user_with_email_auth['email_address'],
'id': pending_user_with_email_auth['id'],
}
client_request.get(
'main.verify_email',
token='notreal',