diff --git a/app/templates/views/letters.html b/app/templates/views/letters.html
index 1086f1d50..5ef3e4d6f 100644
--- a/app/templates/views/letters.html
+++ b/app/templates/views/letters.html
@@ -7,7 +7,11 @@
{% block maincolumn_content %}
diff --git a/app/templates/views/manage-users.html b/app/templates/views/manage-users.html
index 0876f8f5b..e0f7fe1a5 100644
--- a/app/templates/views/manage-users.html
+++ b/app/templates/views/manage-users.html
@@ -16,11 +16,16 @@ Manage users – GOV.UK Notify
{% block maincolumn_content %}
-
{% call(item) list_table(
users, caption='Active', **table_options
diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html
index c285f6c7d..b05e06025 100644
--- a/app/templates/views/service-settings.html
+++ b/app/templates/views/service-settings.html
@@ -7,7 +7,7 @@
{% block maincolumn_content %}
-
{{ browse_list([
{
diff --git a/app/templates/views/service_dashboard.html b/app/templates/views/service_dashboard.html
index 90b4ecc0d..f7a6dc7fa 100644
--- a/app/templates/views/service_dashboard.html
+++ b/app/templates/views/service_dashboard.html
@@ -29,12 +29,12 @@
@@ -42,7 +42,7 @@
{% elif not jobs %}
{% call banner_wrapper(subhead='Next step', type="tip") %}
{% if current_user.has_permissions(['send_texts', 'send_emails', 'send_letters']) %}
-
{% endif %}
{% endcall %}
{% else %}
diff --git a/app/templates/views/verify.html b/app/templates/views/verify.html
index dcde0a4f3..e34285720 100644
--- a/app/templates/views/verify.html
+++ b/app/templates/views/verify.html
@@ -3,30 +3,48 @@
{% from "components/page-footer.html" import page_footer %}
{% block page_title %}
- Enter the codes we’ve sent you – GOV.UK Notify
+ {% if form.email_code %}
+ Enter the codes we’ve sent you – GOV.UK Notify
+ {% else %}
+ Enter the code we’ve sent you – GOV.UK Notify
+ {% endif %}
{% endblock %}
{% block maincolumn_content %}
-
Enter the codes we’ve sent you
-
- We’ve sent you confirmation codes by email and text message.
-
+ {% if form.email_code %}
+
Enter the codes we’ve sent you
+ {% else %}
+
Enter the code we’ve sent you
+ {% endif %}
+ {% if form.email_code %}
+
+ We’ve sent you confirmation codes by email and text message.
+
+ {% else %}
+
+ We’ve sent you a confirmation code by text message.
+
+ {% endif %}
diff --git a/config.py b/config.py
index ef8ced69b..bb520a3ae 100644
--- a/config.py
+++ b/config.py
@@ -13,11 +13,7 @@ class Config(object):
NOTIFY_APP_NAME = 'admin'
NOTIFY_LOG_PATH = '/var/log/notify/application.log'
- SQLALCHEMY_COMMIT_ON_TEARDOWN = False
- SQLALCHEMY_RECORD_QUERIES = True
- SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/notifications_admin'
MAX_FAILED_LOGIN_COUNT = 10
- PASS_SECRET_KEY = 'secret-key-unique-changeme'
SESSION_COOKIE_NAME = 'notify_admin_session'
SESSION_COOKIE_PATH = '/admin'
@@ -67,7 +63,6 @@ class Development(Config):
class Test(Development):
- SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/test_notifications_admin'
WTF_CSRF_ENABLED = False
diff --git a/requirements.txt b/requirements.txt
index 85ed0e61d..c0d9bbd45 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,4 +14,4 @@ Pygments==2.0.2
git+https://github.com/alphagov/notifications-python-client.git@0.3.1#egg=notifications-python-client==0.3.1
-git+https://github.com/alphagov/notifications-utils.git@2.0.0#egg=notifications-utils==2.0.0
+git+https://github.com/alphagov/notifications-utils.git@3.0.0#egg=notifications-utils==3.0.0
diff --git a/tests/app/main/notify_client/test_sender.py b/tests/app/main/notify_client/test_sender.py
deleted file mode 100644
index aef8d1f0c..000000000
--- a/tests/app/main/notify_client/test_sender.py
+++ /dev/null
@@ -1,29 +0,0 @@
-from itsdangerous import BadSignature
-from pytest import fail
-
-from app.notify_client.sender import generate_token, check_token
-
-
-def test_should_return_email_from_signed_token(app_):
- email = 'email@something.com'
- token = generate_token(email)
- assert email == check_token(token)
-
-
-def test_should_throw_exception_when_token_is_tampered_with(app_):
- email = 'email@something.com'
- token = generate_token(email)
- try:
- check_token(token + 'qerqwer')
- fail()
- except BadSignature:
- pass
-
-
-def test_return_none_when_token_is_expired(app_):
- with app_.test_request_context():
- app_.config['TOKEN_MAX_AGE_SECONDS'] = -1000
- email = 'email@something.com'
- token = generate_token(email)
- assert check_token(token) is None
- app_.config['TOKEN_MAX_AGE_SECONDS'] = 120000
diff --git a/tests/app/main/test_errorhandlers.py b/tests/app/main/test_errorhandlers.py
new file mode 100644
index 000000000..f4853632f
--- /dev/null
+++ b/tests/app/main/test_errorhandlers.py
@@ -0,0 +1,10 @@
+from bs4 import BeautifulSoup
+from flask import url_for
+
+
+def test_bad_url_returns_page_not_found(app_):
+ with app_.test_client() as client:
+ response = client.get('/bad_url')
+ assert response.status_code == 404
+ page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
+ assert page.h1.string.strip() == 'Page could not be found'
diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py
index 3e48e1f73..b74142682 100644
--- a/tests/app/main/views/test_accept_invite.py
+++ b/tests/app/main/views/test_accept_invite.py
@@ -3,6 +3,8 @@ from flask import url_for
from bs4 import BeautifulSoup
import app
+
+from app.notify_client.models import InvitedUser
from tests.conftest import sample_invite as create_sample_invite
from tests.conftest import mock_check_invite_token as mock_check_token_invite
@@ -34,6 +36,48 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(app_,
assert response.location == expected_redirect_location
+def test_existing_user_with_no_permissions_accept_invite(app_,
+ mocker,
+ service_one,
+ api_user_active,
+ sample_invite,
+ mock_check_invite_token,
+ mock_get_user_by_email,
+ mock_add_user_to_service):
+
+ expected_service = service_one['id']
+ sample_invite['permissions'] = ''
+ expected_permissions = []
+ mocker.patch('app.invite_api_client.accept_invite', return_value=sample_invite)
+
+ with app_.test_request_context():
+ with app_.test_client() as client:
+
+ response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'))
+ mock_add_user_to_service.assert_called_with(expected_service, api_user_active.id, expected_permissions)
+
+ assert response.status_code == 302
+
+
+def test_existing_user_cant_accept_twice(app_,
+ mocker,
+ sample_invite):
+
+ sample_invite['status'] = 'accepted'
+ invite = InvitedUser(**sample_invite)
+ mocker.patch('app.invite_api_client.check_token', return_value=invite)
+
+ with app_.test_request_context():
+ with app_.test_client() as client:
+ response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'), follow_redirects=True)
+ assert response.status_code == 200
+ page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
+ assert page.h1.string.strip() == 'Sign in'
+ flash_banners = page.find_all('div', class_='banner-default')
+ assert len(flash_banners) == 2
+ assert flash_banners[0].text.strip() == 'You have already accepted this invitation'
+
+
def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(app_,
service_one,
api_user_active,
@@ -125,8 +169,7 @@ def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation
service_one,
mocker,
mock_get_user,
- mock_get_service
- ):
+ mock_get_service):
with app_.test_request_context():
with app_.test_client() as client:
cancelled_invitation = create_sample_invite(mocker, service_one, status='cancelled')
@@ -188,6 +231,7 @@ def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(a
def test_new_invited_user_verifies_and_added_to_service(app_,
service_one,
sample_invite,
+ api_user_active,
mock_check_invite_token,
mock_dont_get_user_by_email,
mock_register_user,
@@ -217,8 +261,7 @@ def test_new_invited_user_verifies_and_added_to_service(app_,
response = client.post(url_for('main.register_from_invite'), data=data)
# that sends user on to verify
- response = client.post(url_for('main.verify'), data={'sms_code': '12345', 'email_code': '23456'},
- follow_redirects=True)
+ response = client.post(url_for('main.verify'), data={'sms_code': '12345'}, follow_redirects=True)
# when they post codes back to admin user should be added to
# service and sent on to dash board
@@ -226,8 +269,8 @@ def test_new_invited_user_verifies_and_added_to_service(app_,
with client.session_transaction() as session:
new_user_id = session['user_id']
mock_add_user_to_service.assert_called_with(data['service'], new_user_id, expected_permissions)
-
- mock_accept_invite.assert_called_with(data['service'], sample_invite['id'])
+ mock_accept_invite.assert_called_with(data['service'], sample_invite['id'])
+ mock_check_verify_code.assert_called_once_with(new_user_id, '12345', 'sms')
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
element = page.find('h2', class_='navigation-service-name').find('a')
@@ -236,4 +279,4 @@ def test_new_invited_user_verifies_and_added_to_service(app_,
assert service_link == '/services/{}/dashboard'.format(service_one['id'])
flash_banner = page.find('div', class_='banner-default-with-tick').string.strip()
- assert flash_banner == 'You have sucessfully accepted your invitation and been added to Test Service'
+ assert flash_banner == 'You have successfully accepted your invitation and been added to Test Service'
diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py
index c5a4fc9e7..2b1e1c264 100644
--- a/tests/app/main/views/test_add_service.py
+++ b/tests/app/main/views/test_add_service.py
@@ -7,7 +7,6 @@ def test_get_should_render_add_service_template(app_,
mock_login,
mock_get_service,
mock_get_services,
- mock_get_user,
mock_get_user_by_email):
with app_.test_request_context():
with app_.test_client() as client:
@@ -21,9 +20,7 @@ def test_should_add_service_and_redirect_to_next_page(app_,
mock_login,
mock_create_service,
mock_get_services,
- api_user_active,
- mock_get_user,
- mock_get_user_by_email):
+ api_user_active):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
@@ -32,7 +29,9 @@ def test_should_add_service_and_redirect_to_next_page(app_,
data={'name': 'testing the post'})
assert response.status_code == 302
assert response.location == url_for('main.service_dashboard', service_id=101, _external=True)
- assert mock_create_service.called
+ mock_create_service.asset_called_once_with('testing the post', False,
+ app_.config['DEFAULT_SERVICE_LIMIT'],
+ True, api_user_active.id)
def test_should_return_form_errors_when_service_name_is_empty(app_,
diff --git a/tests/app/main/views/test_manage_users.py b/tests/app/main/views/test_manage_users.py
index a335ea8be..d0ed7e571 100644
--- a/tests/app/main/views/test_manage_users.py
+++ b/tests/app/main/views/test_manage_users.py
@@ -123,7 +123,7 @@ def test_should_show_page_for_inviting_user(
client.login(api_user_active)
response = client.get(url_for('main.invite_user', service_id=55555))
- assert 'Add a new team member' in response.get_data(as_text=True)
+ assert 'Invite a team member' in response.get_data(as_text=True)
assert response.status_code == 200
@@ -277,6 +277,6 @@ def test_user_cant_invite_themselves(
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
- assert page.h1.string.strip() == 'Add a new team member'
+ assert page.h1.string.strip() == 'Invite a team member'
form_error = page.find('span', class_='error-message').string.strip()
assert form_error == "You can't send an invitation to yourself"
diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py
index d61513784..9849da99f 100644
--- a/tests/app/main/views/test_register.py
+++ b/tests/app/main/views/test_register.py
@@ -44,7 +44,7 @@ def test_process_register_creates_new_user(app_,
assert mock_register_user.called
-def test_process_register_returns_400_when_mobile_number_is_invalid(app_,
+def test_process_register_returns_200_when_mobile_number_is_invalid(app_,
mock_send_verify_code,
mock_get_user_by_email_not_found,
mock_login):
diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py
index 5115d4e73..44fc9a1ee 100644
--- a/tests/app/main/views/test_send.py
+++ b/tests/app/main/views/test_send.py
@@ -19,17 +19,16 @@ def test_upload_csvfile_with_errors_shows_check_page_with_errors(
mock_has_permissions
):
- contents = 'phone number,name\n+44 123,test1\n+44 456,test2'
- file_data = (BytesIO(contents.encode('utf-8')), 'invalid.csv')
+ contents = u'phone number,name\n+44 123,test1\n+44 456,test2'
mocker.patch('app.main.views.send.s3download', return_value=contents)
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
- upload_data = {'file': file_data}
response = client.post(
url_for('main.send_messages', service_id=12345, template_id=54321),
- data=upload_data,
+ data={'file': (BytesIO(contents.encode('utf-8')), 'invalid.csv')},
+ content_type='multipart/form-data',
follow_redirects=True
)
assert response.status_code == 200
@@ -126,7 +125,27 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(
mocker.patch(
'app.main.views.send.s3download',
- return_value='phone number\n+44 7700 900981\n+44 7700 900982\n+44 7700 900983\n+44 7700 900984\n+44 7700 900985\n+44 7700 900986' # noqa
+ return_value="""
+ phone number
+ +44 7700 9009 01
+ +44 7700 9009 02
+ +44 7700 9009 03
+ +44 7700 9009 04
+ +44 7700 9009 05
+ +44 7700 9009 06
+ +44 7700 9009 07
+ +44 7700 9009 08
+ +44 7700 9009 09
+ +44 7700 9009 10
+ +44 7700 9009 11
+ +44 7700 9009 12
+ +44 7700 9009 13
+ +44 7700 9009 14
+ +44 7700 9009 15
+ +44 7700 9009 99
+ +44 7700 9009 99
+ +44 7700 9009 99
+ """
)
with app_.test_request_context():
@@ -134,22 +153,21 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(
client.login(api_user_active)
response = client.post(
url_for('main.send_messages', service_id=12345, template_id=54321),
- data={'file': (BytesIO(), 'valid.csv')},
+ data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')},
+ content_type='multipart/form-data',
follow_redirects=True
)
with client.session_transaction() as sess:
assert int(sess['upload_data']['template_id']) == 54321
assert sess['upload_data']['original_file_name'] == 'valid.csv'
- assert sess['upload_data']['notification_count'] == 6
+ assert sess['upload_data']['notification_count'] == 18
content = response.get_data(as_text=True)
assert response.status_code == 200
- assert '+44 7700 900981' in content
- assert '+44 7700 900982' in content
- assert '+44 7700 900983' in content
- assert '+44 7700 900984' in content
- assert '+44 7700 900985' in content
- assert '1 more row not shown' in content
+ assert '+44 7700 9009 01' in content
+ assert '+44 7700 9009 15' in content
+ assert '+44 7700 9009 16' not in content
+ assert '3 rows not shown' in content
def test_create_job_should_call_api(
@@ -206,7 +224,14 @@ def test_check_messages_should_revalidate_file_when_uploading_file(
mocker.patch(
'app.main.views.send.s3download',
- return_value='phone number,name,,,\n++44 7700 900981,test1,,,\n+44 7700 900981,test2,,,\n ,,, \n ,,, \t \t \n'
+ return_value="""
+ phone number,name,,,
+ ++44 7700 900981,test1,,,
+ +44 7700 900981,test2,,,
+ ,,,
+ ,,, \t \t
+
+ """
)
with app_.test_request_context():
with app_.test_client() as client:
@@ -214,10 +239,12 @@ def test_check_messages_should_revalidate_file_when_uploading_file(
with client.session_transaction() as session:
session['upload_data'] = {'original_file_name': 'invalid.csv',
'template_id': job_data['template'],
- 'notification_count': job_data['notification_count']}
+ 'notification_count': job_data['notification_count'],
+ 'valid': True}
response = client.post(
url_for('main.check_messages', service_id=service_id, upload_id=job_data['id']),
- data={'file': (BytesIO(), 'invalid.csv')},
+ data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
+ content_type='multipart/form-data',
follow_redirects=True
)
assert response.status_code == 200
diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py
index f0210dd7e..65f7030e7 100644
--- a/tests/app/main/views/test_service_settings.py
+++ b/tests/app/main/views/test_service_settings.py
@@ -54,8 +54,9 @@ def test_should_redirect_after_change_service_name(app_,
with app_.test_client() as client:
client.login(api_user_active)
service_id = 123
- response = client.post(url_for(
- 'main.service_name_change', service_id=service_id))
+ response = client.post(
+ url_for('main.service_name_change', service_id=service_id),
+ data={'name': "new name"})
assert response.status_code == 302
settings_url = url_for(
@@ -64,6 +65,27 @@ def test_should_redirect_after_change_service_name(app_,
assert mock_get_service.called
+def test_should_not_allow_duplicate_names(app_,
+ api_user_active,
+ mock_get_service,
+ mock_get_user,
+ mock_get_user_by_email,
+ mock_login,
+ mock_has_permissions,
+ mock_get_services):
+ with app_.test_request_context():
+ with app_.test_client() as client:
+ client.login(api_user_active)
+ service_id = 123
+ response = client.post(
+ url_for('main.service_name_change', service_id=service_id),
+ data={'name': "service_one"})
+
+ assert response.status_code == 200
+ resp_data = response.get_data(as_text=True)
+ assert 'This service name is already in use' in resp_data
+
+
def test_should_show_service_name_confirmation(app_,
api_user_active,
mock_get_service,
@@ -112,6 +134,32 @@ def test_should_redirect_after_service_name_confirmation(app_,
assert mock_update_service.called
+def test_should_raise_duplicate_name_handled(app_,
+ api_user_active,
+ mock_get_service,
+ mock_update_service_raise_httperror_duplicate_name,
+ mock_get_user,
+ mock_get_user_by_email,
+ mock_login,
+ mock_verify_password,
+ mock_has_permissions):
+ with app_.test_request_context():
+ with app_.test_client() as client:
+ client.login(api_user_active)
+ service_id = 123
+ service_new_name = 'New Name'
+ with client.session_transaction() as session:
+ session['service_name_change'] = service_new_name
+ response = client.post(url_for(
+ 'main.service_name_change_confirm', service_id=service_id))
+
+ assert response.status_code == 302
+ name_change_url = url_for(
+ 'main.service_name_change', service_id=service_id, _external=True)
+ resp_data = response.get_data(as_text=True)
+ assert name_change_url == response.location
+
+
def test_should_show_request_to_go_live(app_,
api_user_active,
mock_get_service,
diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py
index ef8569338..c3cc669d1 100644
--- a/tests/app/main/views/test_sign_in.py
+++ b/tests/app/main/views/test_sign_in.py
@@ -58,18 +58,6 @@ def test_should_return_locked_out_true_when_user_is_locked(app_,
assert 'Username or password is incorrect' in resp.get_data(as_text=True)
-def test_should_return_active_user_is_false_if_user_is_inactive(app_, mock_get_user_by_email_inactive):
-
- with app_.test_request_context():
- response = app_.test_client().post(
- url_for('main.sign_in'), data={
- 'email_address': 'inactive_user@example.gov.uk',
- 'password': 'val1dPassw0rd!'})
-
- assert response.status_code == 200
- assert 'Username or password is incorrect' in response.get_data(as_text=True)
-
-
def test_should_return_200_when_user_does_not_exist(app_, mock_get_user_by_email_not_found):
with app_.test_request_context():
response = app_.test_client().post(
diff --git a/tests/app/main/views/test_sign_out.py b/tests/app/main/views/test_sign_out.py
index f4d7019a8..a6b8e5fcb 100644
--- a/tests/app/main/views/test_sign_out.py
+++ b/tests/app/main/views/test_sign_out.py
@@ -19,8 +19,6 @@ def test_sign_out_user(app_,
mock_login,
mock_get_jobs):
with app_.test_request_context():
- email = 'valid@example.gov.uk'
- password = 'val1dPassw0rd!'
with app_.test_client() as client:
client.login(api_user_active)
with client.session_transaction() as session:
diff --git a/tests/app/main/views/test_verify.py b/tests/app/main/views/test_verify.py
index 4b5d790da..d149ba362 100644
--- a/tests/app/main/views/test_verify.py
+++ b/tests/app/main/views/test_verify.py
@@ -1,8 +1,4 @@
-from flask import json, url_for
-from app.main.dao import users_dao
-from tests import create_test_api_user
-
-import pytest
+from flask import url_for
def test_should_return_verify_template(app_,
@@ -67,3 +63,26 @@ def test_should_return_200_when_codes_are_wrong(app_,
assert response.status_code == 200
resp_data = response.get_data(as_text=True)
assert resp_data.count('Code not found') == 2
+
+
+def test_should_only_check_codes_in_validation_if_both_are_present(app_,
+ api_user_active,
+ mock_get_user,
+ mock_update_user,
+ mock_check_verify_code):
+ with app_.test_request_context():
+ with app_.test_client() as client:
+ with client.session_transaction() as session:
+ session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
+ response = client.post(url_for('main.verify'), data={'sms_code': '12345'})
+ assert response.status_code == 200
+ assert not mock_check_verify_code.called
+
+ response = client.post(url_for('main.verify'), data={'email_code': '12345'})
+ assert response.status_code == 200
+ assert not mock_check_verify_code.called
+
+ response = client.post(url_for('main.verify'), data={'sms_code': '12345', 'email_code': '12345'})
+ assert response.status_code == 302
+ assert mock_check_verify_code.called
+ assert mock_check_verify_code.call_count == 2
diff --git a/tests/conftest.py b/tests/conftest.py
index 93dce2265..9d5c88f39 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,6 @@
import uuid
from datetime import date, datetime, timedelta
+from unittest.mock import Mock
import pytest
from app import create_app
@@ -18,6 +19,8 @@ from app.notify_client.models import (
InvitedUser
)
+from notifications_python_client.errors import HTTPError
+
@pytest.fixture(scope='session')
def app_(request):
@@ -67,7 +70,7 @@ def mock_create_service(mocker):
service = service_json(
101, service_name, [user_id], limit=limit,
active=active, restricted=restricted)
- return {'data': service}
+ return service['id']
return mocker.patch(
'app.notifications_api_client.create_service', side_effect=_create)
@@ -90,6 +93,24 @@ def mock_update_service(mocker):
'app.notifications_api_client.update_service', side_effect=_update)
+@pytest.fixture(scope='function')
+def mock_update_service_raise_httperror_duplicate_name(mocker):
+
+ def _update(service_id,
+ service_name,
+ active,
+ limit,
+ restricted,
+ users):
+ json_mock = Mock(return_value={'message': {'name': ["Duplicate service name '{}'".format(service_name)]}})
+ resp_mock = Mock(status_code=400, json=json_mock)
+ http_error = HTTPError(response=resp_mock, message="Default message")
+ raise http_error
+
+ return mocker.patch(
+ 'app.notifications_api_client.update_service', side_effect=_update)
+
+
SERVICE_ONE_ID = "596364a0-858e-42c8-9062-a8fe822260eb"
SERVICE_TWO_ID = "147ad62a-2951-4fa1-9ca0-093cd1a52c52"
@@ -311,6 +332,7 @@ def mock_register_user(mocker, api_user_pending):
@pytest.fixture(scope='function')
def mock_get_user(mocker, api_user_active):
def _get_user(id):
+ api_user_active.id = id
return api_user_active
return mocker.patch(
'app.user_api_client.get_user', side_effect=_get_user)
@@ -380,12 +402,7 @@ def mock_get_user_by_email_locked(mocker, api_user_locked):
@pytest.fixture(scope='function')
def mock_get_user_by_email_inactive(mocker, api_user_pending):
-
- def _get_user(email_address):
- api_user_pending._email_address = email_address
- api_user_pending._is_locked = True
- return api_user_pending
- return mocker.patch('app.user_api_client.get_user_by_email', side_effect=_get_user)
+ return mocker.patch('app.user_api_client.get_user_by_email', return_value=api_user_pending)
@pytest.fixture(scope='function')