mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Return metadata about placeholders
In the future, we may want to return additional information about
placeholders.
We came up with three possible formats:
1. list of `dict`s, eg `[{'name': 'first name', 'required': True}]`
2. `dict` of `list`s, eg `{'required': ['first name']}`
3. `dict` of `dict`s, eg `{'name': {'required': True}}`
I don’t like 1. because it’s harder to traverse if all you want is the
name of the placeholders, and suggests that you could have two
placeholders with the same name (which you can’t). I don’t like 2.
because it only lets the data be sliced by one dimension (unless the
inner lists aren’t exclusive, in which case you’d need to filter
duplicates when just listing placeholders).
I think 3. has the two advantages of:
- represents that personalisation is unique, ie you can’t pass back in
two different values for the same key
- is forward compatible, ie we can add many more properties of a
placeholder without breaking anything
So this commit implements 3.
This commit is contained in:
@@ -40,7 +40,7 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
|
||||
'body': template.content,
|
||||
"subject": expected_subject,
|
||||
'name': expected_name,
|
||||
'personalisation': [],
|
||||
'personalisation': {},
|
||||
}
|
||||
|
||||
assert json_response == expected_response
|
||||
@@ -52,7 +52,14 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
|
||||
"template_type": SMS_TYPE,
|
||||
"content": "Hello ((placeholder)) ((conditional??yes))",
|
||||
},
|
||||
["placeholder", "conditional"]
|
||||
{
|
||||
"placeholder": {
|
||||
"required": True
|
||||
},
|
||||
"conditional": {
|
||||
"required": True
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -60,7 +67,14 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
|
||||
"subject": "((subject))",
|
||||
"content": "((content))",
|
||||
},
|
||||
["subject", "content"]
|
||||
{
|
||||
"subject": {
|
||||
"required": True
|
||||
},
|
||||
"content": {
|
||||
"required": True
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -68,7 +82,17 @@ def test_get_template_by_id_returns_200(client, sample_service, tmp_type, expect
|
||||
"subject": "((letterSubject))",
|
||||
"content": "((letter_content))",
|
||||
},
|
||||
["letterSubject", "letter_content", "contact block"]
|
||||
{
|
||||
"letterSubject": {
|
||||
"required": True,
|
||||
},
|
||||
"letter_content": {
|
||||
"required": True,
|
||||
},
|
||||
"contact block": {
|
||||
"required": True,
|
||||
},
|
||||
},
|
||||
)
|
||||
])
|
||||
@pytest.mark.parametrize("version", valid_version_params)
|
||||
|
||||
Reference in New Issue
Block a user