2016-08-31 11:53:54 +01:00
|
|
|
from app.dao.api_key_dao import save_model_api_key
|
2024-01-16 14:46:17 -05:00
|
|
|
from app.enums import KeyType
|
|
|
|
|
from app.models import ApiKey
|
2021-08-04 15:12:09 +01:00
|
|
|
from tests import create_service_authorization_header
|
2016-08-30 15:54:22 +01:00
|
|
|
|
2024-05-30 12:27:07 -07:00
|
|
|
from . import return_json_from_response, validate_v0
|
2021-03-10 13:55:06 +00:00
|
|
|
|
2016-08-30 15:54:22 +01:00
|
|
|
|
2016-11-22 11:17:28 +00:00
|
|
|
def _get_notification(client, notification, url):
|
2023-08-29 14:54:30 -07:00
|
|
|
save_model_api_key(
|
|
|
|
|
ApiKey(
|
|
|
|
|
service=notification.service,
|
|
|
|
|
name="api_key",
|
|
|
|
|
created_by=notification.service.created_by,
|
2024-01-16 14:46:17 -05:00
|
|
|
key_type=KeyType.NORMAL,
|
2023-08-29 14:54:30 -07:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
auth_header = create_service_authorization_header(
|
|
|
|
|
service_id=notification.service_id
|
|
|
|
|
)
|
2016-11-22 11:03:57 +00:00
|
|
|
return client.get(url, headers=[auth_header])
|
|
|
|
|
|
|
|
|
|
|
2016-11-25 16:46:19 +00:00
|
|
|
# v0
|
2016-11-22 11:03:57 +00:00
|
|
|
def test_get_api_sms_contract(client, sample_notification):
|
2023-08-29 14:54:30 -07:00
|
|
|
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")
|
2016-08-31 11:53:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_job_sms_contract(client, sample_notification):
|
2023-08-29 14:54:30 -07:00
|
|
|
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")
|
2016-08-30 15:54:22 +01:00
|
|
|
|
|
|
|
|
|
2025-05-16 14:14:50 -04:00
|
|
|
def test_get_notifications_contract(
|
|
|
|
|
client, sample_notification, sample_email_notification
|
|
|
|
|
):
|
2023-08-29 14:54:30 -07:00
|
|
|
response_json = return_json_from_response(
|
|
|
|
|
_get_notification(client, sample_notification, "/notifications")
|
|
|
|
|
)
|
2025-05-14 15:01:01 -04:00
|
|
|
notifications = response_json["notifications"]
|
|
|
|
|
assert notifications, "No notifications returned"
|
|
|
|
|
assert notifications[0]["template"]["template_type"] == "sms"
|
2023-08-29 14:54:30 -07:00
|
|
|
validate_v0(response_json, "GET_notifications_return.json")
|