From 49917ccafda31b5cf29c719b80a30089bb4bccc0 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 29 Jun 2017 18:16:03 +0100 Subject: [PATCH] Add redact_personalisation to TemplateSchema --- app/schemas.py | 9 ++++----- tests/app/dao/test_templates_dao.py | 17 ++++++++++++++--- tests/app/template/test_rest.py | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index 48151dba2..b645ec39d 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -297,15 +297,14 @@ class BaseTemplateSchema(BaseSchema): strict = True -class TemplateRedactedSchema(BaseSchema): - class Meta: - model = models.TemplateRedacted - - class TemplateSchema(BaseTemplateSchema): created_by = field_for(models.Template, 'created_by', required=True) process_type = field_for(models.Template, 'process_type') + redact_personalisation = fields.Method("redact") + + def redact(self, template): + return template.redact_personalisation @validates_schema def validate_type(self, data): diff --git a/tests/app/dao/test_templates_dao.py b/tests/app/dao/test_templates_dao.py index 58ad14e15..43cc88fd7 100644 --- a/tests/app/dao/test_templates_dao.py +++ b/tests/app/dao/test_templates_dao.py @@ -195,10 +195,13 @@ def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_ser notify_db_session, template_name='Test Template', service=sample_service) - assert dao_get_template_by_id_and_service_id( + template = dao_get_template_by_id_and_service_id( template_id=sample_template.id, - service_id=sample_service.id).name == 'Test Template' - assert Template.query.count() == 1 + service_id=sample_service.id) + assert template.id == sample_template.id + assert template.name == 'Test Template' + assert template.version == sample_template.version + assert not template.redact_personalisation def test_get_template_by_id_and_service_returns_none_if_no_template(sample_service, fake_uuid): @@ -280,6 +283,14 @@ def test_get_template_history_version(sample_user, sample_service, sample_templa assert old_template.content == old_content +def test_can_get_template_then_redacted_returns_right_values(sample_template): + template = dao_get_template_by_id_and_service_id(template_id=sample_template.id, + service_id=sample_template.service_id) + assert not template.redact_personalisation + dao_redact_template(template=template, user_id=sample_template.created_by_id) + assert template.redact_personalisation + + def test_get_template_versions(sample_template): original_content = sample_template.content sample_template.content = 'new version' diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index dfb773453..80c30d71b 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -349,6 +349,7 @@ def test_should_get_a_single_template( assert data['content'] == content assert data['subject'] == subject assert data['process_type'] == 'normal' + assert not data['redact_personalisation'] @pytest.mark.parametrize(