mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Merge branch 'master' into get-stats-for-today
This commit is contained in:
@@ -11,6 +11,7 @@ from app.dao.api_key_dao import save_model_api_key
|
||||
from app.models import ApiKey, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
from notifications_utils.template import NeededByTemplateError
|
||||
|
||||
|
||||
def test_get_sms_notification_by_id(notify_api, sample_notification):
|
||||
@@ -602,10 +603,10 @@ def test_get_notifications_for_service_returns_merged_template_content(notify_ap
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.get(
|
||||
path='/service/{}/notifications'.format(sample_template_with_placeholders.service.id),
|
||||
path='/notifications',
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 200
|
||||
|
||||
@@ -615,6 +616,40 @@ def test_get_notifications_for_service_returns_merged_template_content(notify_ap
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True, raises=NeededByTemplateError)
|
||||
def test_get_notification_selects_correct_template_for_personalisation(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_template):
|
||||
|
||||
create_sample_notification(notify_db,
|
||||
notify_db_session,
|
||||
service=sample_template.service,
|
||||
template=sample_template)
|
||||
|
||||
sample_template.content = '((name))'
|
||||
notify_db.session.commit()
|
||||
|
||||
create_sample_notification(notify_db,
|
||||
notify_db_session,
|
||||
service=sample_template.service,
|
||||
template=sample_template,
|
||||
personalisation={"name": "foo"})
|
||||
|
||||
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.get(path='/notifications', headers=[auth_header])
|
||||
assert response.status_code == 200
|
||||
|
||||
resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(resp['notifications']) == 2
|
||||
assert resp['notifications'][0]['template_version'] == 1
|
||||
assert resp['notifications'][0]['body'] == 'This is a template'
|
||||
assert resp['notifications'][1]['template_version'] == 2
|
||||
assert resp['notifications'][1]['body'] == 'foo'
|
||||
|
||||
|
||||
def _create_auth_header_from_key(api_key):
|
||||
token = create_jwt_token(secret=api_key.unsigned_secret, client_id=str(api_key.service_id))
|
||||
return [('Authorization', 'Bearer {}'.format(token))]
|
||||
|
||||
Reference in New Issue
Block a user