Rename variables and functions in tests

To reflect the new name of the feature.
This commit is contained in:
Chris Hill-Scott
2020-07-28 11:22:19 +01:00
parent 716eb67bfd
commit 65346852ed
9 changed files with 66 additions and 66 deletions

View File

@@ -809,13 +809,13 @@ def notify_service(notify_db, notify_db_session):
@pytest.fixture(scope='function') @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) 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() notify_db.session.commit()
return whitelisted_user return guest_list_user
@pytest.fixture @pytest.fixture

View File

@@ -13,27 +13,27 @@ from app.dao.service_whitelist_dao import (
from tests.app.db import create_service from tests.app.db import create_service
def test_fetch_service_whitelist_gets_whitelists(sample_service_whitelist): def test_fetch_service_guest_list_gets_guest_lists(sample_service_guest_list):
whitelist = dao_fetch_service_guest_list(sample_service_whitelist.service_id) guest_list = dao_fetch_service_guest_list(sample_service_guest_list.service_id)
assert len(whitelist) == 1 assert len(guest_list) == 1
assert whitelist[0].id == sample_service_whitelist.id 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 assert len(dao_fetch_service_guest_list(uuid.uuid4())) == 0
def test_add_and_commit_whitelisted_contacts_saves_data(sample_service): def test_add_and_commit_guest_list_contacts_saves_data(sample_service):
whitelist = ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'foo@example.com') 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() db_contents = ServiceGuestList.query.all()
assert len(db_contents) == 1 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_1 = create_service(service_name="service 1")
service_2 = create_service(service_name="service 2") service_2 = create_service(service_name="service 2")
dao_add_and_commit_guest_list_contacts([ 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 assert len(service_2.guest_list) == 1
def test_remove_service_whitelist_does_not_commit(notify_db, sample_service_whitelist): def test_remove_service_guest_list_does_not_commit(notify_db, sample_service_guest_list):
dao_remove_service_guest_list(sample_service_whitelist.service_id) 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 # since dao_remove_service_guest_list doesn't commit, we can still rollback its changes
notify_db.session.rollback() notify_db.session.rollback()

View File

@@ -738,17 +738,17 @@ def create_ft_notification_status(
return data 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: 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: 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: 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() db.session.commit()
return whitelisted_user return guest_list_user
def create_complaint(service=None, def create_complaint(service=None,

View File

@@ -25,7 +25,7 @@ from tests.app.db import (
create_api_key, create_api_key,
create_notification, create_notification,
create_service, create_service,
create_service_whitelist, create_service_guest_list,
create_template, create_template,
create_reply_to_email, 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', [ @pytest.mark.parametrize('notification_type, to', [
(SMS_TYPE, '07827992635'), (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, client,
sample_service_whitelist, sample_service_guest_list,
notification_type, notification_type,
to, to,
key_type, key_type,
mocker mocker
): ):
service = sample_service_whitelist.service service = sample_service_guest_list.service
service.restricted = True service.restricted = True
service.message_limit = 2 service.message_limit = 2
apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type)) apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
template = create_template(service, template_type=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] assert to not in [member.recipient for member in service.guest_list]
create_notification(template=template) 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', [ @pytest.mark.parametrize('notification_type, to', [
(SMS_TYPE, '07123123123'), (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, client,
sample_service, sample_service,
notification_type, 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)) apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
template = create_template(sample_service, template_type=notification_type) template = create_template(sample_service, template_type=notification_type)
if notification_type == SMS_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: 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] assert to in [member.recipient for member in sample_service.guest_list]
create_notification(template=template) create_notification(template=template)

View File

@@ -39,7 +39,7 @@ from tests.app.db import (
create_reply_to_email, create_reply_to_email,
create_service, create_service,
create_service_sms_sender, create_service_sms_sender,
create_service_whitelist, create_service_guest_list,
create_template, create_template,
) )
from unittest.mock import ANY 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 serialised_service) is None
def test_service_can_send_to_recipient_passes_for_whitelisted_recipient_passes(sample_service): def test_service_can_send_to_recipient_passes_for_guest_list_recipient_passes(sample_service):
create_service_whitelist(sample_service, email_address="some_other_email@test.com") create_service_guest_list(sample_service, email_address="some_other_email@test.com")
assert service_can_send_to_recipient("some_other_email@test.com", assert service_can_send_to_recipient("some_other_email@test.com",
'team', 'team',
sample_service) is None 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', assert service_can_send_to_recipient('07513332413',
'team', 'team',
sample_service) is None 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"}, {"email_address": "some_other_email@test.com"},
{"mobile_number": "07513332413"}, {"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,
notify_db_session, notify_db_session,
sample_service, sample_service,
recipient, recipient,
): ):
create_service_whitelist(sample_service, **recipient) create_service_guest_list(sample_service, **recipient)
with pytest.raises(BadRequestError) as exec_info: with pytest.raises(BadRequestError) as exec_info:
service_can_send_to_recipient( service_can_send_to_recipient(
next(iter(recipient.values())), next(iter(recipient.values())),

View File

@@ -259,9 +259,9 @@ def test_send_one_off_notification_raises_if_invalid_recipient(notify_db_session
@pytest.mark.parametrize('recipient', [ @pytest.mark.parametrize('recipient', [
'07700 900 001', # not in team or whitelist '07700 900 001', # not in team or guest_list
'07700900123', # in whitelist '07700900123', # in guest_list
'+447700-900-123', # in whitelist in different format '+447700-900-123', # in guest_list in different format
]) ])
def test_send_one_off_notification_raises_if_cant_send_to_recipient( def test_send_one_off_notification_raises_if_cant_send_to_recipient(
notify_db_session, notify_db_session,

View File

@@ -15,18 +15,18 @@ from app.dao.service_whitelist_dao import dao_add_and_commit_guest_list_contacts
'service/{}/whitelist', 'service/{}/whitelist',
'service/{}/guest-list', 'service/{}/guest-list',
)) ))
def test_get_whitelist_returns_data(client, sample_service_whitelist, url_path): def test_get_guest_list_returns_data(client, sample_service_guest_list, url_path):
service_id = sample_service_whitelist.service_id service_id = sample_service_guest_list.service_id
response = client.get(url_path.format(service_id), headers=[create_authorization_header()]) response = client.get(url_path.format(service_id), headers=[create_authorization_header()])
assert response.status_code == 200 assert response.status_code == 200
assert json.loads(response.get_data(as_text=True)) == { assert json.loads(response.get_data(as_text=True)) == {
'email_addresses': [sample_service_whitelist.recipient], 'email_addresses': [sample_service_guest_list.recipient],
'phone_numbers': [] '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([ dao_add_and_commit_guest_list_contacts([
ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'), ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'),
ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '07123456789'), 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']) 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()) path = 'service/{}/guest-list'.format(uuid.uuid4())
response = client.get(path, headers=[create_authorization_header()]) 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' 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) path = 'service/{}/guest-list'.format(sample_service.id)
response = client.get(path, headers=[create_authorization_header()]) 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/{}/whitelist',
'service/{}/guest-list', '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 = { data = {
'email_addresses': ['foo@bar.com'], 'email_addresses': ['foo@bar.com'],
'phone_numbers': ['07123456789'] 'phone_numbers': ['07123456789']
} }
response = client.put( response = client.put(
url_path.format(sample_service_whitelist.service_id), url_path.format(sample_service_guest_list.service_id),
data=json.dumps(data), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), create_authorization_header()] headers=[('Content-Type', 'application/json'), create_authorization_header()]
) )
assert response.status_code == 204 assert response.status_code == 204
whitelist = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all() guest_list = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all()
assert len(whitelist) == 2 assert len(guest_list) == 2
assert whitelist[0].recipient == '07123456789' assert guest_list[0].recipient == '07123456789'
assert whitelist[1].recipient == 'foo@bar.com' 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 = { data = {
'email_addresses': [''], 'email_addresses': [''],
@@ -90,7 +90,7 @@ def test_update_whitelist_doesnt_remove_old_whitelist_if_error(client, sample_se
} }
response = client.put( 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), data=json.dumps(data),
headers=[('Content-Type', 'application/json'), create_authorization_header()] 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', 'result': 'error',
'message': 'Invalid guest list: "" is not a valid email address or phone number' 'message': 'Invalid guest list: "" is not a valid email address or phone number'
} }
whitelist = ServiceGuestList.query.one() guest_list = ServiceGuestList.query.one()
assert whitelist.id == sample_service_whitelist.id assert guest_list.id == sample_service_guest_list.id

View File

@@ -37,19 +37,19 @@ from tests.app.db import (
'07700 900678', '07700 900678',
'+44 7700 900678' '+44 7700 900678'
]) ])
def test_should_build_service_whitelist_from_mobile_number(mobile_number): def test_should_build_service_guest_list_from_mobile_number(mobile_number):
service_whitelist = ServiceGuestList.from_string('service_id', MOBILE_TYPE, 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', [ @pytest.mark.parametrize('email_address', [
'test@example.com' 'test@example.com'
]) ])
def test_should_build_service_whitelist_from_email_address(email_address): def test_should_build_service_guest_list_from_email_address(email_address):
service_whitelist = ServiceGuestList.from_string('service_id', EMAIL_TYPE, 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', [ @pytest.mark.parametrize('contact, recipient_type', [
@@ -57,7 +57,7 @@ def test_should_build_service_whitelist_from_email_address(email_address):
('07700dsadsad', MOBILE_TYPE), ('07700dsadsad', MOBILE_TYPE),
('gmail.com', EMAIL_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): with pytest.raises(ValueError):
ServiceGuestList.from_string('service_id', recipient_type, contact) ServiceGuestList.from_string('service_id', recipient_type, contact)

View File

@@ -652,7 +652,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_notification(
@pytest.mark.parametrize('restricted', [True, False]) @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 notify_db_session, client, restricted
): ):
service = create_service(restricted=restricted, service_permissions=[SMS_TYPE, INTERNATIONAL_SMS_TYPE]) service = create_service(restricted=restricted, service_permissions=[SMS_TYPE, INTERNATIONAL_SMS_TYPE])