Skip to content

Commit

Permalink
make TemplateSchemaNoDetail tidier now that it doesn't have content
Browse files Browse the repository at this point in the history
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
  • Loading branch information
leohemsted committed Jan 10, 2024
1 parent 3f802e4 commit 4bbec83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
30 changes: 8 additions & 22 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
36 changes: 6 additions & 30 deletions tests/app/template/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4bbec83

Please sign in to comment.