2016-09-22 11:56:26 +01:00
|
|
|
|
import pytest
|
2017-04-20 11:52:00 +01:00
|
|
|
|
from freezegun import freeze_time
|
2017-11-10 11:33:42 +00:00
|
|
|
|
from sqlalchemy.exc import IntegrityError
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
2017-07-03 16:04:21 +01:00
|
|
|
|
from app import encryption
|
2016-09-27 13:44:29 +01:00
|
|
|
|
from app.models import (
|
2016-11-25 14:55:29 +00:00
|
|
|
|
EMAIL_TYPE,
|
2021-03-10 13:55:06 +00:00
|
|
|
|
MOBILE_TYPE,
|
2016-11-25 14:55:29 +00:00
|
|
|
|
NOTIFICATION_CREATED,
|
2017-10-23 15:57:00 +01:00
|
|
|
|
NOTIFICATION_DELIVERED,
|
2016-11-25 14:55:29 +00:00
|
|
|
|
NOTIFICATION_FAILED,
|
2021-03-10 13:55:06 +00:00
|
|
|
|
NOTIFICATION_PENDING,
|
|
|
|
|
|
NOTIFICATION_SENDING,
|
2017-10-23 15:57:00 +01:00
|
|
|
|
NOTIFICATION_STATUS_LETTER_ACCEPTED,
|
|
|
|
|
|
NOTIFICATION_STATUS_LETTER_RECEIVED,
|
2017-09-20 15:21:05 +01:00
|
|
|
|
NOTIFICATION_STATUS_TYPES_FAILED,
|
2018-03-07 15:42:59 +00:00
|
|
|
|
NOTIFICATION_TECHNICAL_FAILURE,
|
2021-03-10 13:55:06 +00:00
|
|
|
|
PRECOMPILED_TEMPLATE_NAME,
|
|
|
|
|
|
SMS_TYPE,
|
|
|
|
|
|
Notification,
|
|
|
|
|
|
ServiceGuestList,
|
2016-11-25 14:55:29 +00:00
|
|
|
|
)
|
2017-09-21 16:08:49 +01:00
|
|
|
|
from tests.app.db import (
|
|
|
|
|
|
create_inbound_number,
|
2018-09-25 15:59:08 +01:00
|
|
|
|
create_letter_contact,
|
2021-03-10 13:55:06 +00:00
|
|
|
|
create_notification,
|
|
|
|
|
|
create_reply_to_email,
|
|
|
|
|
|
create_service,
|
2018-11-08 16:44:57 +00:00
|
|
|
|
create_template,
|
2021-03-10 13:55:06 +00:00
|
|
|
|
create_template_folder,
|
2017-09-21 16:08:49 +01:00
|
|
|
|
)
|
2016-09-07 13:44:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-09-22 11:56:26 +01:00
|
|
|
|
@pytest.mark.parametrize('mobile_number', [
|
2023-01-06 10:02:23 -05:00
|
|
|
|
'+447700900855',
|
2023-01-04 16:35:25 -05:00
|
|
|
|
'+12348675309'
|
2016-09-22 11:56:26 +01:00
|
|
|
|
])
|
2020-07-28 11:22:19 +01:00
|
|
|
|
def test_should_build_service_guest_list_from_mobile_number(mobile_number):
|
|
|
|
|
|
service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number)
|
2016-09-22 11:56:26 +01:00
|
|
|
|
|
2020-07-28 11:22:19 +01:00
|
|
|
|
assert service_guest_list.recipient == mobile_number
|
2016-09-22 11:56:26 +01:00
|
|
|
|
|
2016-09-22 17:18:52 +01:00
|
|
|
|
|
2016-09-22 11:56:26 +01:00
|
|
|
|
@pytest.mark.parametrize('email_address', [
|
|
|
|
|
|
'test@example.com'
|
|
|
|
|
|
])
|
2020-07-28 11:22:19 +01:00
|
|
|
|
def test_should_build_service_guest_list_from_email_address(email_address):
|
|
|
|
|
|
service_guest_list = ServiceGuestList.from_string('service_id', EMAIL_TYPE, email_address)
|
2016-09-22 11:56:26 +01:00
|
|
|
|
|
2020-07-28 11:22:19 +01:00
|
|
|
|
assert service_guest_list.recipient == email_address
|
2016-09-22 11:56:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-09-27 13:44:29 +01:00
|
|
|
|
@pytest.mark.parametrize('contact, recipient_type', [
|
|
|
|
|
|
('', None),
|
|
|
|
|
|
('07700dsadsad', MOBILE_TYPE),
|
|
|
|
|
|
('gmail.com', EMAIL_TYPE)
|
2016-09-22 11:56:26 +01:00
|
|
|
|
])
|
2020-07-28 11:22:19 +01:00
|
|
|
|
def test_should_not_build_service_guest_list_from_invalid_contact(recipient_type, contact):
|
2016-09-22 11:56:26 +01:00
|
|
|
|
with pytest.raises(ValueError):
|
2020-07-28 10:22:13 +01:00
|
|
|
|
ServiceGuestList.from_string('service_id', recipient_type, contact)
|
2016-11-25 14:55:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('initial_statuses, expected_statuses', [
|
|
|
|
|
|
# passing in single statuses as strings
|
|
|
|
|
|
(NOTIFICATION_FAILED, NOTIFICATION_STATUS_TYPES_FAILED),
|
2017-09-20 15:21:05 +01:00
|
|
|
|
(NOTIFICATION_STATUS_LETTER_ACCEPTED, [NOTIFICATION_SENDING, NOTIFICATION_CREATED]),
|
|
|
|
|
|
(NOTIFICATION_CREATED, [NOTIFICATION_CREATED]),
|
|
|
|
|
|
(NOTIFICATION_TECHNICAL_FAILURE, [NOTIFICATION_TECHNICAL_FAILURE]),
|
2016-11-25 14:55:29 +00:00
|
|
|
|
# passing in lists containing single statuses
|
|
|
|
|
|
([NOTIFICATION_FAILED], NOTIFICATION_STATUS_TYPES_FAILED),
|
|
|
|
|
|
([NOTIFICATION_CREATED], [NOTIFICATION_CREATED]),
|
|
|
|
|
|
([NOTIFICATION_TECHNICAL_FAILURE], [NOTIFICATION_TECHNICAL_FAILURE]),
|
2017-10-23 15:57:00 +01:00
|
|
|
|
(NOTIFICATION_STATUS_LETTER_RECEIVED, NOTIFICATION_DELIVERED),
|
2016-11-25 14:55:29 +00:00
|
|
|
|
# passing in lists containing multiple statuses
|
|
|
|
|
|
([NOTIFICATION_FAILED, NOTIFICATION_CREATED], NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]),
|
|
|
|
|
|
([NOTIFICATION_CREATED, NOTIFICATION_PENDING], [NOTIFICATION_CREATED, NOTIFICATION_PENDING]),
|
|
|
|
|
|
([NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE], [NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE]),
|
2017-09-20 15:21:05 +01:00
|
|
|
|
(
|
|
|
|
|
|
[NOTIFICATION_FAILED, NOTIFICATION_STATUS_LETTER_ACCEPTED],
|
|
|
|
|
|
NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_SENDING, NOTIFICATION_CREATED]
|
|
|
|
|
|
),
|
2016-11-25 14:55:29 +00:00
|
|
|
|
# checking we don't end up with duplicates
|
|
|
|
|
|
(
|
|
|
|
|
|
[NOTIFICATION_FAILED, NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE],
|
|
|
|
|
|
NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]
|
|
|
|
|
|
),
|
|
|
|
|
|
])
|
2017-09-20 15:21:05 +01:00
|
|
|
|
def test_status_conversion(initial_statuses, expected_statuses):
|
2016-11-25 14:55:29 +00:00
|
|
|
|
converted_statuses = Notification.substitute_status(initial_statuses)
|
|
|
|
|
|
assert len(converted_statuses) == len(expected_statuses)
|
|
|
|
|
|
assert set(converted_statuses) == set(expected_statuses)
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2016-01-01 11:09:00.000000")
|
|
|
|
|
|
@pytest.mark.parametrize('template_type, recipient', [
|
2023-01-04 16:35:25 -05:00
|
|
|
|
('sms', '+12028675309'),
|
2017-04-20 11:52:00 +01:00
|
|
|
|
('email', 'foo@bar.com'),
|
|
|
|
|
|
])
|
2018-09-25 15:59:08 +01:00
|
|
|
|
def test_notification_for_csv_returns_correct_type(sample_service, template_type, recipient):
|
|
|
|
|
|
template = create_template(sample_service, template_type=template_type)
|
|
|
|
|
|
notification = create_notification(template, to_field=recipient)
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
serialized = notification.serialize_for_csv()
|
2017-04-21 11:07:45 +01:00
|
|
|
|
assert serialized['template_type'] == template_type
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2016-01-01 11:09:00.000000")
|
2018-09-25 15:59:08 +01:00
|
|
|
|
def test_notification_for_csv_returns_correct_job_row_number(sample_job):
|
|
|
|
|
|
notification = create_notification(sample_job.template, sample_job, job_row_number=0)
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
serialized = notification.serialize_for_csv()
|
2017-04-21 11:07:45 +01:00
|
|
|
|
assert serialized['row_number'] == 1
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2016-01-30 12:39:58.321312")
|
2017-04-21 11:07:45 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type, status, expected_status', [
|
|
|
|
|
|
('email', 'failed', 'Failed'),
|
|
|
|
|
|
('email', 'technical-failure', 'Technical failure'),
|
|
|
|
|
|
('email', 'temporary-failure', 'Inbox not accepting messages right now'),
|
|
|
|
|
|
('email', 'permanent-failure', 'Email address doesn’t exist'),
|
|
|
|
|
|
('sms', 'temporary-failure', 'Phone not accepting messages right now'),
|
|
|
|
|
|
('sms', 'permanent-failure', 'Phone number doesn’t exist'),
|
2017-04-28 11:00:55 +01:00
|
|
|
|
('sms', 'sent', 'Sent internationally'),
|
2017-09-11 11:57:33 +01:00
|
|
|
|
('letter', 'created', 'Accepted'),
|
|
|
|
|
|
('letter', 'sending', 'Accepted'),
|
2017-10-23 15:57:00 +01:00
|
|
|
|
('letter', 'technical-failure', 'Technical failure'),
|
2021-06-15 15:12:46 +01:00
|
|
|
|
('letter', 'permanent-failure', 'Permanent failure'),
|
2017-10-23 15:57:00 +01:00
|
|
|
|
('letter', 'delivered', 'Received')
|
2017-04-21 11:07:45 +01:00
|
|
|
|
])
|
|
|
|
|
|
def test_notification_for_csv_returns_formatted_status(
|
2018-09-25 15:59:08 +01:00
|
|
|
|
sample_service,
|
2017-04-21 11:07:45 +01:00
|
|
|
|
template_type,
|
|
|
|
|
|
status,
|
|
|
|
|
|
expected_status
|
|
|
|
|
|
):
|
2018-09-25 15:59:08 +01:00
|
|
|
|
template = create_template(sample_service, template_type=template_type)
|
|
|
|
|
|
notification = create_notification(template, status=status)
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
serialized = notification.serialize_for_csv()
|
2017-04-21 11:07:45 +01:00
|
|
|
|
assert serialized['status'] == expected_status
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2017-03-26 23:01:53.321312")
|
2018-09-25 15:59:08 +01:00
|
|
|
|
def test_notification_for_csv_returns_bst_correctly(sample_template):
|
|
|
|
|
|
notification = create_notification(sample_template)
|
2017-04-20 11:52:00 +01:00
|
|
|
|
|
|
|
|
|
|
serialized = notification.serialize_for_csv()
|
2022-11-10 16:54:48 -05:00
|
|
|
|
assert serialized['created_at'] == '2017-03-26 19:01:53'
|
2017-07-03 16:04:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-08-02 11:14:05 +01:00
|
|
|
|
def test_notification_personalisation_getter_returns_empty_dict_from_None():
|
|
|
|
|
|
noti = Notification()
|
|
|
|
|
|
noti._personalisation = None
|
|
|
|
|
|
assert noti.personalisation == {}
|
2017-07-03 16:04:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 08:53:41 -05:00
|
|
|
|
def test_notification_personalisation_getter_always_returns_empty_dict(notify_app):
|
2017-08-02 11:14:05 +01:00
|
|
|
|
noti = Notification()
|
2022-12-09 16:33:10 -05:00
|
|
|
|
noti._personalisation = encryption.encrypt({})
|
2017-08-02 11:14:05 +01:00
|
|
|
|
assert noti.personalisation == {}
|
2017-07-03 16:04:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 14:18:34 -05:00
|
|
|
|
def test_notification_personalisation_getter_returns_empty_dict_for_encryption_errors(notify_app):
|
|
|
|
|
|
noti = Notification()
|
|
|
|
|
|
# old _personalisation values were created with encryption.sign, which will trigger a decryption error
|
|
|
|
|
|
noti._personalisation = encryption.sign({"value": "PII"})
|
|
|
|
|
|
assert noti.personalisation == {}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-03 16:04:21 +01:00
|
|
|
|
@pytest.mark.parametrize('input_value', [
|
|
|
|
|
|
None,
|
|
|
|
|
|
{}
|
|
|
|
|
|
])
|
2022-12-13 08:53:41 -05:00
|
|
|
|
def test_notification_personalisation_setter_always_sets_empty_dict(notify_app, input_value):
|
2017-08-02 11:14:05 +01:00
|
|
|
|
noti = Notification()
|
|
|
|
|
|
noti.personalisation = input_value
|
2017-07-03 16:04:21 +01:00
|
|
|
|
|
2022-12-09 16:33:10 -05:00
|
|
|
|
assert noti.personalisation == {}
|
2017-08-02 11:14:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 13:48:23 +01:00
|
|
|
|
def test_notification_subject_is_none_for_sms(sample_service):
|
|
|
|
|
|
template = create_template(service=sample_service, template_type=SMS_TYPE)
|
|
|
|
|
|
notification = create_notification(template=template)
|
|
|
|
|
|
assert notification.subject is None
|
2017-08-02 11:14:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-06-25 16:16:50 +01:00
|
|
|
|
@pytest.mark.parametrize('template_type', ['email', 'letter'])
|
|
|
|
|
|
def test_notification_subject_fills_in_placeholders(sample_service, template_type):
|
|
|
|
|
|
template = create_template(service=sample_service, template_type=template_type, subject='((name))')
|
|
|
|
|
|
notification = create_notification(template=template, personalisation={'name': 'hello'})
|
|
|
|
|
|
assert notification.subject == 'hello'
|
2017-08-02 11:14:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_notification_serializes_with_address(client, sample_letter_notification):
|
|
|
|
|
|
sample_letter_notification.personalisation = {
|
|
|
|
|
|
'address_line_1': 'foo',
|
|
|
|
|
|
'address_line_3': 'bar',
|
|
|
|
|
|
'address_line_5': None,
|
|
|
|
|
|
'postcode': 'SW1 1AA'
|
|
|
|
|
|
}
|
|
|
|
|
|
res = sample_letter_notification.serialize()
|
|
|
|
|
|
assert res['line_1'] == 'foo'
|
|
|
|
|
|
assert res['line_2'] is None
|
|
|
|
|
|
assert res['line_3'] == 'bar'
|
|
|
|
|
|
assert res['line_4'] is None
|
|
|
|
|
|
assert res['line_5'] is None
|
|
|
|
|
|
assert res['line_6'] is None
|
|
|
|
|
|
assert res['postcode'] == 'SW1 1AA'
|
2017-08-09 11:56:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-07-16 13:12:17 +01:00
|
|
|
|
def test_notification_serializes_created_by_name_with_no_created_by_id(client, sample_notification):
|
|
|
|
|
|
res = sample_notification.serialize()
|
|
|
|
|
|
assert res['created_by_name'] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_notification_serializes_created_by_name_with_created_by_id(client, sample_notification, sample_user):
|
|
|
|
|
|
sample_notification.created_by_id = sample_user.id
|
|
|
|
|
|
res = sample_notification.serialize()
|
|
|
|
|
|
assert res['created_by_name'] == sample_user.name
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-09 11:56:52 +01:00
|
|
|
|
def test_sms_notification_serializes_without_subject(client, sample_template):
|
2020-07-06 16:41:53 +01:00
|
|
|
|
res = sample_template.serialize_for_v2()
|
2017-08-09 11:56:52 +01:00
|
|
|
|
assert res['subject'] is None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_email_notification_serializes_with_subject(client, sample_email_template):
|
2020-07-06 16:41:53 +01:00
|
|
|
|
res = sample_email_template.serialize_for_v2()
|
2017-08-09 11:56:52 +01:00
|
|
|
|
assert res['subject'] == 'Email Subject'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_notification_serializes_with_subject(client, sample_letter_template):
|
2020-07-06 16:41:53 +01:00
|
|
|
|
res = sample_letter_template.serialize_for_v2()
|
2017-08-09 12:24:35 +01:00
|
|
|
|
assert res['subject'] == 'Template subject'
|
2017-08-10 17:51:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-11-10 11:33:42 +00:00
|
|
|
|
def test_notification_references_template_history(client, sample_template):
|
|
|
|
|
|
noti = create_notification(sample_template)
|
|
|
|
|
|
sample_template.version = 3
|
|
|
|
|
|
sample_template.content = 'New template content'
|
|
|
|
|
|
|
|
|
|
|
|
res = noti.serialize()
|
|
|
|
|
|
assert res['template']['version'] == 1
|
|
|
|
|
|
|
|
|
|
|
|
assert res['body'] == noti.template.content
|
|
|
|
|
|
assert noti.template.content != sample_template.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_notification_requires_a_valid_template_version(client, sample_template):
|
|
|
|
|
|
sample_template.version = 2
|
|
|
|
|
|
with pytest.raises(IntegrityError):
|
|
|
|
|
|
create_notification(sample_template)
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-10 17:51:47 +01:00
|
|
|
|
def test_inbound_number_serializes_with_service(client, notify_db_session):
|
|
|
|
|
|
service = create_service()
|
|
|
|
|
|
inbound_number = create_inbound_number(number='1', service_id=service.id)
|
|
|
|
|
|
serialized_inbound_number = inbound_number.serialize()
|
|
|
|
|
|
assert serialized_inbound_number.get('id') == str(inbound_number.id)
|
|
|
|
|
|
assert serialized_inbound_number.get('service').get('id') == str(inbound_number.service.id)
|
|
|
|
|
|
assert serialized_inbound_number.get('service').get('name') == inbound_number.service.name
|
2017-08-14 19:47:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_inbound_number_returns_inbound_number(client, notify_db_session):
|
|
|
|
|
|
service = create_service()
|
|
|
|
|
|
inbound_number = create_inbound_number(number='1', service_id=service.id)
|
|
|
|
|
|
|
|
|
|
|
|
assert service.get_inbound_number() == inbound_number.number
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-24 13:37:17 +01:00
|
|
|
|
def test_inbound_number_returns_none_when_no_inbound_number(client, notify_db_session):
|
2017-11-07 14:26:18 +00:00
|
|
|
|
service = create_service()
|
2017-08-14 19:47:09 +01:00
|
|
|
|
|
2017-10-24 13:37:17 +01:00
|
|
|
|
assert not service.get_inbound_number()
|
2017-09-20 10:45:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_service_get_default_reply_to_email_address(sample_service):
|
|
|
|
|
|
create_reply_to_email(service=sample_service, email_address="default@email.com")
|
|
|
|
|
|
|
|
|
|
|
|
assert sample_service.get_default_reply_to_email_address() == 'default@email.com'
|
2017-09-21 16:08:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_service_get_default_contact_letter(sample_service):
|
|
|
|
|
|
create_letter_contact(service=sample_service, contact_block='London,\nNW1A 1AA')
|
|
|
|
|
|
|
|
|
|
|
|
assert sample_service.get_default_letter_contact() == 'London,\nNW1A 1AA'
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-21 16:41:10 +01:00
|
|
|
|
def test_service_get_default_sms_sender(notify_db_session):
|
2017-11-07 14:26:18 +00:00
|
|
|
|
service = create_service()
|
|
|
|
|
|
assert service.get_default_sms_sender() == 'testing'
|
2018-01-22 10:18:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_notification_serializes_correctly(client, sample_letter_notification):
|
|
|
|
|
|
sample_letter_notification.personalisation = {
|
|
|
|
|
|
'addressline1': 'test',
|
|
|
|
|
|
'addressline2': 'London',
|
|
|
|
|
|
'postcode': 'N1',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
json = sample_letter_notification.serialize()
|
|
|
|
|
|
assert json['line_1'] == 'test'
|
|
|
|
|
|
assert json['line_2'] == 'London'
|
|
|
|
|
|
assert json['postcode'] == 'N1'
|
2018-02-26 13:53:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_letter_notification_postcode_can_be_null_for_precompiled_letters(client, sample_letter_notification):
|
|
|
|
|
|
sample_letter_notification.personalisation = {
|
|
|
|
|
|
'address_line_1': 'test',
|
|
|
|
|
|
'address_line_2': 'London',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
json = sample_letter_notification.serialize()
|
|
|
|
|
|
assert json['line_1'] == 'test'
|
|
|
|
|
|
assert json['line_2'] == 'London'
|
|
|
|
|
|
assert json['postcode'] is None
|
2018-03-07 15:42:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_precompiled_letter_false(sample_letter_template):
|
|
|
|
|
|
assert not sample_letter_template.is_precompiled_letter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_precompiled_letter_true(sample_letter_template):
|
|
|
|
|
|
sample_letter_template.hidden = True
|
|
|
|
|
|
sample_letter_template.name = PRECOMPILED_TEMPLATE_NAME
|
|
|
|
|
|
assert sample_letter_template.is_precompiled_letter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_precompiled_letter_hidden_true_not_name(sample_letter_template):
|
|
|
|
|
|
sample_letter_template.hidden = True
|
|
|
|
|
|
assert not sample_letter_template.is_precompiled_letter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_precompiled_letter_name_correct_not_hidden(sample_letter_template):
|
|
|
|
|
|
sample_letter_template.name = PRECOMPILED_TEMPLATE_NAME
|
|
|
|
|
|
assert not sample_letter_template.is_precompiled_letter
|
2018-11-08 16:44:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_template_folder_is_parent(sample_service):
|
|
|
|
|
|
x = None
|
|
|
|
|
|
folders = []
|
|
|
|
|
|
for i in range(5):
|
|
|
|
|
|
x = create_template_folder(sample_service, name=str(i), parent=x)
|
|
|
|
|
|
folders.append(x)
|
|
|
|
|
|
|
|
|
|
|
|
assert folders[0].is_parent_of(folders[1])
|
|
|
|
|
|
assert folders[0].is_parent_of(folders[2])
|
|
|
|
|
|
assert folders[0].is_parent_of(folders[4])
|
|
|
|
|
|
assert folders[1].is_parent_of(folders[2])
|
|
|
|
|
|
assert not folders[1].is_parent_of(folders[0])
|
2021-06-25 17:29:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('is_platform_admin', (False, True))
|
2021-06-30 15:41:43 +01:00
|
|
|
|
def test_user_can_use_webauthn_if_platform_admin(sample_user, is_platform_admin):
|
2021-06-25 17:29:19 +01:00
|
|
|
|
sample_user.platform_admin = is_platform_admin
|
|
|
|
|
|
assert sample_user.can_use_webauthn == is_platform_admin
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-30 15:41:43 +01:00
|
|
|
|
@pytest.mark.parametrize(('auth_type', 'can_use_webauthn'), [
|
|
|
|
|
|
('email_auth', False),
|
|
|
|
|
|
('sms_auth', False),
|
|
|
|
|
|
('webauthn_auth', True)
|
|
|
|
|
|
])
|
|
|
|
|
|
def test_user_can_use_webauthn_if_they_login_with_it(sample_user, auth_type, can_use_webauthn):
|
|
|
|
|
|
sample_user.auth_type = auth_type
|
|
|
|
|
|
assert sample_user.can_use_webauthn == can_use_webauthn
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-25 17:29:19 +01:00
|
|
|
|
def test_user_can_use_webauthn_if_in_notify_team(notify_service):
|
|
|
|
|
|
assert notify_service.users[0].can_use_webauthn
|