mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 16:01:15 -05:00
Remove wrapper around response object
Before:
```json
{'data': {'template': '…'}}
```
There’s no need to wrap the response in key because there will only
ever be one valid key for the template preview endpoint.
Flatter is better:
```json
{
'content': '…',
'subject': '…',
'template_type': '…',
…
}
```
The response will be different if there’s an error, but you should be
checking the status code first anyway.
This commit:
- changes the template preview endpoint to return the above format
- adds a test to make sure that the original `/service/…/template/…`
endpoint still returns JSON in the same format (with a `data` key)
This commit is contained in:
@@ -108,7 +108,7 @@ def preview_template_by_id_and_service_id(service_id, template_id):
|
||||
|
||||
data['subject'], data['content'] = template_object.replaced_subject, template_object.replaced
|
||||
|
||||
return jsonify(data=data)
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@template.route('/<uuid:template_id>/version/<int:version>')
|
||||
|
||||
@@ -327,15 +327,48 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"subject, content, path, expected_subject, expected_content, expected_error", [
|
||||
"subject, content, template_type", [
|
||||
(
|
||||
'about your ((thing))',
|
||||
'hello ((name)) we’ve received your ((thing))',
|
||||
'/service/{}/template/{}',
|
||||
'about your ((thing))',
|
||||
'hello ((name)) we’ve received your ((thing))',
|
||||
None
|
||||
'email'
|
||||
),
|
||||
(
|
||||
None,
|
||||
'hello ((name)) we’ve received your ((thing))',
|
||||
'sms'
|
||||
)
|
||||
]
|
||||
)
|
||||
def test_should_get_a_single_template(
|
||||
notify_db,
|
||||
notify_api,
|
||||
sample_user,
|
||||
service_factory,
|
||||
subject,
|
||||
content,
|
||||
template_type
|
||||
):
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
|
||||
template = create_sample_template(
|
||||
notify_db, notify_db.session, subject_line=subject, content=content, template_type=template_type
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/{}'.format(template.service.id, template.id),
|
||||
headers=[create_authorization_header()]
|
||||
)
|
||||
|
||||
data = json.loads(response.get_data(as_text=True))['data']
|
||||
|
||||
assert response.status_code == 200
|
||||
assert data['content'] == content
|
||||
assert data['subject'] == subject
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"subject, content, path, expected_subject, expected_content, expected_error", [
|
||||
(
|
||||
'about your thing',
|
||||
'hello user we’ve received your thing',
|
||||
@@ -368,7 +401,7 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
)
|
||||
]
|
||||
)
|
||||
def test_should_get_a_single_template(
|
||||
def test_should_preview_a_single_template(
|
||||
notify_db,
|
||||
notify_api,
|
||||
sample_user,
|
||||
@@ -398,8 +431,8 @@ def test_should_get_a_single_template(
|
||||
assert content['message']['template'] == [expected_error]
|
||||
else:
|
||||
assert response.status_code == 200
|
||||
assert content['data']['content'] == expected_content
|
||||
assert content['data']['subject'] == expected_subject
|
||||
assert content['content'] == expected_content
|
||||
assert content['subject'] == expected_subject
|
||||
|
||||
|
||||
def test_should_return_empty_array_if_no_templates_for_service(notify_api, sample_service):
|
||||
|
||||
Reference in New Issue
Block a user