Add tests for notification.template returning the right version

Adds test for:
* checking the template version foreign key constraint
* checking that template changes don't affect existing notifications
* notification statistics aren't affected by different template versions
* notification stats always return the current template name
This commit is contained in:
Alexey Bezhan
2017-11-10 11:33:42 +00:00
parent db1c647873
commit 0825177f2d
3 changed files with 57 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import pytest
from freezegun import freeze_time
from sqlalchemy.exc import IntegrityError
from app import encryption
from app.models import (
@@ -239,6 +240,24 @@ def test_letter_notification_serializes_with_subject(client, sample_letter_templ
assert res['subject'] == 'Template subject'
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)
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)