Skip to content

Commit

Permalink
Add test to illustrate expected validation on object PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Oct 9, 2024
1 parent 541682b commit 8299129
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/objects/tests/v2/test_object_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8299129

Please sign in to comment.