mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 11:28:25 -04:00
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:
@@ -1,10 +1,11 @@
|
||||
from . import validate
|
||||
from . import return_json_from_response, validate_v0, validate
|
||||
from app.models import ApiKey, KEY_TYPE_NORMAL
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from app.v2.notifications.notification_schemas import get_notification_response
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def _get(client, notification, url):
|
||||
def _get_notification(client, notification, url):
|
||||
save_model_api_key(ApiKey(
|
||||
service=notification.service,
|
||||
name='api_key',
|
||||
@@ -16,30 +17,42 @@ def _get(client, notification, url):
|
||||
|
||||
|
||||
def test_get_v2_notification(client, sample_notification):
|
||||
response = _get(client, sample_notification, '/v2/notifications/{}'.format(sample_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_email_v2.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/v2/notifications/{}'.format(sample_notification.id)
|
||||
))
|
||||
validate(response_json, get_notification_response)
|
||||
|
||||
|
||||
def test_get_api_sms_contract(client, sample_notification):
|
||||
response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/notifications/{}'.format(sample_notification.id)
|
||||
))
|
||||
validate_v0(response_json, 'GET_notification_return_sms.json')
|
||||
|
||||
|
||||
def test_get_api_email_contract(client, sample_email_notification):
|
||||
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id)
|
||||
))
|
||||
validate_v0(response_json, 'GET_notification_return_email.json')
|
||||
|
||||
|
||||
def test_get_job_sms_contract(client, sample_notification):
|
||||
response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/notifications/{}'.format(sample_notification.id)
|
||||
))
|
||||
validate_v0(response_json, 'GET_notification_return_sms.json')
|
||||
|
||||
|
||||
def test_get_job_email_contract(client, sample_email_notification):
|
||||
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id)
|
||||
))
|
||||
validate_v0(response_json, 'GET_notification_return_email.json')
|
||||
|
||||
|
||||
def test_get_notifications_contract(client, sample_notification, sample_email_notification):
|
||||
response = _get(client, sample_notification, '/notifications')
|
||||
validate(response.get_data(as_text=True), 'GET_notifications_return.json')
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/notifications'
|
||||
))
|
||||
validate_v0(response_json, 'GET_notifications_return.json')
|
||||
|
||||
Reference in New Issue
Block a user