2017-07-27 11:10:22 +01:00
|
|
|
from app.models import LETTER_TYPE
|
|
|
|
|
from app.models import Notification
|
2017-09-26 11:28:54 +01:00
|
|
|
from app.models import NOTIFICATION_CREATED
|
2017-07-27 11:10:22 +01:00
|
|
|
from app.notifications.process_letter_notifications import create_letter_notification
|
|
|
|
|
|
|
|
|
|
|
2017-09-26 11:28:54 +01:00
|
|
|
def test_create_letter_notification_creates_notification(sample_letter_template, sample_api_key):
|
2017-07-27 11:10:22 +01:00
|
|
|
data = {
|
|
|
|
|
'personalisation': {
|
|
|
|
|
'address_line_1': 'The Queen',
|
|
|
|
|
'address_line_2': 'Buckingham Palace',
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 11:28:54 +01:00
|
|
|
notification = create_letter_notification(data, sample_letter_template, sample_api_key, NOTIFICATION_CREATED)
|
2017-07-27 11:10:22 +01:00
|
|
|
|
|
|
|
|
assert notification == Notification.query.one()
|
2017-09-26 11:28:54 +01:00
|
|
|
assert notification.job is None
|
|
|
|
|
assert notification.status == NOTIFICATION_CREATED
|
|
|
|
|
assert notification.template == sample_letter_template
|
2017-07-27 11:10:22 +01:00
|
|
|
assert notification.api_key == sample_api_key
|
|
|
|
|
assert notification.notification_type == LETTER_TYPE
|
|
|
|
|
assert notification.key_type == sample_api_key.key_type
|
|
|
|
|
assert notification.reference is not None
|
|
|
|
|
assert notification.client_reference is None
|
|
|
|
|
|
|
|
|
|
|
2017-09-26 11:28:54 +01:00
|
|
|
def test_create_letter_notification_sets_reference(sample_letter_template, sample_api_key):
|
2017-07-27 11:10:22 +01:00
|
|
|
data = {
|
|
|
|
|
'personalisation': {
|
|
|
|
|
'address_line_1': 'The Queen',
|
|
|
|
|
'address_line_2': 'Buckingham Palace',
|
|
|
|
|
'postcode': 'SW1 1AA',
|
|
|
|
|
},
|
|
|
|
|
'reference': 'foo'
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 11:28:54 +01:00
|
|
|
notification = create_letter_notification(data, sample_letter_template, sample_api_key, NOTIFICATION_CREATED)
|
2017-07-27 11:10:22 +01:00
|
|
|
|
|
|
|
|
assert notification.client_reference == 'foo'
|