@@ -163,7 +163,7 @@ def test_put_and_get_objects(self):
163163 destination .cleanup ()
164164 client .delete_bucket_spectra_s3 (ds3 .DeleteBucketSpectraS3Request (bucket_name = bucket , force = True ))
165165
166- def test_put_and_get_all_objects_in_directory (self ):
166+ def test_put_and_get_all_objects_in_directory (self , prefix_dir : str = "" ):
167167 bucket = f'ds3-python3-sdk-test-{ uuid .uuid1 ()} '
168168 job_name = "python test job"
169169
@@ -201,15 +201,20 @@ def test_put_and_get_all_objects_in_directory(self):
201201
202202 # retrieve the objects from the BP
203203 destination = tempfile .TemporaryDirectory (prefix = "ds3-python3-sdk-dst-" )
204+
205+ # retrieve the objects in prefix directory
206+ prefixed_objects = [p for p in put_objects if p .object_name .startswith (prefix_dir )]
207+
204208 job_ids = helpers .get_all_files_in_bucket (destination_dir = destination .name ,
205209 bucket = bucket ,
206- objects_per_bp_job = 10 ,
207- job_name = job_name )
210+ objects_per_bp_job = 10 , job_name = job_name ,
211+ prefix = prefix_dir )
208212
209- self .assertGreaterEqual (len (job_ids ), 2 , "multiple job ids returned" )
213+ if len (prefix_dir ) == 0 :
214+ self .assertGreaterEqual (len (job_ids ), 2 , "multiple job ids returned" )
210215
211- # verify all the files and directories were retrieved
212- for put_object in put_objects :
216+ # verify all the files in prefix were returned
217+ for put_object in prefixed_objects :
213218 obj_destination = os .path .join (destination .name ,
214219 ds3Helpers .object_name_to_file_path (put_object .object_name ))
215220 if put_object .object_name .endswith ('/' ):
@@ -228,6 +233,12 @@ def test_put_and_get_all_objects_in_directory(self):
228233 destination .cleanup ()
229234 client .delete_bucket_spectra_s3 (ds3 .DeleteBucketSpectraS3Request (bucket_name = bucket , force = True ))
230235
236+ def test_put_and_get_all_objects_in_directory_with_prefix (self ):
237+ self .test_put_and_get_all_objects_in_directory (prefix_dir = "dir-0/sub-dir-1/" )
238+
239+ def test_put_and_get_all_objects_in_directory_with_bad_prefix (self ):
240+ self .test_put_and_get_all_objects_in_directory (prefix_dir = "not/gonna/match/" )
241+
231242 def test_put_all_objects_in_directory_with_md5_checksum (self ):
232243 self .put_all_objects_in_directory_with_checksum (checksum_type = 'MD5' )
233244
0 commit comments