From 65346852edad514fb6013c16505d3c7f0f3e5573 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 28 Jul 2020 11:22:19 +0100 Subject: [PATCH] Rename variables and functions in tests To reflect the new name of the feature. --- tests/app/conftest.py | 8 ++--- tests/app/dao/test_service_whitelist_dao.py | 24 +++++++------- tests/app/db.py | 12 +++---- .../rest/test_send_notification.py | 22 ++++++------- tests/app/notifications/test_validators.py | 12 +++---- .../service/test_send_one_off_notification.py | 6 ++-- tests/app/service/test_service_whitelist.py | 32 +++++++++---------- tests/app/test_model.py | 14 ++++---- .../notifications/test_post_notifications.py | 2 +- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 1698d594b..5fd67f4b6 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -809,13 +809,13 @@ def notify_service(notify_db, notify_db_session): @pytest.fixture(scope='function') -def sample_service_whitelist(notify_db, notify_db_session): +def sample_service_guest_list(notify_db, notify_db_session): service = create_service(check_if_service_exists=True) - whitelisted_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, 'whitelisted_user@digital.gov.uk') + guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, 'guest_list_user@digital.gov.uk') - notify_db.session.add(whitelisted_user) + notify_db.session.add(guest_list_user) notify_db.session.commit() - return whitelisted_user + return guest_list_user @pytest.fixture diff --git a/tests/app/dao/test_service_whitelist_dao.py b/tests/app/dao/test_service_whitelist_dao.py index 10b7c3d93..695f98ed7 100644 --- a/tests/app/dao/test_service_whitelist_dao.py +++ b/tests/app/dao/test_service_whitelist_dao.py @@ -13,27 +13,27 @@ from app.dao.service_whitelist_dao import ( from tests.app.db import create_service -def test_fetch_service_whitelist_gets_whitelists(sample_service_whitelist): - whitelist = dao_fetch_service_guest_list(sample_service_whitelist.service_id) - assert len(whitelist) == 1 - assert whitelist[0].id == sample_service_whitelist.id +def test_fetch_service_guest_list_gets_guest_lists(sample_service_guest_list): + guest_list = dao_fetch_service_guest_list(sample_service_guest_list.service_id) + assert len(guest_list) == 1 + assert guest_list[0].id == sample_service_guest_list.id -def test_fetch_service_whitelist_ignores_other_service(sample_service_whitelist): +def test_fetch_service_guest_list_ignores_other_service(sample_service_guest_list): assert len(dao_fetch_service_guest_list(uuid.uuid4())) == 0 -def test_add_and_commit_whitelisted_contacts_saves_data(sample_service): - whitelist = ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'foo@example.com') +def test_add_and_commit_guest_list_contacts_saves_data(sample_service): + guest_list = ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'foo@example.com') - dao_add_and_commit_guest_list_contacts([whitelist]) + dao_add_and_commit_guest_list_contacts([guest_list]) db_contents = ServiceGuestList.query.all() assert len(db_contents) == 1 - assert db_contents[0].id == whitelist.id + assert db_contents[0].id == guest_list.id -def test_remove_service_whitelist_only_removes_for_my_service(notify_db, notify_db_session): +def test_remove_service_guest_list_only_removes_for_my_service(notify_db, notify_db_session): service_1 = create_service(service_name="service 1") service_2 = create_service(service_name="service 2") dao_add_and_commit_guest_list_contacts([ @@ -47,8 +47,8 @@ def test_remove_service_whitelist_only_removes_for_my_service(notify_db, notify_ assert len(service_2.guest_list) == 1 -def test_remove_service_whitelist_does_not_commit(notify_db, sample_service_whitelist): - dao_remove_service_guest_list(sample_service_whitelist.service_id) +def test_remove_service_guest_list_does_not_commit(notify_db, sample_service_guest_list): + dao_remove_service_guest_list(sample_service_guest_list.service_id) # since dao_remove_service_guest_list doesn't commit, we can still rollback its changes notify_db.session.rollback() diff --git a/tests/app/db.py b/tests/app/db.py index 012d55e18..2dc048dae 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -738,17 +738,17 @@ def create_ft_notification_status( return data -def create_service_whitelist(service, email_address=None, mobile_number=None): +def create_service_guest_list(service, email_address=None, mobile_number=None): if email_address: - whitelisted_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, email_address) + guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, email_address) elif mobile_number: - whitelisted_user = ServiceGuestList.from_string(service.id, MOBILE_TYPE, mobile_number) + guest_list_user = ServiceGuestList.from_string(service.id, MOBILE_TYPE, mobile_number) else: - whitelisted_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, 'whitelisted_user@digital.gov.uk') + guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, 'guest_list_user@digital.gov.uk') - db.session.add(whitelisted_user) + db.session.add(guest_list_user) db.session.commit() - return whitelisted_user + return guest_list_user def create_complaint(service=None, diff --git a/tests/app/notifications/rest/test_send_notification.py b/tests/app/notifications/rest/test_send_notification.py index 63856a47e..946f46521 100644 --- a/tests/app/notifications/rest/test_send_notification.py +++ b/tests/app/notifications/rest/test_send_notification.py @@ -25,7 +25,7 @@ from tests.app.db import ( create_api_key, create_notification, create_service, - create_service_whitelist, + create_service_guest_list, create_template, create_reply_to_email, ) @@ -776,23 +776,23 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number( ]) @pytest.mark.parametrize('notification_type, to', [ (SMS_TYPE, '07827992635'), - (EMAIL_TYPE, 'non_whitelist_recipient@mail.com')] + (EMAIL_TYPE, 'non_guest_list_recipient@mail.com')] ) -def test_should_not_send_notification_to_non_whitelist_recipient_in_trial_mode( +def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode( client, - sample_service_whitelist, + sample_service_guest_list, notification_type, to, key_type, mocker ): - service = sample_service_whitelist.service + service = sample_service_guest_list.service service.restricted = True service.message_limit = 2 apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type)) template = create_template(service, template_type=notification_type) - assert sample_service_whitelist.service_id == service.id + assert sample_service_guest_list.service_id == service.id assert to not in [member.recipient for member in service.guest_list] create_notification(template=template) @@ -830,9 +830,9 @@ def test_should_not_send_notification_to_non_whitelist_recipient_in_trial_mode( ]) @pytest.mark.parametrize('notification_type, to', [ (SMS_TYPE, '07123123123'), - (EMAIL_TYPE, 'whitelist_recipient@mail.com')] + (EMAIL_TYPE, 'guest_list_recipient@mail.com')] ) -def test_should_send_notification_to_whitelist_recipient( +def test_should_send_notification_to_guest_list_recipient( client, sample_service, notification_type, @@ -847,11 +847,11 @@ def test_should_send_notification_to_whitelist_recipient( apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type)) template = create_template(sample_service, template_type=notification_type) if notification_type == SMS_TYPE: - service_whitelist = create_service_whitelist(sample_service, mobile_number=to) + service_guest_list = create_service_guest_list(sample_service, mobile_number=to) elif notification_type == EMAIL_TYPE: - service_whitelist = create_service_whitelist(sample_service, email_address=to) + service_guest_list = create_service_guest_list(sample_service, email_address=to) - assert service_whitelist.service_id == sample_service.id + assert service_guest_list.service_id == sample_service.id assert to in [member.recipient for member in sample_service.guest_list] create_notification(template=template) diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index f69060bf1..57bd88882 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -39,7 +39,7 @@ from tests.app.db import ( create_reply_to_email, create_service, create_service_sms_sender, - create_service_whitelist, + create_service_guest_list, create_template, ) from unittest.mock import ANY @@ -245,12 +245,12 @@ def test_service_can_send_to_recipient_passes_for_live_service_non_team_member(k serialised_service) is None -def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(sample_service): - create_service_whitelist(sample_service, email_address="some_other_email@test.com") +def test_service_can_send_to_recipient_passes_for_guest_list_recipient_passes(sample_service): + create_service_guest_list(sample_service, email_address="some_other_email@test.com") assert service_can_send_to_recipient("some_other_email@test.com", 'team', sample_service) is None - create_service_whitelist(sample_service, mobile_number='07513332413') + create_service_guest_list(sample_service, mobile_number='07513332413') assert service_can_send_to_recipient('07513332413', 'team', sample_service) is None @@ -260,13 +260,13 @@ def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(s {"email_address": "some_other_email@test.com"}, {"mobile_number": "07513332413"}, ]) -def test_service_can_send_to_recipient_fails_when_ignoring_whitelist( +def test_service_can_send_to_recipient_fails_when_ignoring_guest_list( notify_db, notify_db_session, sample_service, recipient, ): - create_service_whitelist(sample_service, **recipient) + create_service_guest_list(sample_service, **recipient) with pytest.raises(BadRequestError) as exec_info: service_can_send_to_recipient( next(iter(recipient.values())), diff --git a/tests/app/service/test_send_one_off_notification.py b/tests/app/service/test_send_one_off_notification.py index af1bc353a..685d42286 100644 --- a/tests/app/service/test_send_one_off_notification.py +++ b/tests/app/service/test_send_one_off_notification.py @@ -259,9 +259,9 @@ def test_send_one_off_notification_raises_if_invalid_recipient(notify_db_session @pytest.mark.parametrize('recipient', [ - '07700 900 001', # not in team or whitelist - '07700900123', # in whitelist - '+447700-900-123', # in whitelist in different format + '07700 900 001', # not in team or guest_list + '07700900123', # in guest_list + '+447700-900-123', # in guest_list in different format ]) def test_send_one_off_notification_raises_if_cant_send_to_recipient( notify_db_session, diff --git a/tests/app/service/test_service_whitelist.py b/tests/app/service/test_service_whitelist.py index 365d0feab..9f7c8b6dd 100644 --- a/tests/app/service/test_service_whitelist.py +++ b/tests/app/service/test_service_whitelist.py @@ -15,18 +15,18 @@ from app.dao.service_whitelist_dao import dao_add_and_commit_guest_list_contacts 'service/{}/whitelist', 'service/{}/guest-list', )) -def test_get_whitelist_returns_data(client, sample_service_whitelist, url_path): - service_id = sample_service_whitelist.service_id +def test_get_guest_list_returns_data(client, sample_service_guest_list, url_path): + service_id = sample_service_guest_list.service_id response = client.get(url_path.format(service_id), headers=[create_authorization_header()]) assert response.status_code == 200 assert json.loads(response.get_data(as_text=True)) == { - 'email_addresses': [sample_service_whitelist.recipient], + 'email_addresses': [sample_service_guest_list.recipient], 'phone_numbers': [] } -def test_get_whitelist_separates_emails_and_phones(client, sample_service): +def test_get_guest_list_separates_emails_and_phones(client, sample_service): dao_add_and_commit_guest_list_contacts([ ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'), ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '07123456789'), @@ -40,7 +40,7 @@ def test_get_whitelist_separates_emails_and_phones(client, sample_service): assert sorted(json_resp['phone_numbers']) == sorted(['+1800-555-555', '07123456789']) -def test_get_whitelist_404s_with_unknown_service_id(client): +def test_get_guest_list_404s_with_unknown_service_id(client): path = 'service/{}/guest-list'.format(uuid.uuid4()) response = client.get(path, headers=[create_authorization_header()]) @@ -50,7 +50,7 @@ def test_get_whitelist_404s_with_unknown_service_id(client): assert json_resp['message'] == 'No result found' -def test_get_whitelist_returns_no_data(client, sample_service): +def test_get_guest_list_returns_no_data(client, sample_service): path = 'service/{}/guest-list'.format(sample_service.id) response = client.get(path, headers=[create_authorization_header()]) @@ -63,26 +63,26 @@ def test_get_whitelist_returns_no_data(client, sample_service): 'service/{}/whitelist', 'service/{}/guest-list', )) -def test_update_whitelist_replaces_old_whitelist(client, sample_service_whitelist, url_path): +def test_update_guest_list_replaces_old_guest_list(client, sample_service_guest_list, url_path): data = { 'email_addresses': ['foo@bar.com'], 'phone_numbers': ['07123456789'] } response = client.put( - url_path.format(sample_service_whitelist.service_id), + url_path.format(sample_service_guest_list.service_id), data=json.dumps(data), headers=[('Content-Type', 'application/json'), create_authorization_header()] ) assert response.status_code == 204 - whitelist = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all() - assert len(whitelist) == 2 - assert whitelist[0].recipient == '07123456789' - assert whitelist[1].recipient == 'foo@bar.com' + guest_list = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all() + assert len(guest_list) == 2 + assert guest_list[0].recipient == '07123456789' + assert guest_list[1].recipient == 'foo@bar.com' -def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_service_whitelist): +def test_update_guest_list_doesnt_remove_old_guest_list_if_error(client, sample_service_guest_list): data = { 'email_addresses': [''], @@ -90,7 +90,7 @@ def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_se } response = client.put( - 'service/{}/guest-list'.format(sample_service_whitelist.service_id), + 'service/{}/guest-list'.format(sample_service_guest_list.service_id), data=json.dumps(data), headers=[('Content-Type', 'application/json'), create_authorization_header()] ) @@ -100,5 +100,5 @@ def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_se 'result': 'error', 'message': 'Invalid guest list: "" is not a valid email address or phone number' } - whitelist = ServiceGuestList.query.one() - assert whitelist.id == sample_service_whitelist.id + guest_list = ServiceGuestList.query.one() + assert guest_list.id == sample_service_guest_list.id diff --git a/tests/app/test_model.py b/tests/app/test_model.py index e44d50221..10e0cd5cc 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -37,19 +37,19 @@ from tests.app.db import ( '07700 900678', '+44 7700 900678' ]) -def test_should_build_service_whitelist_from_mobile_number(mobile_number): - service_whitelist = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number) +def test_should_build_service_guest_list_from_mobile_number(mobile_number): + service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number) - assert service_whitelist.recipient == mobile_number + assert service_guest_list.recipient == mobile_number @pytest.mark.parametrize('email_address', [ 'test@example.com' ]) -def test_should_build_service_whitelist_from_email_address(email_address): - service_whitelist = ServiceGuestList.from_string('service_id', EMAIL_TYPE, email_address) +def test_should_build_service_guest_list_from_email_address(email_address): + service_guest_list = ServiceGuestList.from_string('service_id', EMAIL_TYPE, email_address) - assert service_whitelist.recipient == email_address + assert service_guest_list.recipient == email_address @pytest.mark.parametrize('contact, recipient_type', [ @@ -57,7 +57,7 @@ def test_should_build_service_whitelist_from_email_address(email_address): ('07700dsadsad', MOBILE_TYPE), ('gmail.com', EMAIL_TYPE) ]) -def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type, contact): +def test_should_not_build_service_guest_list_from_invalid_contact(recipient_type, contact): with pytest.raises(ValueError): ServiceGuestList.from_string('service_id', recipient_type, contact) diff --git a/tests/app/v2/notifications/test_post_notifications.py b/tests/app/v2/notifications/test_post_notifications.py index 6d1ea71c2..bdb33b7bc 100644 --- a/tests/app/v2/notifications/test_post_notifications.py +++ b/tests/app/v2/notifications/test_post_notifications.py @@ -652,7 +652,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_notification( @pytest.mark.parametrize('restricted', [True, False]) -def test_post_sms_notification_returns_400_if_number_not_whitelisted( +def test_post_sms_notification_returns_400_if_number_not_in_guest_list( notify_db_session, client, restricted ): service = create_service(restricted=restricted, service_permissions=[SMS_TYPE, INTERNATIONAL_SMS_TYPE])