2016-08-31 12:22:05 +01:00
|
|
|
from flask import json
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
from . import return_json_from_response, validate_v0
|
2016-08-31 12:22:05 +01:00
|
|
|
from tests import create_authorization_header
|
|
|
|
|
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
def _post_notification(client, template, url, to):
|
2016-08-31 12:22:05 +01:00
|
|
|
data = {
|
2016-11-22 11:17:28 +00:00
|
|
|
'to': to,
|
|
|
|
|
'template': str(template.id)
|
2016-08-31 12:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
auth_header = create_authorization_header(service_id=template.service_id)
|
2016-08-31 12:22:05 +01:00
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
return client.post(
|
|
|
|
|
path=url,
|
2016-08-31 12:22:05 +01:00
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=[('Content-Type', 'application/json'), auth_header]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
def test_post_sms_contract(client, mocker, sample_template):
|
2017-03-30 10:46:15 +01:00
|
|
|
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
2016-08-31 12:22:05 +01:00
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
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')
|
2016-08-31 12:22:05 +01:00
|
|
|
|
|
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
def test_post_email_contract(client, mocker, sample_email_template):
|
2017-03-30 10:46:15 +01:00
|
|
|
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
2016-11-22 11:17:28 +00:00
|
|
|
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
|
2016-08-31 12:22:05 +01:00
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
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')
|