|
7 | 7 | from redash.destinations.discord import Discord |
8 | 8 | from redash.destinations.slack import Slack |
9 | 9 | from redash.destinations.webex import Webex |
10 | | -from redash.destinations.webhook import Webhook |
11 | 10 | from redash.models import Alert, NotificationDestination |
12 | 11 | from tests import BaseTestCase |
13 | 12 |
|
@@ -519,48 +518,3 @@ def test_datadog_notify_calls_requests_post(): |
519 | 518 | ) |
520 | 519 |
|
521 | 520 | assert mock_response.status_code == 202 |
522 | | - |
523 | | - |
524 | | -def test_webhook_notify_handles_unicode(): |
525 | | - # Create a mock alert with all the properties needed by serialize_alert |
526 | | - alert = mock.Mock() |
527 | | - alert.id = 1 |
528 | | - alert.name = "Test Alert" |
529 | | - alert.custom_subject = "Test Subject With Unicode: 晨" |
530 | | - alert.custom_body = "Test Body" |
531 | | - alert.options = {} |
532 | | - alert.state = "ok" |
533 | | - alert.last_triggered_at = None |
534 | | - alert.updated_at = "2025-12-02T08:00:00Z" |
535 | | - alert.created_at = "2025-12-02T08:00:00Z" |
536 | | - alert.rearm = None |
537 | | - alert.query_id = 10 |
538 | | - alert.user_id = 20 |
539 | | - |
540 | | - query = mock.Mock() |
541 | | - user = mock.Mock() |
542 | | - app = mock.Mock() |
543 | | - host = "http://redash.local" |
544 | | - options = {"url": "https://example.com/webhook", "username": "user", "password": "password"} |
545 | | - metadata = {} |
546 | | - new_state = Alert.TRIGGERED_STATE |
547 | | - destination = Webhook(options) |
548 | | - |
549 | | - with mock.patch("redash.destinations.webhook.requests.post") as mock_post: |
550 | | - mock_response = mock.Mock() |
551 | | - mock_response.status_code = 200 |
552 | | - mock_post.return_value = mock_response |
553 | | - |
554 | | - destination.notify(alert, query, user, new_state, app, host, metadata, options) |
555 | | - |
556 | | - # Get the data passed to the mock |
557 | | - call_args, call_kwargs = mock_post.call_args |
558 | | - sent_data = call_kwargs["data"] |
559 | | - |
560 | | - # 1. Make sure we send bytes |
561 | | - assert isinstance(sent_data, bytes) |
562 | | - |
563 | | - # 2. Make sure the bytes are the correct UTF-8 encoded JSON |
564 | | - decoded_data = json.loads(sent_data.decode("utf-8")) |
565 | | - assert decoded_data["alert"]["title"] == alert.custom_subject |
566 | | - assert "Test Subject With Unicode: 晨" in sent_data.decode("utf-8") |
0 commit comments