mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 00:11:16 -05:00
separated schemas once more into "with template" and "with personalisation"
"with personalisation" should only be used by the public notification api "with template" should be used when we want template name, etc details. also added an xfail test for correctly constructing notification personalisation
This commit is contained in:
@@ -11,7 +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):
|
||||
with notify_api.test_request_context():
|
||||
@@ -615,6 +615,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