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}.") 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", ( 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: