Skip to content

Commit 90651c5

Browse files
committed
test invalid payload templates
1 parent f76a57a commit 90651c5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/unit/test_actions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,31 @@ def test_create_alert_webhook_action_headers(gl_experimental: ExperimentalApi):
184184
assert len(alert.webhook_action) == 1
185185
assert alert.webhook_action[0].payload_template.template == template
186186
assert alert.webhook_action[0].payload_template.headers == headers
187+
188+
def test_create_alert_webhook_action_with_invalid_payload_template_headers(gl_experimental: ExperimentalApi):
189+
name = f"Test {datetime.utcnow()}"
190+
det = gl_experimental.get_or_create_detector(name, "test_query")
191+
condition = gl_experimental.make_condition("CHANGED_TO", {"label": "YES"})
192+
payload_template = gl_experimental.make_payload_template(
193+
'{"template": "This is a fine template"}', headers="bad headers"
194+
)
195+
webhook_action = gl_experimental.make_webhook_action(
196+
url="https://groundlight.ai", include_image=True, payload_template=payload_template
197+
)
198+
199+
bad_request_exception_status_code = 400
200+
201+
with pytest.raises(ApiException) as e:
202+
gl_experimental.create_alert(det, f"test_alert_{name}", condition, webhook_actions=webhook_action)
203+
assert e.value.status == bad_request_exception_status_code
204+
205+
payload_template = gl_experimental.make_payload_template(
206+
"This should not be a valid payload, it's valid jinja but won't produce valid json"
207+
)
208+
webhook_action = gl_experimental.make_webhook_action(
209+
url="https://groundlight.ai", include_image=True, payload_template=payload_template
210+
)
211+
212+
with pytest.raises(ApiException) as e:
213+
gl_experimental.create_alert(det, f"test_alert_{name}", condition, webhook_actions=webhook_action)
214+
assert e.value.status == bad_request_exception_status_code

0 commit comments

Comments
 (0)