ensure template history serializes using template serialize fn

This commit is contained in:
Leo Hemsted
2017-08-09 12:24:35 +01:00
parent c9762f75a1
commit da02ffa32f
4 changed files with 10 additions and 18 deletions

View File

@@ -506,18 +506,7 @@ class TemplateHistory(db.Model):
default=NORMAL)
def serialize(self):
serialized = {
"id": self.id,
"type": self.template_type,
"created_at": self.created_at.strftime(DATETIME_FORMAT),
"updated_at": self.updated_at.strftime(DATETIME_FORMAT) if self.updated_at else None,
"created_by": self.created_by.email_address,
"version": self.version,
"body": self.content,
"subject": self.subject if self.template_type == EMAIL_TYPE else None
}
return serialized
return Template.serialize(self)
MMG_PROVIDER = "mmg"

View File

@@ -18,5 +18,4 @@ def get_template_by_id(template_id, version=None):
template = templates_dao.dao_get_template_by_id_and_service_id(
template_id, authenticated_service.id, data.get('version'))
return jsonify(template.serialize()), 200

View File

@@ -217,4 +217,4 @@ def test_email_notification_serializes_with_subject(client, sample_email_templat
def test_letter_notification_serializes_with_subject(client, sample_letter_template):
res = sample_letter_template.serialize()
assert res['subject'] == 'Template Subject'
assert res['subject'] == 'Template subject'

View File

@@ -3,16 +3,20 @@ import pytest
from flask import json
from app import DATETIME_FORMAT
from app.models import EMAIL_TYPE, TEMPLATE_TYPES
from app.models import TEMPLATE_TYPES, EMAIL_TYPE, SMS_TYPE, LETTER_TYPE
from tests import create_authorization_header
from tests.app.db import create_template
valid_version_params = [None, 1]
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
@pytest.mark.parametrize("tmp_type, expected_subject", [
(SMS_TYPE, None),
(EMAIL_TYPE, 'Template subject'),
(LETTER_TYPE, 'Template subject')
])
@pytest.mark.parametrize("version", valid_version_params)
def test_get_template_by_id_returns_200(client, sample_service, tmp_type, version):
def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expected_subject, version):
template = create_template(sample_service, template_type=tmp_type)
auth_header = create_authorization_header(service_id=sample_service.id)
@@ -34,7 +38,7 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, versio
'version': template.version,
'created_by': template.created_by.email_address,
'body': template.content,
"subject": template.subject if tmp_type == EMAIL_TYPE else None
"subject": expected_subject
}
assert json_response == expected_response