Use jsonschema validation + remove 'v2' schema

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.
This commit is contained in:
Paul Craig
2016-11-22 11:17:28 +00:00
parent fb50bb6325
commit 7ae427c4ef
12 changed files with 64 additions and 113 deletions

View File

@@ -1,44 +1,39 @@
from flask import json
from . import validate
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")
data = {
'to': '07700 900 855',
'template': str(sample_template.id)
}
auth_header = create_authorization_header(service_id=sample_template.service_id)
response = client.post(
path='/notifications/sms',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]
)
validate(response.get_data(as_text=True), 'POST_notification_return_sms.json')
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")
data = {
'to': 'foo@bar.com',
'template': str(sample_email_template.id)
}
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
response = client.post(
path='/notifications/email',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header]
)
validate(response.get_data(as_text=True), 'POST_notification_return_email.json')
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')