33import pytest
44from groundlight import ApiException , ExperimentalApi
55from groundlight_openapi_client .exceptions import NotFoundException
6-
6+ from groundlight_openapi_client .model .payload_template import PayloadTemplate
7+ import json
78
89def test_create_action (gl_experimental : ExperimentalApi ):
910 # We first clear out any rules in case the account has any left over from a previous test
@@ -154,3 +155,33 @@ def test_create_alert_webhook_action_with_invalid_payload_template(gl_experiment
154155 with pytest .raises (ApiException ) as e :
155156 gl_experimental .create_alert (det , f"test_alert_{ name } " , condition , webhook_actions = webhook_action )
156157 assert e .value .status == bad_request_exception_status_code
158+
159+ def test_create_alert_webhook_action_headers (gl_experimental : ExperimentalApi ):
160+ name = f"Test { datetime .utcnow ()} "
161+ det = gl_experimental .get_or_create_detector (name , "test_query" )
162+ condition = gl_experimental .make_condition ("ANSWERED_CONSECUTIVELY" , {"num_consecutive_labels" : 1 , "label" : "YES" })
163+
164+ test_api_key = "test_api_key"
165+ url = "https://example.com/webhook"
166+ headers = {
167+ "Authorization" : f"Bearer { test_api_key } " ,
168+ }
169+
170+ template = """{"records": [{"fields": {"detector_id": "{{ detector_id }}", "image_query_id": "{{ image_query_id }}", "activation_time": "{{ activation_time }}" } }]}"""
171+
172+ payload_template = {
173+ "template" : template ,
174+ "headers" : headers
175+ }
176+ webhook_action = gl_experimental .make_webhook_action (url = url , include_image = False , payload_template = payload_template )
177+
178+ alert = gl_experimental .create_alert (
179+ det ,
180+ f"test_alert_{ name } " ,
181+ condition ,
182+ webhook_actions = webhook_action ,
183+ )
184+
185+ assert len (alert .webhook_action ) == 1
186+ assert alert .webhook_action [0 ].payload_template .template == template
187+ assert alert .webhook_action [0 ].payload_template .headers == headers
0 commit comments