mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
- Use these validation methods in post_sms_notification and the version 1 of post_notification. - Create a v2 error handlers. - InvalidRequest has a to_dict method for private and v1 error responses and a to_dict_v2 method to create the v2 of the error responses. - Each validation method has extensive unit tests, so the unit test for the endpoint do not need to check every error case, but check that the error handle formats the message correctly. - The format of the error messages is still a work on progress. - This version of the api could be deployed without causing a problem to the application. - The new endpoing is still a work in progress and is not being used yet.
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
from flask import json
|
|
|
|
from tests import create_authorization_header
|
|
|
|
|
|
def test_post_sms_notification_returns_201(notify_api, sample_template):
|
|
with notify_api.test_request_context():
|
|
with notify_api.test_client() as client:
|
|
data = {
|
|
'phone_number': '+447700900855',
|
|
'template_id': str(sample_template.id)
|
|
}
|
|
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
|
|
|
response = client.post(
|
|
path='/v2/notifications/sms',
|
|
data=json.dumps(data),
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
|
|
|
assert response.status_code == 201
|
|
|
|
|
|
def test_post_sms_notification_returns_404_when_template_is_wrong_type(notify_api, sample_email_template):
|
|
with notify_api.test_request_context():
|
|
with notify_api.test_client() as client:
|
|
data = {
|
|
'phone_number': '+447700900855',
|
|
'template_id': str(sample_email_template.id)
|
|
}
|
|
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
|
|
|
response = client.post(
|
|
path='/v2/notifications/sms',
|
|
data=json.dumps(data),
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
|
|
|
assert response.status_code == 400
|
|
resp_text = json.loads(response.get_data(as_text=True))
|
|
assert resp_text['code'] == '10400'
|
|
assert resp_text['message'] == '{0} template is not suitable for {1} notification'.format('email', 'sms')
|
|
assert resp_text['link'] == 'link to documentation'
|
|
field = "{0} template is not suitable for {1} notification".format("email", "sms")
|
|
assert resp_text['fields'][0]['template'] == field
|