From a4d9bc99a8efe639c45c303e2733179b441bbd51 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 21 Jun 2022 12:53:22 +0300 Subject: [PATCH] Rename field `webhook` to `url` for outgoing webhook public api endpoint, update tests --- engine/apps/public_api/serializers/action.py | 16 +++++++-------- .../public_api/tests/test_custom_actions.py | 20 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/engine/apps/public_api/serializers/action.py b/engine/apps/public_api/serializers/action.py index 963aacbc..f652bc7c 100644 --- a/engine/apps/public_api/serializers/action.py +++ b/engine/apps/public_api/serializers/action.py @@ -14,6 +14,7 @@ class ActionCreateSerializer(serializers.ModelSerializer): id = serializers.CharField(read_only=True, source="public_primary_key") organization = serializers.HiddenField(default=CurrentOrganizationDefault()) team_id = TeamPrimaryKeyRelatedField(required=False, allow_null=True, source="team") + url = serializers.CharField(required=True, allow_null=False, allow_blank=False, source="webhook") class Meta: model = CustomButton @@ -22,7 +23,7 @@ class ActionCreateSerializer(serializers.ModelSerializer): "name", "organization", "team_id", - "webhook", + "url", "data", "user", "password", @@ -31,7 +32,6 @@ class ActionCreateSerializer(serializers.ModelSerializer): ] extra_kwargs = { "name": {"required": True, "allow_null": False, "allow_blank": False}, - "webhook": {"required": True, "allow_null": False, "allow_blank": False}, "data": {"required": False, "allow_null": True, "allow_blank": False}, "user": {"required": False, "allow_null": True, "allow_blank": False}, "password": {"required": False, "allow_null": True, "allow_blank": False}, @@ -41,13 +41,13 @@ class ActionCreateSerializer(serializers.ModelSerializer): validators = [UniqueTogetherValidator(queryset=CustomButton.objects.all(), fields=["name", "organization"])] - def validate_webhook(self, webhook): - if webhook: + def validate_url(self, url): + if url: try: - URLValidator()(webhook) + URLValidator()(url) except ValidationError: - raise serializers.ValidationError("Webhook is incorrect") - return webhook + raise serializers.ValidationError("URL is incorrect") + return url return None def validate_data(self, data): @@ -74,12 +74,12 @@ class ActionCreateSerializer(serializers.ModelSerializer): class ActionUpdateSerializer(ActionCreateSerializer): team_id = TeamPrimaryKeyRelatedField(source="team", read_only=True) + url = serializers.CharField(required=False, allow_null=False, allow_blank=False, source="webhook") class Meta(ActionCreateSerializer.Meta): extra_kwargs = { "name": {"required": False, "allow_null": False, "allow_blank": False}, - "webhook": {"required": False, "allow_null": False, "allow_blank": False}, "data": {"required": False, "allow_null": True, "allow_blank": False}, "user": {"required": False, "allow_null": True, "allow_blank": False}, "password": {"required": False, "allow_null": True, "allow_blank": False}, diff --git a/engine/apps/public_api/tests/test_custom_actions.py b/engine/apps/public_api/tests/test_custom_actions.py index ee0e5f67..9fb4ebb6 100644 --- a/engine/apps/public_api/tests/test_custom_actions.py +++ b/engine/apps/public_api/tests/test_custom_actions.py @@ -30,7 +30,7 @@ def test_get_custom_actions( "id": custom_action.public_primary_key, "name": custom_action.name, "team_id": None, - "webhook": custom_action.webhook, + "url": custom_action.webhook, "data": custom_action.data, "user": custom_action.user, "password": custom_action.password, @@ -68,7 +68,7 @@ def test_get_custom_actions_filter_by_name( "id": custom_action.public_primary_key, "name": custom_action.name, "team_id": None, - "webhook": custom_action.webhook, + "url": custom_action.webhook, "data": custom_action.data, "user": custom_action.user, "password": custom_action.password, @@ -122,7 +122,7 @@ def test_get_custom_action( "id": custom_action.public_primary_key, "name": custom_action.name, "team_id": None, - "webhook": custom_action.webhook, + "url": custom_action.webhook, "data": custom_action.data, "user": custom_action.user, "password": custom_action.password, @@ -144,7 +144,7 @@ def test_create_custom_action(make_organization_and_user_with_token): data = { "name": "Test outgoing webhook", - "webhook": "https://example.com", + "url": "https://example.com", } response = client.post(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}") @@ -155,7 +155,7 @@ def test_create_custom_action(make_organization_and_user_with_token): "id": custom_action.public_primary_key, "name": custom_action.name, "team_id": None, - "webhook": custom_action.webhook, + "url": custom_action.webhook, "data": custom_action.data, "user": custom_action.user, "password": custom_action.password, @@ -179,13 +179,13 @@ def test_create_custom_action_invalid_data( data = { "name": "Test outgoing webhook", - "webhook": "invalid_url", + "url": "invalid_url", } response = client.post(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_400_BAD_REQUEST - assert response.data["webhook"][0] == "Webhook is incorrect" + assert response.data["url"][0] == "URL is incorrect" data = { "name": "Test outgoing webhook", @@ -194,10 +194,10 @@ def test_create_custom_action_invalid_data( response = client.post(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}") assert response.status_code == status.HTTP_400_BAD_REQUEST - assert response.data["webhook"][0] == "This field is required." + assert response.data["url"][0] == "This field is required." data = { - "webhook": "https://example.com", + "url": "https://example.com", } response = client.post(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}") @@ -231,7 +231,7 @@ def test_update_custom_action( "id": custom_action.public_primary_key, "name": data["name"], "team_id": None, - "webhook": custom_action.webhook, + "url": custom_action.webhook, "data": custom_action.data, "user": custom_action.user, "password": custom_action.password,