From c6d66eb705d7860e58fc13b05827d668b55c7254 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 12 Dec 2023 19:07:21 +0000 Subject: [PATCH] make TemplateSchemaNoDetail tidier now that it doesn't have content the schema was originally created so that it could not show content. However, then it needed content conditionally for broadcast messages so content was added back in. Now that broadcasts no longer exist we can revert that - however, for a template that has a specific list of expected keys, it's nicer to just list those rather than maintain a huge list of exceptions that needs to be modified every time a field changes on the template model --- app/schemas.py | 30 ++++++++------------------- tests/app/template/test_rest.py | 36 ++++++--------------------------- 2 files changed, 14 insertions(+), 52 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index 791a4eaeb4..c58093a90a 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -430,28 +430,14 @@ def validate_type(self, data, **kwargs): class TemplateSchemaNoDetail(TemplateSchema): class Meta(TemplateSchema.Meta): - exclude = TemplateSchema.Meta.exclude + ( - "archived", - "created_at", - "created_by", - "created_by_id", - "hidden", - "letter_attachment", - "postage", - "process_type", - "redact_personalisation", - "reply_to", - "reply_to_text", - "service", - "service_letter_contact", - "subject", - "template_redacted", - "updated_at", - "version", - "letter_welsh_subject", - "letter_welsh_content", - "letter_languages", - ) + fields = [ + "folder", + "id", + "is_precompiled_letter", + "name", + "template_type", + ] + exclude = [] class TemplateHistorySchema(BaseSchema): diff --git a/tests/app/template/test_rest.py b/tests/app/template/test_rest.py index e0081541e2..dee79d6ee6 100644 --- a/tests/app/template/test_rest.py +++ b/tests/app/template/test_rest.py @@ -612,45 +612,21 @@ def test_should_get_return_all_fields_by_default( } -@pytest.mark.parametrize( - "extra_args", - ( - {"detailed": False}, - {"detailed": "False"}, - ), -) -@pytest.mark.parametrize( - "template_type, expected_content", - ( - (EMAIL_TYPE, None), - (SMS_TYPE, None), - (LETTER_TYPE, None), - ), -) -def test_should_not_return_content_and_subject_if_requested( - admin_request, - sample_service, - extra_args, - template_type, - expected_content, -): - create_template( - sample_service, - template_type=template_type, - content="This is a test", - ) +@pytest.mark.parametrize("template_type", (EMAIL_TYPE, SMS_TYPE, LETTER_TYPE)) +def test_should_not_return_content_and_subject_if_requested(admin_request, sample_service, template_type): + create_template(sample_service, template_type=template_type) json_response = admin_request.get( - "template.get_all_templates_for_service", service_id=sample_service.id, **extra_args + "template.get_all_templates_for_service", + service_id=sample_service.id, + detailed=False, ) assert json_response["data"][0].keys() == { - "content", "folder", "id", "is_precompiled_letter", "name", "template_type", } - assert json_response["data"][0]["content"] == expected_content @pytest.mark.parametrize(