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:
Chris Hill-Scott
2017-09-22 10:12:32 +01:00
parent fa8e4b29f2
commit 55d185f50d
2 changed files with 34 additions and 5 deletions

View File

@@ -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)