mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-25 00:33:41 -04:00
Don’t store the underlying dict
This will give us smaller objects to cache, and forces us to be explicit about which properties we’re using.
This commit is contained in:
@@ -9,7 +9,6 @@ class JSONModel(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def __init__(self, _dict):
|
def __init__(self, _dict):
|
||||||
self._dict = _dict
|
|
||||||
for property in self.ALLOWED_PROPERTIES:
|
for property in self.ALLOWED_PROPERTIES:
|
||||||
setattr(self, property, _dict[property])
|
setattr(self, property, _dict[property])
|
||||||
|
|
||||||
@@ -20,10 +19,12 @@ class JSONModel(ABC):
|
|||||||
class TemplateJSONModel(JSONModel):
|
class TemplateJSONModel(JSONModel):
|
||||||
ALLOWED_PROPERTIES = {
|
ALLOWED_PROPERTIES = {
|
||||||
'archived',
|
'archived',
|
||||||
|
'content',
|
||||||
'id',
|
'id',
|
||||||
'postage',
|
'postage',
|
||||||
'process_type',
|
'process_type',
|
||||||
'reply_to_text',
|
'reply_to_text',
|
||||||
|
'subject',
|
||||||
'template_type',
|
'template_type',
|
||||||
'version',
|
'version',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,12 +50,29 @@ REDIS_GET_AND_INCR_DAILY_LIMIT_DURATION_SECONDS = Histogram(
|
|||||||
|
|
||||||
def create_content_for_notification(template, personalisation):
|
def create_content_for_notification(template, personalisation):
|
||||||
if template.template_type == EMAIL_TYPE:
|
if template.template_type == EMAIL_TYPE:
|
||||||
template_object = PlainTextEmailTemplate(template._dict, personalisation)
|
template_object = PlainTextEmailTemplate(
|
||||||
|
{
|
||||||
|
'content': template.content,
|
||||||
|
'subject': template.subject,
|
||||||
|
'template_type': template.template_type,
|
||||||
|
},
|
||||||
|
personalisation,
|
||||||
|
)
|
||||||
if template.template_type == SMS_TYPE:
|
if template.template_type == SMS_TYPE:
|
||||||
template_object = SMSMessageTemplate(template._dict, personalisation)
|
template_object = SMSMessageTemplate(
|
||||||
|
{
|
||||||
|
'content': template.content,
|
||||||
|
'template_type': template.template_type,
|
||||||
|
},
|
||||||
|
personalisation,
|
||||||
|
)
|
||||||
if template.template_type == LETTER_TYPE:
|
if template.template_type == LETTER_TYPE:
|
||||||
template_object = LetterPrintTemplate(
|
template_object = LetterPrintTemplate(
|
||||||
template._dict,
|
{
|
||||||
|
'content': template.content,
|
||||||
|
'subject': template.subject,
|
||||||
|
'template_type': template.template_type,
|
||||||
|
},
|
||||||
personalisation,
|
personalisation,
|
||||||
contact_block=template.reply_to_text,
|
contact_block=template.reply_to_text,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from tests.app.db import create_service, create_template, create_api_key
|
|||||||
def test_create_content_for_notification_passes(sample_email_template):
|
def test_create_content_for_notification_passes(sample_email_template):
|
||||||
template = get_template_model(sample_email_template.id, sample_email_template.service_id)
|
template = get_template_model(sample_email_template.id, sample_email_template.service_id)
|
||||||
content = create_content_for_notification(template, None)
|
content = create_content_for_notification(template, None)
|
||||||
assert str(content) == template._dict['content'] + '\n'
|
assert str(content) == template.content + '\n'
|
||||||
|
|
||||||
|
|
||||||
def test_create_content_for_notification_with_placeholders_passes(sample_template_with_placeholders):
|
def test_create_content_for_notification_with_placeholders_passes(sample_template_with_placeholders):
|
||||||
@@ -37,7 +37,7 @@ def test_create_content_for_notification_with_placeholders_passes(sample_templat
|
|||||||
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
||||||
)
|
)
|
||||||
content = create_content_for_notification(template, {'name': 'Bobby'})
|
content = create_content_for_notification(template, {'name': 'Bobby'})
|
||||||
assert content.content == template._dict['content']
|
assert content.content == template.content
|
||||||
assert 'Bobby' in str(content)
|
assert 'Bobby' in str(content)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user