From 36bb0222443d9798cafb8ccfcbf74756ffe361b7 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Wed, 13 May 2026 15:47:59 +0200 Subject: [PATCH 1/2] Add test for single file upload --- tests/integration/test_native_upload.py | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/integration/test_native_upload.py b/tests/integration/test_native_upload.py index 0127ced..e2cb885 100644 --- a/tests/integration/test_native_upload.py +++ b/tests/integration/test_native_upload.py @@ -590,6 +590,73 @@ def test_native_upload_with_large_file( dataverse_url=BASE_URL, n_parallel_uploads=1, ) + + def test_native_upload_single_file_with_path( + self, + credentials, + ): + + BASE_URL, API_TOKEN = credentials + + filename = "single_file.bin" + dv_path = "a/b/c" + categories = ["testfile", "with metadata"] + description = "This is a testfile with metadata" + + # Create Dataset + pid = create_dataset( + parent="Root", + server_url=BASE_URL, + api_token=API_TOKEN, + ) + + with tempfile.TemporaryDirectory() as directory: + os.makedirs(os.path.join(directory, dv_path)) + local_path = os.path.join(directory, dv_path, filename) + self._create_file(1024*2, local_path) + + files = [ + File( + filepath=local_path, + directoryLabel=dv_path, + categories=categories, + description=description, + ), + ] + + uploader = DVUploader(files=files) + uploader.upload( + persistent_id=pid, + api_token=API_TOKEN, + dataverse_url=BASE_URL, + n_parallel_uploads=1, + ) + + files = retrieve_dataset_files( + dataverse_url=BASE_URL, + persistent_id=pid, + api_token=API_TOKEN, + ) + + expected_files = [ + { + "label": filename, + "directoryLabel": dv_path, + "description": description, + "categories": categories, + } + ] + + files_as_expected = sorted( # pyright: ignore[reportCallIssue] + [ + {k: (f[k] if k in f else None) for k in expected_files[0].keys()} + for f in files + ], + key=lambda x: x["label"], # pyright: ignore[reportArgumentType] + ) + assert files_as_expected == expected_files, ( + f"File metadata not as expected: {json.dumps(files, indent=2)}" + ) def _create_file(self, size: int, path: str): with open(path, "wb") as f: From 879acc8f8fe4214f5a27031c2fd182b0b6743bc5 Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Wed, 13 May 2026 16:51:37 +0200 Subject: [PATCH 2/2] include directory_label into json_data --- dvuploader/nativeupload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dvuploader/nativeupload.py b/dvuploader/nativeupload.py index 65c7e2b..a052b71 100644 --- a/dvuploader/nativeupload.py +++ b/dvuploader/nativeupload.py @@ -396,6 +396,7 @@ def _get_json_data(file: File) -> Dict: "categories", "restrict", "tabIngest", + "directory_label" } return file.model_dump(by_alias=True, exclude_none=True, include=include)