Update the last template usage query to check Notification table:

* Don't check the NotificationHistory table (this can cause a timeout)
* Check template actually exists first
This commit is contained in:
Imdad Ahad
2017-07-26 12:09:13 +01:00
parent 84a32180b3
commit f5e38a896c
3 changed files with 38 additions and 12 deletions

View File

@@ -211,8 +211,8 @@ def test_get_template_statistics_by_id_returns_last_notification(
def test_get_template_statistics_for_template_returns_empty_if_no_statistics(
client,
sample_template,
client,
sample_template,
):
auth_header = create_authorization_header()
@@ -221,7 +221,24 @@ def test_get_template_statistics_for_template_returns_empty_if_no_statistics(
headers=[('Content-Type', 'application/json'), auth_header],
)
assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['data'] == {}
def test_get_template_statistics_raises_error_for_nonexistent_template(
client,
sample_service,
fake_uuid
):
auth_header = create_authorization_header()
response = client.get(
'/service/{}/template-statistics/{}'.format(sample_service.id, fake_uuid),
headers=[('Content-Type', 'application/json'), auth_header],
)
assert response.status_code == 404
json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['message'] == 'No result found'
assert json_resp['result'] == 'error'
assert json_resp['message']['template_id'] == ['No template found for id {}'.format(sample_template.id)]