separated schemas once more into "with template" and "with personalisation"

"with personalisation" should only be used by the public notification api
"with template" should be used when we want template name, etc details.

also added an xfail test for correctly constructing notification
personalisation
This commit is contained in:
Leo Hemsted
2016-07-26 14:33:14 +01:00
parent b28e7efd14
commit c81b30dba1
4 changed files with 49 additions and 13 deletions

View File

@@ -22,7 +22,7 @@ from app.schemas import (
job_schema,
unarchived_template_schema,
notifications_filter_schema,
notification_schema
notification_with_template_schema
)
from app.celery.tasks import process_job
@@ -62,7 +62,7 @@ def get_all_notifications_for_service_job(service_id, job_id):
kwargs['service_id'] = service_id
kwargs['job_id'] = job_id
return jsonify(
notifications=notification_schema.dump(pagination.items, many=True).data,
notifications=notification_with_template_schema.dump(pagination.items, many=True).data,
page_size=page_size,
total=pagination.total,
links=pagination_links(

View File

@@ -18,7 +18,7 @@ from app.dao import (
services_dao,
notifications_dao
)
from app.models import NOTIFICATION_TYPE, SMS_TYPE
from app.models import SMS_TYPE
from app.notifications.process_client_response import (
validate_callback_data,
process_sms_client_response
@@ -26,7 +26,7 @@ from app.notifications.process_client_response import (
from app.schemas import (
email_notification_schema,
sms_template_notification_schema,
notification_with_template_schema,
notification_with_personalisation_schema,
notifications_filter_schema,
notifications_statistics_schema,
day_schema,
@@ -175,7 +175,7 @@ def get_notifications(notification_id):
notification = notifications_dao.get_notification(str(api_user.service_id),
notification_id,
key_type=api_user.key_type)
return jsonify(data={"notification": notification_with_template_schema.dump(notification).data}), 200
return jsonify(data={"notification": notification_with_personalisation_schema.dump(notification).data}), 200
@notifications.route('/notifications', methods=['GET'])
@@ -193,7 +193,7 @@ def get_all_notifications():
limit_days=limit_days,
key_type=api_user.key_type)
return jsonify(
notifications=notification_with_template_schema.dump(pagination.items, many=True).data,
notifications=notification_with_personalisation_schema.dump(pagination.items, many=True).data,
page_size=page_size,
total=pagination.total,
links=pagination_links(

View File

@@ -281,16 +281,17 @@ class SmsAdminNotificationSchema(SmsNotificationSchema):
class NotificationWithTemplateSchema(BaseSchema):
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type", "content", "subject"], dump_only=True)
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
personalisation = fields.Dict(required=False)
class Meta:
model = models.Notification
strict = True
exclude = ('_personalisation',)
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type", "content", "subject"], dump_only=True)
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
personalisation = fields.Dict(required=False)
class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
@pre_dump
def handle_personalisation_property(self, in_data):
self.personalisation = in_data.personalisation
@@ -518,7 +519,8 @@ email_notification_schema = EmailNotificationSchema()
job_email_template_notification_schema = JobEmailTemplateNotificationSchema()
notification_schema = NotificationModelSchema()
notification_with_template_schema = NotificationWithTemplateSchema()
notification_with_template_schema_load_json = NotificationWithTemplateSchema(load_json=True)
notification_with_personalisation_schema = NotificationWithPersonalisationSchema()
notification_with_personalisation_schema_load_json = NotificationWithPersonalisationSchema(load_json=True)
invited_user_schema = InvitedUserSchema()
permission_schema = PermissionSchema()
email_data_request_schema = EmailDataSchema()