@@ -590,6 +590,73 @@ def test_native_upload_with_large_file(
590590 dataverse_url = BASE_URL ,
591591 n_parallel_uploads = 1 ,
592592 )
593+
594+ def test_native_upload_single_file_with_path (
595+ self ,
596+ credentials ,
597+ ):
598+
599+ BASE_URL , API_TOKEN = credentials
600+
601+ filename = "single_file.bin"
602+ dv_path = "a/b/c"
603+ categories = ["testfile" , "with metadata" ]
604+ description = "This is a testfile with metadata"
605+
606+ # Create Dataset
607+ pid = create_dataset (
608+ parent = "Root" ,
609+ server_url = BASE_URL ,
610+ api_token = API_TOKEN ,
611+ )
612+
613+ with tempfile .TemporaryDirectory () as directory :
614+ os .makedirs (os .path .join (directory , dv_path ))
615+ local_path = os .path .join (directory , dv_path , filename )
616+ self ._create_file (1024 * 2 , local_path )
617+
618+ files = [
619+ File (
620+ filepath = local_path ,
621+ directoryLabel = dv_path ,
622+ categories = categories ,
623+ description = description ,
624+ ),
625+ ]
626+
627+ uploader = DVUploader (files = files )
628+ uploader .upload (
629+ persistent_id = pid ,
630+ api_token = API_TOKEN ,
631+ dataverse_url = BASE_URL ,
632+ n_parallel_uploads = 1 ,
633+ )
634+
635+ files = retrieve_dataset_files (
636+ dataverse_url = BASE_URL ,
637+ persistent_id = pid ,
638+ api_token = API_TOKEN ,
639+ )
640+
641+ expected_files = [
642+ {
643+ "label" : filename ,
644+ "directoryLabel" : dv_path ,
645+ "description" : description ,
646+ "categories" : categories ,
647+ }
648+ ]
649+
650+ files_as_expected = sorted ( # pyright: ignore[reportCallIssue]
651+ [
652+ {k : (f [k ] if k in f else None ) for k in expected_files [0 ].keys ()}
653+ for f in files
654+ ],
655+ key = lambda x : x ["label" ], # pyright: ignore[reportArgumentType]
656+ )
657+ assert files_as_expected == expected_files , (
658+ f"File metadata not as expected: { json .dumps (files , indent = 2 )} "
659+ )
593660
594661 def _create_file (self , size : int , path : str ):
595662 with open (path , "wb" ) as f :
0 commit comments