Skip to content

Commit

Permalink
Merge pull request #1551 from open-zaak/feature/1550-bestandsdeel-lock
Browse files Browse the repository at this point in the history
✨ [#1550] add 'lock' to BestandsDeel response
  • Loading branch information
annashamray committed Feb 1, 2024
2 parents 905a4e5 + 7fcc766 commit 4ea3205
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/openzaak/components/documenten/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,14 @@ def get_attribute(self, instance):
return instance.get_informatieobject()


class LockField(serializers.CharField):
def get_attribute(self, instance):
return instance.get_current_lock_value()


class BestandsDeelSerializer(serializers.HyperlinkedModelSerializer):
lock = serializers.CharField(
write_only=True,
lock = LockField(
required=True,
help_text="Hash string, which represents id of the lock of related informatieobject",
)

Expand Down
58 changes: 58 additions & 0 deletions src/openzaak/components/documenten/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ def _upload_part_files(self):
)

self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
self.assertEqual(response.json()["lock"], self.canonical.lock)

part.refresh_from_db()

Expand Down Expand Up @@ -743,6 +744,63 @@ def test_upload_part_twice_correct(self):
self.assertNotEqual(part.inhoud, "")
self.assertEqual(part.voltooid, True)

def test_upload_part_without_lock(self):
"""
Test the upload of the part file without lock
Input:
* part file
Expected result:
* 400 status
"""
self._create_metadata()

# upload one of parts again
self.file_content.seek(0)
part_files = split_file(
self.file_content, settings.DOCUMENTEN_UPLOAD_CHUNK_SIZE
)
part = self.bestandsdelen[0]
part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid)

response = self.client.put(
part_url, {"inhoud": part_files[0],}, format="multipart",
)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
error = get_validation_errors(response, "lock")
self.assertEqual(error["code"], "required")

def test_upload_part_with_incorrect_lock(self):
"""
Test the upload of the part file without lock
Input:
* part file
* lock (incorrect)
Expected result:
* 400 status
"""
self._create_metadata()

# upload one of parts again
self.file_content.seek(0)
part_files = split_file(
self.file_content, settings.DOCUMENTEN_UPLOAD_CHUNK_SIZE
)
part = self.bestandsdelen[0]
part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid)

response = self.client.put(
part_url, {"inhoud": part_files[0], "lock": "12345"}, format="multipart",
)

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "incorrect-lock-id")

def test_unlock_without_uploading(self):
"""
Test the unlock of the document with no part files uploaded
Expand Down

0 comments on commit 4ea3205

Please sign in to comment.