Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for correctionFor = null #407

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/objects/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ObjectRecordSerializer(serializers.ModelSerializer):
source="correct",
slug_field="index",
required=False,
allow_null=True,
help_text=_("Index of the record corrected by the current record"),
)
correctedBy = serializers.SlugRelatedField(
Expand Down
5 changes: 1 addition & 4 deletions src/objects/api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,6 @@ components:
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
description: Object data, based on OBJECTTYPE
geometry:
allOf:
Expand Down Expand Up @@ -794,8 +792,6 @@ components:
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
description: Object data, based on OBJECTTYPE
geometry:
allOf:
Expand Down Expand Up @@ -825,6 +821,7 @@ components:
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
nullable: true
correctedBy:
type: integer
maximum: 2147483647
Expand Down
7 changes: 1 addition & 6 deletions src/objects/api/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,6 @@ components:
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
description: Object data, based on OBJECTTYPE
geometry:
allOf:
Expand Down Expand Up @@ -890,8 +888,6 @@ components:
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
description: Object data, based on OBJECTTYPE
geometry:
allOf:
Expand Down Expand Up @@ -921,6 +917,7 @@ components:
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
nullable: true
correctedBy:
type: integer
maximum: 2147483647
Expand Down Expand Up @@ -1044,8 +1041,6 @@ components:
type: boolean
description: Use field-based authorization
fields:
type: object
additionalProperties: {}
nullable: true
title: Mode
description: Fields allowed for this token in relation to objecttype versions.
Expand Down
41 changes: 39 additions & 2 deletions src/objects/tests/v2/test_object_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def test_history_object(self, m):
],
)

# In the ticket https://github.com/maykinmedia/objects-api/issues/282 we descovered that updating an object \
# where the startAt value has been moddified with an earlier date causes an 500 response.
# In the ticket https://github.com/maykinmedia/objects-api/issues/282 we discovered that updating an object \
# where the startAt value has been modified with an earlier date causes an 500 response.
def test_updating_object_after_changing_the_startAt_value_returns_200(self, m):
mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes")
m.get(
Expand Down Expand Up @@ -388,3 +388,40 @@ def test_updating_object_after_changing_the_startAt_value_returns_200(self, m):
response_updating_data_after_startAt_modification.status_code,
status.HTTP_200_OK,
)

# regression test for https://github.com/maykinmedia/objects-api/issues/268
def test_update_object_correctionFor(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),
)
m.get(self.object_type.url, json=mock_objecttype(self.object_type.url))

initial_record = ObjectRecordFactory.create(
object__object_type=self.object_type, version=1
)
object = initial_record.object
# correction record
ObjectRecordFactory.create(object=object, version=1, correct=initial_record)

url = reverse("object-detail", args=[object.uuid])
modified_data = {
"type": self.object_type.url,
"record": {
"typeVersion": 1,
"data": {"plantDate": "2020-04-12", "diameter": 30},
"startAt": "2024-01-01",
"correctionFor": None,
},
}

response = self.client.put(url, data=modified_data, **GEO_WRITE_KWARGS)

self.assertEqual(response.status_code, 200)

object.refresh_from_db()
self.assertEqual(object.records.count(), 3)

last_record = object.last_record
self.assertIsNone(last_record.correct)
Loading