Use personalisation to set client_reference for letters

which were sent through Notify interface only. This is done
to avoid performance dip from additional operation for
other notification types.
This commit is contained in:
Pea Tyczynska
2021-03-19 16:42:55 +00:00
parent a2da8bc070
commit 52c529ab3a
9 changed files with 79 additions and 49 deletions

View File

@@ -1249,3 +1249,27 @@ def test_send_notification_should_send_international_letters(
notification = Notification.query.get(notification_id['id'])
assert notification.postage == expected_postage
assert notification.international == expected_international
@pytest.mark.parametrize('reference_paceholder,', [None, 'ref2'])
def test_send_notification_should_set_client_reference_from_placeholder(
sample_letter_template, mocker, reference_paceholder
):
deliver_mock = mocker.patch('app.celery.tasks.letters_pdf_tasks.get_pdf_for_templated_letter.apply_async')
data = {
'template_id': sample_letter_template.id,
'personalisation': {
'address_line_1': 'Jane',
'address_line_2': 'Moss Lane',
'address_line_3': 'SW1A 1AA',
},
'to': 'Jane',
'created_by': sample_letter_template.service.created_by_id
}
if reference_paceholder:
data['personalisation']['reference'] = reference_paceholder
notification_id = send_one_off_notification(sample_letter_template.service_id, data)
assert deliver_mock.called
notification = Notification.query.get(notification_id['id'])
assert notification.client_reference == reference_paceholder

View File

@@ -96,42 +96,6 @@ def test_persist_notification_creates_and_save_to_db(sample_template, sample_api
assert notification_from_db.reply_to_text == sample_template.service.get_default_sms_sender()
@pytest.mark.parametrize('client_reference,personalisation,expected_client_reference', [
('clientref1', {}, 'clientref1'),
('clientref1', {'reference': 'ref2'}, 'clientref1'),
(None, {'reference': 'ref2'}, 'ref2'),
(None, {'foo': 'bar'}, None),
])
def test_persist_notification_sets_client_reference_correctly(
sample_letter_template, sample_api_key, client_reference, personalisation, expected_client_reference
):
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 0
notification = persist_notification(
template_id=sample_letter_template.id,
template_version=sample_letter_template.version,
recipient='3 Somerset House',
service=sample_letter_template.service,
personalisation=personalisation,
notification_type='letter',
api_key_id=sample_api_key.id,
key_type=sample_api_key.key_type,
reference="ref",
client_reference=client_reference,
)
assert Notification.query.get(notification.id) is not None
notification_from_db = Notification.query.one()
assert notification_from_db.id == notification.id
assert notification_from_db.template_id == notification.template_id
assert notification_from_db.notification_type == notification.notification_type
assert notification_from_db.reference == notification.reference
assert notification_from_db.client_reference == expected_client_reference
def test_persist_notification_throws_exception_when_missing_template(sample_api_key):
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 0