mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 15:18:25 -04:00
Rename JSONModel to SerialisedModel 2/2
This class doesn’t actually wrap JSON, it wraps serialised data. So this name feels better.
This commit is contained in:
@@ -21,7 +21,7 @@ from app.notifications.process_notifications import create_content_for_notificat
|
|||||||
from app.utils import get_public_notify_type_text
|
from app.utils import get_public_notify_type_text
|
||||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||||
from app.dao.service_letter_contact_dao import dao_get_letter_contact_by_id
|
from app.dao.service_letter_contact_dao import dao_get_letter_contact_by_id
|
||||||
from app.serialised_models import TemplateJSONModel
|
from app.serialised_models import SerialisedTemplate
|
||||||
|
|
||||||
from gds_metrics.metrics import Histogram
|
from gds_metrics.metrics import Histogram
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ def check_notification_content_is_not_empty(template_with_content):
|
|||||||
def validate_template(template_id, personalisation, service, notification_type):
|
def validate_template(template_id, personalisation, service, notification_type):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
template = TemplateJSONModel.from_id_and_service_id(template_id, service.id)
|
template = SerialisedTemplate.from_id_and_service_id(template_id, service.id)
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
message = 'Template not found'
|
message = 'Template not found'
|
||||||
raise BadRequestError(message=message,
|
raise BadRequestError(message=message,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
|
|||||||
from app.dao import templates_dao
|
from app.dao import templates_dao
|
||||||
|
|
||||||
|
|
||||||
class JSONModel(ABC):
|
class SerialisedModel(ABC):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -18,7 +18,7 @@ class JSONModel(ABC):
|
|||||||
return super().__dir__() + list(sorted(self.ALLOWED_PROPERTIES))
|
return super().__dir__() + list(sorted(self.ALLOWED_PROPERTIES))
|
||||||
|
|
||||||
|
|
||||||
class TemplateJSONModel(JSONModel):
|
class SerialisedTemplate(SerialisedModel):
|
||||||
ALLOWED_PROPERTIES = {
|
ALLOWED_PROPERTIES = {
|
||||||
'archived',
|
'archived',
|
||||||
'content',
|
'content',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from app.models import LETTER_TYPE
|
|||||||
from app.models import Notification
|
from app.models import Notification
|
||||||
from app.models import NOTIFICATION_CREATED
|
from app.models import NOTIFICATION_CREATED
|
||||||
from app.notifications.process_letter_notifications import create_letter_notification
|
from app.notifications.process_letter_notifications import create_letter_notification
|
||||||
from app.json_models import TemplateJSONModel
|
from app.serialised_models import SerialisedTemplate
|
||||||
|
|
||||||
|
|
||||||
def test_create_letter_notification_creates_notification(sample_letter_template, sample_api_key):
|
def test_create_letter_notification_creates_notification(sample_letter_template, sample_api_key):
|
||||||
@@ -14,7 +14,7 @@ def test_create_letter_notification_creates_notification(sample_letter_template,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_letter_template.id, sample_letter_template.service_id
|
sample_letter_template.id, sample_letter_template.service_id
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ def test_create_letter_notification_sets_reference(sample_letter_template, sampl
|
|||||||
'reference': 'foo'
|
'reference': 'foo'
|
||||||
}
|
}
|
||||||
|
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_letter_template.id, sample_letter_template.service_id
|
sample_letter_template.id, sample_letter_template.service_id
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ def test_create_letter_notification_sets_billable_units(sample_letter_template,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_letter_template.id, sample_letter_template.service_id
|
sample_letter_template.id, sample_letter_template.service_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ from app.notifications.process_notifications import (
|
|||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
simulated_recipient
|
simulated_recipient
|
||||||
)
|
)
|
||||||
from app.serialised_models import TemplateJSONModel
|
from app.serialised_models import SerialisedTemplate
|
||||||
from notifications_utils.recipients import validate_and_format_phone_number, validate_and_format_email_address
|
from notifications_utils.recipients import validate_and_format_phone_number, validate_and_format_email_address
|
||||||
from app.v2.errors import BadRequestError
|
from app.v2.errors import BadRequestError
|
||||||
from tests.app.db import create_service, create_template, create_api_key
|
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 = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_email_template.id, sample_email_template.service_id
|
sample_email_template.id, sample_email_template.service_id
|
||||||
)
|
)
|
||||||
content = create_content_for_notification(template, None)
|
content = create_content_for_notification(template, None)
|
||||||
@@ -35,7 +35,7 @@ def test_create_content_for_notification_passes(sample_email_template):
|
|||||||
|
|
||||||
|
|
||||||
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):
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
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'})
|
||||||
@@ -44,7 +44,7 @@ def test_create_content_for_notification_with_placeholders_passes(sample_templat
|
|||||||
|
|
||||||
|
|
||||||
def test_create_content_for_notification_fails_with_missing_personalisation(sample_template_with_placeholders):
|
def test_create_content_for_notification_fails_with_missing_personalisation(sample_template_with_placeholders):
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
||||||
)
|
)
|
||||||
with pytest.raises(BadRequestError):
|
with pytest.raises(BadRequestError):
|
||||||
@@ -52,7 +52,7 @@ def test_create_content_for_notification_fails_with_missing_personalisation(samp
|
|||||||
|
|
||||||
|
|
||||||
def test_create_content_for_notification_allows_additional_personalisation(sample_template_with_placeholders):
|
def test_create_content_for_notification_allows_additional_personalisation(sample_template_with_placeholders):
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
sample_template_with_placeholders.id, sample_template_with_placeholders.service_id
|
||||||
)
|
)
|
||||||
create_content_for_notification(template, {'name': 'Bobby', 'Additional placeholder': 'Data'})
|
create_content_for_notification(template, {'name': 'Bobby', 'Additional placeholder': 'Data'})
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from app.notifications.validators import (
|
|||||||
validate_and_format_recipient,
|
validate_and_format_recipient,
|
||||||
validate_template,
|
validate_template,
|
||||||
)
|
)
|
||||||
from app.serialised_models import TemplateJSONModel
|
from app.serialised_models import SerialisedTemplate
|
||||||
from app.utils import get_template_instance
|
from app.utils import get_template_instance
|
||||||
|
|
||||||
from app.v2.errors import (
|
from app.v2.errors import (
|
||||||
@@ -315,7 +315,7 @@ def test_check_content_char_count_passes_for_long_email_or_letter(sample_service
|
|||||||
|
|
||||||
def test_check_notification_content_is_not_empty_passes(notify_api, mocker, sample_service):
|
def test_check_notification_content_is_not_empty_passes(notify_api, mocker, sample_service):
|
||||||
template_id = create_template(sample_service, content="Content is not empty").id
|
template_id = create_template(sample_service, content="Content is not empty").id
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
service_id=sample_service.id
|
service_id=sample_service.id
|
||||||
)
|
)
|
||||||
@@ -331,7 +331,7 @@ def test_check_notification_content_is_not_empty_fails(
|
|||||||
notify_api, mocker, sample_service, template_content, notification_values
|
notify_api, mocker, sample_service, template_content, notification_values
|
||||||
):
|
):
|
||||||
template_id = create_template(sample_service, content=template_content).id
|
template_id = create_template(sample_service, content=template_content).id
|
||||||
template = TemplateJSONModel.from_id_and_service_id(
|
template = SerialisedTemplate.from_id_and_service_id(
|
||||||
template_id=template_id,
|
template_id=template_id,
|
||||||
service_id=sample_service.id
|
service_id=sample_service.id
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user