mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 08:38:26 -04:00
reformat
This commit is contained in:
@@ -10,14 +10,14 @@ def return_json_from_response(response):
|
||||
|
||||
|
||||
def validate_v0(json_to_validate, schema_filename):
|
||||
schema_dir = os.path.join(os.path.dirname(__file__), 'schemas/v0')
|
||||
resolver = jsonschema.RefResolver('file://' + schema_dir + '/', None)
|
||||
schema_dir = os.path.join(os.path.dirname(__file__), "schemas/v0")
|
||||
resolver = jsonschema.RefResolver("file://" + schema_dir + "/", None)
|
||||
with open(os.path.join(schema_dir, schema_filename)) as schema:
|
||||
jsonschema.validate(
|
||||
json_to_validate,
|
||||
json.load(schema),
|
||||
format_checker=jsonschema.FormatChecker(),
|
||||
resolver=resolver
|
||||
resolver=resolver,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -10,71 +10,103 @@ from . import return_json_from_response, validate, validate_v0
|
||||
|
||||
|
||||
def _get_notification(client, notification, url):
|
||||
save_model_api_key(ApiKey(
|
||||
service=notification.service,
|
||||
name='api_key',
|
||||
created_by=notification.service.created_by,
|
||||
key_type=KEY_TYPE_NORMAL
|
||||
))
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
save_model_api_key(
|
||||
ApiKey(
|
||||
service=notification.service,
|
||||
name="api_key",
|
||||
created_by=notification.service.created_by,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
)
|
||||
)
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=notification.service_id
|
||||
)
|
||||
return client.get(url, headers=[auth_header])
|
||||
|
||||
|
||||
# v2
|
||||
|
||||
|
||||
def test_get_v2_sms_contract(client, sample_notification):
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/v2/notifications/{}'.format(sample_notification.id)
|
||||
))
|
||||
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_v2_email_contract(client, sample_email_notification):
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_email_notification, '/v2/notifications/{}'.format(sample_email_notification.id)
|
||||
))
|
||||
response_json = return_json_from_response(
|
||||
_get_notification(
|
||||
client,
|
||||
sample_email_notification,
|
||||
"/v2/notifications/{}".format(sample_email_notification.id),
|
||||
)
|
||||
)
|
||||
validate(response_json, get_notification_response)
|
||||
|
||||
|
||||
def test_get_v2_notifications_contract(client, sample_notification):
|
||||
response_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/v2/notifications'
|
||||
))
|
||||
response_json = return_json_from_response(
|
||||
_get_notification(client, sample_notification, "/v2/notifications")
|
||||
)
|
||||
validate(response_json, get_notifications_response)
|
||||
|
||||
|
||||
# v0
|
||||
|
||||
|
||||
def test_get_api_sms_contract(client, sample_notification):
|
||||
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')
|
||||
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_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')
|
||||
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_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/notifications/{}'.format(sample_notification.id)
|
||||
))
|
||||
validate_v0(response_json, '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_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')
|
||||
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_json = return_json_from_response(_get_notification(
|
||||
client, sample_notification, '/notifications'
|
||||
))
|
||||
validate_v0(response_json, 'GET_notifications_return.json')
|
||||
def test_get_notifications_contract(
|
||||
client, sample_notification, sample_email_notification
|
||||
):
|
||||
response_json = return_json_from_response(
|
||||
_get_notification(client, sample_notification, "/notifications")
|
||||
)
|
||||
validate_v0(response_json, "GET_notifications_return.json")
|
||||
|
||||
@@ -6,33 +6,34 @@ from . import return_json_from_response, validate_v0
|
||||
|
||||
|
||||
def _post_notification(client, template, url, to):
|
||||
data = {
|
||||
'to': to,
|
||||
'template': str(template.id)
|
||||
}
|
||||
data = {"to": to, "template": str(template.id)}
|
||||
|
||||
auth_header = create_service_authorization_header(service_id=template.service_id)
|
||||
|
||||
return client.post(
|
||||
path=url,
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
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.celery.provider_tasks.deliver_sms.apply_async")
|
||||
|
||||
response_json = return_json_from_response(_post_notification(
|
||||
client, sample_template, url='/notifications/sms', to='202-867-5309'
|
||||
))
|
||||
validate_v0(response_json, 'POST_notification_return_sms.json')
|
||||
response_json = return_json_from_response(
|
||||
_post_notification(
|
||||
client, sample_template, url="/notifications/sms", to="202-867-5309"
|
||||
)
|
||||
)
|
||||
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.celery.provider_tasks.deliver_email.apply_async")
|
||||
|
||||
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')
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user