From 03b791e743724178aa89894825530d10fe895007 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Thu, 5 Dec 2024 16:46:37 +0000 Subject: [PATCH] Fix test connection on integration create (#5328) Related to https://github.com/grafana/support-escalations/issues/13751 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- engine/apps/api/tests/test_alert_receive_channel.py | 6 ++++++ engine/apps/api/views/alert_receive_channel.py | 4 ++++ engine/tox.ini | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/apps/api/tests/test_alert_receive_channel.py b/engine/apps/api/tests/test_alert_receive_channel.py index 6378de0c..460c335e 100644 --- a/engine/apps/api/tests/test_alert_receive_channel.py +++ b/engine/apps/api/tests/test_alert_receive_channel.py @@ -2066,6 +2066,12 @@ def test_alert_receive_channel_test_connection( data = { "integration": integration_config.slug, "team": None, + "create_default_webhooks": True, + "alert_group_labels": { + "inheritable": {}, + "custom": [], + "template": None, + }, } # no test connection setup diff --git a/engine/apps/api/views/alert_receive_channel.py b/engine/apps/api/views/alert_receive_channel.py index e70be142..19c40a57 100644 --- a/engine/apps/api/views/alert_receive_channel.py +++ b/engine/apps/api/views/alert_receive_channel.py @@ -24,6 +24,7 @@ from apps.api.serializers.alert_receive_channel import ( AlertReceiveChannelSerializer, AlertReceiveChannelUpdateSerializer, FilterAlertReceiveChannelSerializer, + IntegrationAlertGroupLabelsSerializer, ) from apps.api.serializers.alert_receive_channel_connection import ( AlertReceiveChannelConnectedChannelSerializer, @@ -309,7 +310,10 @@ class AlertReceiveChannelView( # check we have all the required information serializer.is_valid(raise_exception=True) if instance is None: + # pop extra fields so they are not passed to AlertReceiveChannel(**serializer.validated_data) serializer.validated_data.pop("create_default_webhooks", None) + IntegrationAlertGroupLabelsSerializer.pop_alert_group_labels(serializer.validated_data) + # create in-memory instance to test with the (possible) unsaved data instance = AlertReceiveChannel(**serializer.validated_data) else: diff --git a/engine/tox.ini b/engine/tox.ini index be2959bb..3e98f312 100644 --- a/engine/tox.ini +++ b/engine/tox.ini @@ -21,7 +21,7 @@ banned-modules = # --allow-hosts = allow connections to the given hostnames/IPs. # - localhost = our tests on CI use localhost as the host to connect to databases running locally in docker container # - oncall-dev-mariadb = if you're running things locally, with a MariaDB instance running, there's a good chance the hostname will be this -addopts = --dist no --no-migrations --color=yes --showlocals --disable-socket --allow-hosts=localhost,oncall-dev-mariadb +addopts = --dist no --no-migrations --color=yes --showlocals # https://pytest-django.readthedocs.io/en/latest/faq.html#my-tests-are-not-being-found-why python_files = tests.py test_*.py *_tests.py