def test_upload_part_twice_correct(self): """ Test the upload of the same part file several times Input: * part file * lock Expected result: * the repeated upload of the same file is permiitted. Voltooid = True """ self._create_metadata() self._upload_part_files() # upload one of parts again self.file_content.seek(0) part_files = split_file(self.file_content, settings.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": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) part.refresh_from_db() self.assertNotEqual(part.inhoud, "") self.assertEqual(part.voltooid, True)
def test_upload_part_wrong_size(self): """ Test the upload of the incorrect part file Input: * part files with the size different from grootte field * lock Expected result: * 400 status because of the difference between expected and actual file sizes """ self._create_metadata() # change file size for part file part = self.bestandsdelen[0] part.omvang = part.omvang + 1 part.save() # upload part file part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid) part_file = split_file(self.file_content, settings.CHUNK_SIZE)[0] response = self.client.put( part_url, {"inhoud": part_file, "lock": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "file-size")
def test_unlock_not_finish_upload_force(self): """ Test the unlock of the document with not all part files uploaded Input: * bestandsomvang of the document > 0 * bestandsdelen objects are created, some of them are uploaded * client has 'documenten.geforceerd-unlock' scope Expected result: * document is unlocked * all bestandsdelen are deleted * bestandsomvang is None """ self.autorisatie.scopes = self.autorisatie.scopes + [ SCOPE_DOCUMENTEN_GEFORCEERD_UNLOCK ] self.autorisatie.save() self._create_metadata() # unload 1 part of file part_file = split_file(self.file_content, settings.CHUNK_SIZE)[0] part = self.bestandsdelen[0] part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid) response = self.client.put( part_url, {"inhoud": part_file, "lock": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) # force unlock unlock_url = get_operation_url( "enkelvoudiginformatieobject_unlock", uuid=self.eio.uuid ) response = self.client.post(unlock_url) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.eio.refresh_from_db() self.canonical.refresh_from_db() self.assertEqual(self.eio.bestandsomvang, None) self.assertEqual(self.canonical.bestandsdelen.count(), 0)
def _upload_part_files(self): part_files = split_file(self.file_content, settings.CHUNK_SIZE) for part in self.bestandsdelen: part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid) response = self.client.put( part_url, {"inhoud": part_files.pop(0), "lock": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) part.refresh_from_db() self.assertNotEqual(part.inhoud, "") self.assertEqual(part.voltooid, True)
def test_update_metadata_after_unfinished_upload(self): """ Test the update process of the document metadata with some of part files uploaded Input: * updated fields don't include bestandsomvang and inhoud Expected result: * bestandsdelen objects are regenerated * all uploaded part files are lost """ self._create_metadata() # unload 1 part of file part_file = split_file(self.file_content, settings.CHUNK_SIZE)[0] part = self.bestandsdelen[0] part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid) response = self.client.put( part_url, {"inhoud": part_file, "lock": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) part.refresh_from_db() self.assertEqual(part.voltooid, True) # update metedata eio_url = get_operation_url( "enkelvoudiginformatieobject_read", uuid=self.eio.uuid ) response = self.client.patch( eio_url, {"beschrijving": "beschrijving2", "lock": self.canonical.lock} ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.canonical.refresh_from_db() part_new = self.canonical.bestandsdelen.order_by("volgnummer").first() self.assertEqual(self.canonical.bestandsdelen.count(), 2) self.assertEqual(self.canonical.empty_bestandsdelen, True) self.assertEqual(part_new.voltooid, False)
def test_unlock_not_finish_upload(self): """ Test the unlock of the document with not all part files uploaded Input: * bestandsomvang of the document > 0 * bestandsdelen objects are created, some of them are uploaded Expected result: * 400 status because the upload of part files is incomplete """ self._create_metadata() # unload 1 part of file part_file = split_file(self.file_content, settings.CHUNK_SIZE)[0] part = self.bestandsdelen[0] part_url = get_operation_url("bestandsdeel_update", uuid=part.uuid) response = self.client.put( part_url, {"inhoud": part_file, "lock": self.canonical.lock}, format="multipart", ) self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) # unlock unlock_url = get_operation_url( "enkelvoudiginformatieobject_unlock", uuid=self.eio.uuid ) response = self.client.post(unlock_url, {"lock": self.canonical.lock}) self.assertEqual( response.status_code, status.HTTP_400_BAD_REQUEST, response.data ) error = get_validation_errors(response, "nonFieldErrors") self.assertEqual(error["code"], "incomplete-upload")