mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Emualated the validation methods that exist [in the python-client](620e5f7014/integration_test/__init__.py).
The `validate_v0` function loads json schemas from a local
`/schemas` directory, whereas the new `validate` function (which
we're going to use for our v2 API calls) uses the common
`get_notification_response` python schema defined in
"app/v2/notifications/notification_schemas.py".
Removed the new `v2` schema from the last commit as it's no longer
being used.
Also, refactored common code in the GET and POST contract files
so that making requests and converting responses to JSON are
pulled out into common functions.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from flask import json
|
|
|
|
from . import return_json_from_response, validate_v0
|
|
from tests import create_authorization_header
|
|
|
|
|
|
def _post_notification(client, template, url, to):
|
|
data = {
|
|
'to': to,
|
|
'template': str(template.id)
|
|
}
|
|
|
|
auth_header = create_authorization_header(service_id=template.service_id)
|
|
|
|
return client.post(
|
|
path=url,
|
|
data=json.dumps(data),
|
|
headers=[('Content-Type', 'application/json'), auth_header]
|
|
)
|
|
|
|
|
|
def test_post_sms_contract(client, mocker, sample_template):
|
|
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
response_json = return_json_from_response(_post_notification(
|
|
client, sample_template, url='/notifications/sms', to='07700 900 855'
|
|
))
|
|
validate_v0(response_json, 'POST_notification_return_sms.json')
|
|
|
|
|
|
def test_post_email_contract(client, mocker, sample_email_template):
|
|
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
response_json = return_json_from_response(_post_notification(
|
|
client, sample_email_template, url='/notifications/email', to='foo@bar.com'
|
|
))
|
|
validate_v0(response_json, 'POST_notification_return_email.json')
|