Skip to content

Commit

Permalink
Allow updating Incident.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf authored May 7, 2024
1 parent 737371e commit 15e0325
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.d/+807.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow replacing Incident.metadata with another json blob via API, no questions
asked, nothing to see here.
6 changes: 4 additions & 2 deletions src/argus/incident/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
from collections import OrderedDict
from typing import List, Tuple
from typing import List, Tuple, Any, Dict

from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
Expand Down Expand Up @@ -171,7 +172,7 @@ def validate(self, attrs: dict):


class IncidentPureDeserializer(serializers.ModelSerializer):
EDITABLE_FIELDS = set(["ticket_url", "details_url", "level"])
EDITABLE_FIELDS = set(["ticket_url", "details_url", "level", "metadata"])

tags = IncidentTagRelationSerializer(many=True, write_only=True)

Expand All @@ -182,6 +183,7 @@ class Meta:
"details_url",
"ticket_url",
"level",
"metadata",
]

def update(self, instance: Incident, validated_data: dict):
Expand Down
18 changes: 18 additions & 0 deletions tests/incident/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,24 @@ def test_can_update_incident_level(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(Incident.objects.get(pk=incident_pk).level, 2)

def test_can_update_incident_metadata(self):
incident = self.add_open_incident_with_start_event_and_tag()
start_metadata = {"foo": "xux"}
incident.metadata = start_metadata
incident.save()
incident_path = reverse("v2:incident:incident-detail", args=[incident.pk])
changed_metadata = {"bar": "gurba"}
response = self.client.patch(
path=incident_path,
data={
"metadata": changed_metadata,
},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
changed_incident = Incident.objects.get(pk=incident.pk)
self.assertNotEqual(changed_incident.metadata, start_metadata)
self.assertEqual(changed_incident.metadata, changed_metadata)

def test_can_get_all_acknowledgements_of_incident(self):
ack = self.add_acknowledgement_with_incident_and_event()
incident = ack.event.incident
Expand Down

0 comments on commit 15e0325

Please sign in to comment.