From 5924ad5121744210099b63c73c99b678b69b8da7 Mon Sep 17 00:00:00 2001 From: Sidney Richards Date: Wed, 9 Oct 2024 15:43:33 +0200 Subject: [PATCH] Add test to illustrate expected validation on object PATCH --- src/objects/tests/v2/test_object_api.py | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/objects/tests/v2/test_object_api.py b/src/objects/tests/v2/test_object_api.py index c80c6696..1c2cd2f4 100644 --- a/src/objects/tests/v2/test_object_api.py +++ b/src/objects/tests/v2/test_object_api.py @@ -333,6 +333,42 @@ def test_patch_object_record(self, m): self.assertEqual(initial_record.corrected, current_record) self.assertEqual(initial_record.end_at, date(2020, 1, 1)) + def test_patch_validates_merged_object_rather_than_partial_object(self, m): + mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes") + m.get( + f"{self.object_type.url}/versions/1", + json=mock_objecttype_version(self.object_type.url), + ) + + initial_record = ObjectRecordFactory.create( + version=1, + object__object_type=self.object_type, + start_at=date.today(), + data={"name": "Name", "diameter": 20}, + ) + + url = reverse("object-detail", args=[initial_record.object.uuid]) + data = { + "record": { + "data": { + # Note the required fields are missing, and that should be fine: + # the _merged_ object should be valid according to the schema, not + # the partial. + "plantDate": "2024-10-09" + }, + }, + } + + response = self.client.patch(url, data, **GEO_WRITE_KWARGS) + self.assertEqual(response.status_code, status.HTTP_200_OK) + + initial_record.refresh_from_db() + self.assertEqual( + initial_record.data, + {"plantDate": "2024-10-09", "diameter": 20, "name": "Name"}, + ) + + def test_delete_object(self, m): record = ObjectRecordFactory.create(object__object_type=self.object_type) object = record.object