mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05:00
`Notification.template` changed from being a Template relationship to TemplateHistory. When a relationship attribute is being assigned, SQLAlchemy checks that the assigned value type matches the relationship type. Since most tests at the moment create a notification using a Template instance this check fails. Rewriting the tests to use TemplateHistory objects would require changes to the majority of tests. Instead, when creating a notification objects we assign the foreign key attributes directly. This skips the SQLAlchemy type check, but we still get the constraint check on the foreign keys, so a matching TemplateHistory object needs to exist in the database.
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from app.models import LETTER_TYPE
|
|
from app.models import Notification
|
|
from app.models import NOTIFICATION_CREATED
|
|
from app.notifications.process_letter_notifications import create_letter_notification
|
|
|
|
|
|
def test_create_letter_notification_creates_notification(sample_letter_template, sample_api_key):
|
|
data = {
|
|
'personalisation': {
|
|
'address_line_1': 'The Queen',
|
|
'address_line_2': 'Buckingham Palace',
|
|
'postcode': 'SW1 1AA',
|
|
}
|
|
}
|
|
|
|
notification = create_letter_notification(data, sample_letter_template, sample_api_key, NOTIFICATION_CREATED)
|
|
|
|
assert notification == Notification.query.one()
|
|
assert notification.job is None
|
|
assert notification.status == NOTIFICATION_CREATED
|
|
assert notification.template_id == sample_letter_template.id
|
|
assert notification.template_version == sample_letter_template.version
|
|
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
|
|
|
|
|
|
def test_create_letter_notification_sets_reference(sample_letter_template, sample_api_key):
|
|
data = {
|
|
'personalisation': {
|
|
'address_line_1': 'The Queen',
|
|
'address_line_2': 'Buckingham Palace',
|
|
'postcode': 'SW1 1AA',
|
|
},
|
|
'reference': 'foo'
|
|
}
|
|
|
|
notification = create_letter_notification(data, sample_letter_template, sample_api_key, NOTIFICATION_CREATED)
|
|
|
|
assert notification.client_reference == 'foo'
|