Fix public API integration default route (#2573)
Fix bug related to `order` and default route introduced in https://github.com/grafana/oncall/pull/2572
This commit is contained in:
parent
fd30430184
commit
dc137d705e
2 changed files with 44 additions and 2 deletions
|
|
@ -775,3 +775,45 @@ def test_get_list_integrations_link_and_inbound_email(
|
|||
else:
|
||||
assert integration_link == f"https://test.com/integrations/v1/{integration_type}/test123/"
|
||||
assert integration_inbound_email is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create_integration_default_route(
|
||||
make_organization_and_user_with_token,
|
||||
make_escalation_chain,
|
||||
):
|
||||
organization, _, token = make_organization_and_user_with_token()
|
||||
escalation_chain = make_escalation_chain(organization)
|
||||
|
||||
client = APIClient()
|
||||
data_for_create = {
|
||||
"type": "grafana",
|
||||
"name": "grafana_created",
|
||||
"team_id": None,
|
||||
"default_route": {"escalation_chain_id": escalation_chain.public_primary_key},
|
||||
}
|
||||
url = reverse("api-public:integrations-list")
|
||||
response = client.post(url, data=data_for_create, format="json", HTTP_AUTHORIZATION=f"{token}")
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert response.data["default_route"]["escalation_chain_id"] == escalation_chain.public_primary_key
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_update_integration_default_route(
|
||||
make_organization_and_user_with_token, make_escalation_chain, make_alert_receive_channel, make_channel_filter
|
||||
):
|
||||
organization, _, token = make_organization_and_user_with_token()
|
||||
integration = make_alert_receive_channel(organization)
|
||||
make_channel_filter(integration, is_default=True)
|
||||
escalation_chain = make_escalation_chain(organization)
|
||||
|
||||
client = APIClient()
|
||||
data_for_update = {
|
||||
"default_route": {"escalation_chain_id": escalation_chain.public_primary_key},
|
||||
}
|
||||
|
||||
url = reverse("api-public:integrations-detail", args=[integration.public_primary_key])
|
||||
response = client.put(url, data=data_for_update, format="json", HTTP_AUTHORIZATION=f"{token}")
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data["default_route"]["escalation_chain_id"] == escalation_chain.public_primary_key
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class OrderedModelSerializer(serializers.ModelSerializer):
|
|||
|
||||
def create(self, validated_data):
|
||||
# Remove "manual_order" and "order" fields from validated_data, so they are not passed to create method.
|
||||
manual_order = validated_data.pop("manual_order")
|
||||
manual_order = validated_data.pop("manual_order", False)
|
||||
order = validated_data.pop("order", None)
|
||||
|
||||
# Create the instance.
|
||||
|
|
@ -30,7 +30,7 @@ class OrderedModelSerializer(serializers.ModelSerializer):
|
|||
|
||||
def update(self, instance, validated_data):
|
||||
# Remove "manual_order" and "order" fields from validated_data, so they are not passed to update method.
|
||||
manual_order = validated_data.pop("manual_order")
|
||||
manual_order = validated_data.pop("manual_order", False)
|
||||
order = validated_data.pop("order", None)
|
||||
|
||||
# Adjust order of the instance if necessary.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue