From 13b0fef41dff0633ab9047160d4c12672e4e60b7 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 19 Aug 2024 14:44:01 +0200 Subject: [PATCH] Make Incident.description editable --- changelog.d/811.changed.md | 1 + src/argus/incident/serializers.py | 11 ++++++++++- tests/incident/test_change_event.py | 23 ++++++++++++++++++++++- tests/incident/test_views.py | 24 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 changelog.d/811.changed.md diff --git a/changelog.d/811.changed.md b/changelog.d/811.changed.md new file mode 100644 index 000000000..22f16b8a3 --- /dev/null +++ b/changelog.d/811.changed.md @@ -0,0 +1 @@ +Make description editable \ No newline at end of file diff --git a/src/argus/incident/serializers.py b/src/argus/incident/serializers.py index db5396678..5ca2f901b 100644 --- a/src/argus/incident/serializers.py +++ b/src/argus/incident/serializers.py @@ -172,7 +172,15 @@ def validate(self, attrs: dict): class IncidentPureDeserializer(serializers.ModelSerializer): - EDITABLE_FIELDS = set(["ticket_url", "details_url", "level", "metadata"]) + EDITABLE_FIELDS = set( + [ + "ticket_url", + "details_url", + "level", + "metadata", + "description", + ] + ) tags = IncidentTagRelationSerializer(many=True, write_only=True) @@ -184,6 +192,7 @@ class Meta: "ticket_url", "level", "metadata", + "description", ] def update(self, instance: Incident, validated_data: dict): diff --git a/tests/incident/test_change_event.py b/tests/incident/test_change_event.py index 299d3c306..6f16aa6d1 100644 --- a/tests/incident/test_change_event.py +++ b/tests/incident/test_change_event.py @@ -20,7 +20,12 @@ def setUp(self): super().init_test_objects() self.url = "http://www.example.com/repository/issues/issue" - self.incident = StatefulIncidentFactory(level=1, ticket_url=self.url, details_url=self.url) + self.incident = StatefulIncidentFactory( + level=1, + ticket_url=self.url, + details_url=self.url, + description="old_description", + ) def teardown(self): connect_signals() @@ -146,3 +151,19 @@ def test_change_event_is_created_on_metadata_changes(self): self.assertTrue(change_events) self.assertIn(description, change_events_descriptions) self.assertEqual(change_events.get(description=description).actor, self.user1) + + def test_change_event_is_created_on_description_changes(self): + data = { + "description": "new_description", + } + description = ChangeEvent.format_description("description", "old_description", "new_description") + response = self.user1_rest_client.patch( + path=f"/api/v2/incidents/{self.incident.pk}/", + data=data, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + change_events = self.incident.events.filter(type=Event.Type.INCIDENT_CHANGE) + change_events_descriptions = [event.description for event in change_events] + self.assertTrue(change_events) + self.assertIn(description, change_events_descriptions) + self.assertEqual(change_events.get(description=description).actor, self.user1) diff --git a/tests/incident/test_views.py b/tests/incident/test_views.py index fc838ff21..49f85fcd2 100644 --- a/tests/incident/test_views.py +++ b/tests/incident/test_views.py @@ -147,6 +147,18 @@ 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_description(self): + incident_pk = self.add_open_incident_with_start_event_and_tag().pk + incident_path = reverse("v1:incident:incident-detail", args=[incident_pk]) + response = self.client.patch( + path=incident_path, + data={ + "description": "new description", + }, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(Incident.objects.get(pk=incident_pk).description, "new description") + def test_can_get_all_acknowledgements_of_incident(self): ack = self.add_acknowledgement_with_incident_and_event() incident = ack.event.incident @@ -649,6 +661,18 @@ def test_can_update_incident_metadata(self): self.assertNotEqual(changed_incident.metadata, start_metadata) self.assertEqual(changed_incident.metadata, changed_metadata) + def test_can_update_incident_description(self): + incident_pk = self.add_open_incident_with_start_event_and_tag().pk + incident_path = reverse("v2:incident:incident-detail", args=[incident_pk]) + response = self.client.patch( + path=incident_path, + data={ + "description": "new description", + }, + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(Incident.objects.get(pk=incident_pk).description, "new description") + def test_can_get_all_acknowledgements_of_incident(self): ack = self.add_acknowledgement_with_incident_and_event() incident = ack.event.incident