mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Add 'v2' notification schema to contract tests
Converted python-based schema in "app/v2/notifications/notification_schema.py" into a pure json schema and tested it with the new "v2/" API route to confirm that it validates. Also refactored some common code in the public contract GET tests that returns notifications.
This commit is contained in:
@@ -1,59 +1,45 @@
|
||||
from . import validate
|
||||
from app.models import ApiKey, KEY_TYPE_NORMAL
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
def test_get_api_sms_contract(client, sample_notification):
|
||||
api_key = ApiKey(service=sample_notification.service,
|
||||
name='api_key',
|
||||
created_by=sample_notification.service.created_by,
|
||||
key_type=KEY_TYPE_NORMAL)
|
||||
save_model_api_key(api_key)
|
||||
sample_notification.job = None
|
||||
sample_notification.api_key = api_key
|
||||
sample_notification.key_type = KEY_TYPE_NORMAL
|
||||
dao_update_notification(sample_notification)
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
||||
def _get(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_authorization_header(service_id=notification.service_id)
|
||||
return client.get(url, headers=[auth_header])
|
||||
|
||||
|
||||
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')
|
||||
|
||||
|
||||
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')
|
||||
|
||||
|
||||
def test_get_api_email_contract(client, sample_email_notification):
|
||||
api_key = ApiKey(service=sample_email_notification.service,
|
||||
name='api_key',
|
||||
created_by=sample_email_notification.service.created_by,
|
||||
key_type=KEY_TYPE_NORMAL)
|
||||
save_model_api_key(api_key)
|
||||
sample_email_notification.job = None
|
||||
sample_email_notification.api_key = api_key
|
||||
sample_email_notification.key_type = KEY_TYPE_NORMAL
|
||||
dao_update_notification(sample_email_notification)
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
||||
response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header])
|
||||
|
||||
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||
|
||||
|
||||
def test_get_job_sms_contract(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get('/notifications/{}'.format(sample_notification.id), headers=[auth_header])
|
||||
|
||||
response = _get(client, sample_notification, '/notifications/{}'.format(sample_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_sms.json')
|
||||
|
||||
|
||||
def test_get_job_email_contract(client, sample_email_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_email_notification.service_id)
|
||||
response = client.get('/notifications/{}'.format(sample_email_notification.id), headers=[auth_header])
|
||||
|
||||
response = _get(client, sample_email_notification, '/notifications/{}'.format(sample_email_notification.id))
|
||||
validate(response.get_data(as_text=True), 'GET_notification_return_email.json')
|
||||
|
||||
|
||||
def test_get_notifications_contract(client, sample_notification, sample_email_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get('/notifications', headers=[auth_header])
|
||||
|
||||
response = _get(client, sample_notification, '/notifications')
|
||||
validate(response.get_data(as_text=True), 'GET_notifications_return.json')
|
||||
|
||||
Reference in New Issue
Block a user