mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Merge pull request #1134 from alphagov/imdad-feat-check-notification-table-for-last-template-usage
Update the last template usage query to check Notification table
This commit is contained in:
@@ -5,7 +5,12 @@ import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import (sample_template as create_sample_template, sample_notification, sample_email_template)
|
||||
from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
sample_notification,
|
||||
sample_notification_history,
|
||||
sample_email_template
|
||||
)
|
||||
|
||||
|
||||
def test_get_all_template_statistics_with_bad_arg_returns_400(client, sample_service):
|
||||
@@ -211,8 +216,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 +226,44 @@ 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 not 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)]
|
||||
|
||||
|
||||
def test_get_template_statistics_by_id_returns_empty_for_old_notification(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
client,
|
||||
sample_template
|
||||
):
|
||||
sample_notification_history(notify_db, notify_db_session, sample_template)
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template-statistics/{}'.format(sample_template.service.id, sample_template.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))['data']
|
||||
assert not json_resp
|
||||
|
||||
Reference in New Issue
Block a user