From 0282a76bf7446e49d3063608b0e6daff2d51a371 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 6 Jul 2020 16:41:53 +0100 Subject: [PATCH] rename template.serialize to serialize_for_v2 make it clear that this is for the public api, and we shouldn't add fields to it without considering impacts also add the broadcast_messages relationship on service and template to the exclude from the marshmallow schemas, so it's not included elsewhere --- app/models.py | 3 +-- app/schemas.py | 4 +++- app/v2/template/get_template.py | 2 +- app/v2/templates/get_templates.py | 2 +- tests/app/test_model.py | 6 +++--- tests/app/v2/template/test_get_template.py | 1 - tests/app/v2/template/test_post_template.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index fffeccecb..eae9c921a 100644 --- a/app/models.py +++ b/app/models.py @@ -991,7 +991,7 @@ class TemplateBase(db.Model): template.values = values return template - def serialize(self): + def serialize_for_v2(self): serialized = { "id": str(self.id), "type": self.template_type, @@ -1009,7 +1009,6 @@ class TemplateBase(db.Model): for key in self._as_utils_template().placeholders }, "postage": self.postage, - "broadcast_data": self.broadcast_data } return serialized diff --git a/app/schemas.py b/app/schemas.py index 079701c8e..7788e3c79 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -260,6 +260,7 @@ class ServiceSchema(BaseSchema, UUIDsAsStringsMixin): 'users', 'version', 'whitelist', + 'broadcast_messages', ) strict = True @@ -326,6 +327,7 @@ class DetailedServiceSchema(BaseSchema): 'users', 'version', 'whitelist', + 'broadcast_messages', ) @@ -350,7 +352,7 @@ class BaseTemplateSchema(BaseSchema): class Meta: model = models.Template - exclude = ("service_id", "jobs", "service_letter_contact_id") + exclude = ("service_id", "jobs", "service_letter_contact_id", "broadcast_messages") strict = True diff --git a/app/v2/template/get_template.py b/app/v2/template/get_template.py index 8440b231d..9ac1fbd11 100644 --- a/app/v2/template/get_template.py +++ b/app/v2/template/get_template.py @@ -18,4 +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 + return jsonify(template.serialize_for_v2()), 200 diff --git a/app/v2/templates/get_templates.py b/app/v2/templates/get_templates.py index cd34e46aa..51a5e1217 100644 --- a/app/v2/templates/get_templates.py +++ b/app/v2/templates/get_templates.py @@ -14,5 +14,5 @@ def get_templates(): templates = templates_dao.dao_get_all_templates_for_service(authenticated_service.id, data.get('type')) return jsonify( - templates=[template.serialize() for template in templates] + templates=[template.serialize_for_v2() for template in templates] ), 200 diff --git a/tests/app/test_model.py b/tests/app/test_model.py index 70d7f78ce..c6df9d884 100644 --- a/tests/app/test_model.py +++ b/tests/app/test_model.py @@ -214,17 +214,17 @@ def test_notification_serializes_created_by_name_with_created_by_id(client, samp def test_sms_notification_serializes_without_subject(client, sample_template): - res = sample_template.serialize() + res = sample_template.serialize_for_v2() assert res['subject'] is None def test_email_notification_serializes_with_subject(client, sample_email_template): - res = sample_email_template.serialize() + res = sample_email_template.serialize_for_v2() assert res['subject'] == 'Email Subject' def test_letter_notification_serializes_with_subject(client, sample_letter_template): - res = sample_letter_template.serialize() + res = sample_letter_template.serialize_for_v2() assert res['subject'] == 'Template subject' diff --git a/tests/app/v2/template/test_get_template.py b/tests/app/v2/template/test_get_template.py index 28ccc9082..2616b4489 100644 --- a/tests/app/v2/template/test_get_template.py +++ b/tests/app/v2/template/test_get_template.py @@ -44,7 +44,6 @@ def test_get_template_by_id_returns_200( 'name': expected_name, 'personalisation': {}, 'postage': postage, - 'broadcast_data': None, } assert json_response == expected_response diff --git a/tests/app/v2/template/test_post_template.py b/tests/app/v2/template/test_post_template.py index 9872f96fb..e74ff7dc4 100644 --- a/tests/app/v2/template/test_post_template.py +++ b/tests/app/v2/template/test_post_template.py @@ -2,7 +2,7 @@ import pytest from flask import json -from app.models import EMAIL_TYPE, LETTER_TYPE, SMS_TYPE, TEMPLATE_TYPES +from app.models import EMAIL_TYPE, LETTER_TYPE, TEMPLATE_TYPES from tests import create_authorization_header from tests.app.db import create_template