From 8d32097065e851a449403c655480c848f4d69813 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Thu, 18 Sep 2025 22:47:19 +0200 Subject: [PATCH 1/3] Refactor metadata handling Only include 'directoryLabel' in metadata if present, improving flexibility for file uploads. Also remove unnecessary print statement from error handling in _update_single_metadata. --- dvuploader/nativeupload.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dvuploader/nativeupload.py b/dvuploader/nativeupload.py index 7296c86..e9b4835 100644 --- a/dvuploader/nativeupload.py +++ b/dvuploader/nativeupload.py @@ -301,14 +301,19 @@ def _get_json_data(file: File) -> Dict: Returns: Dict: Dictionary containing file metadata for the upload request. """ - return { + + metadata = { "description": file.description, - "directoryLabel": file.directory_label, "categories": file.categories, "restrict": file.restrict, "forceReplace": True, } + if file.directory_label: + metadata["directoryLabel"] = file.directory_label + + return metadata + async def _update_metadata( session: httpx.AsyncClient, @@ -414,7 +419,6 @@ async def _update_single_metadata( if response.status_code == 200: return else: - print(response.json()) await asyncio.sleep(1.0) raise ValueError(f"Failed to update metadata for file {file.file_name}.") From 84ce9d3945d16492f7edd68cfd9df677fce02c42 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Thu, 18 Sep 2025 22:47:34 +0200 Subject: [PATCH 2/3] Improve assertion error messages in native upload test Enhanced the clarity of assertion error messages in TestNativeUpload by including expected values and pretty-printing file details for easier debugging. --- tests/integration/test_native_upload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_native_upload.py b/tests/integration/test_native_upload.py index ae80990..ebd7327 100644 --- a/tests/integration/test_native_upload.py +++ b/tests/integration/test_native_upload.py @@ -212,11 +212,11 @@ def test_native_upload_by_handler( file = next(file for file in files if file["label"] == ex_f) assert file["label"] == ex_f, ( - f"File label does not match for file {json.dumps(file)}" + f"File label {ex_f} does not match for file {json.dumps(file, indent=2)}" ) assert file.get("directoryLabel", "") == ex_dir, ( - f"Directory label does not match for file {json.dumps(file)}" + f"Directory label '{ex_dir}' of expected file '{ex_f}' does not match for file {json.dumps(file, indent=2)}" ) assert file["description"] == "This is a test", ( From 8c643c364d9a36730f3a711d50b860c3a67ccaae Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 19 Sep 2025 00:15:56 +0200 Subject: [PATCH 3/3] Update test URL in test_raise_http_error Changed the URL in test_raise_http_error from example.com to demo.dataverse.org to better reflect a realistic test scenario. --- tests/unit/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index bd386d9..45d8a1c 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -168,7 +168,7 @@ def test_return_files_list(self, httpx_mock): def test_raise_http_error(self): # Call the function under test and assert that it raises an HTTPError with pytest.raises(httpx.HTTPStatusError): - retrieve_dataset_files("http://example.com", "12345", "token") + retrieve_dataset_files("http://demo.dataverse.org", "12345", "token") class TestSetupPbar: