@@ -405,26 +405,6 @@ def test_move_filepaths_to_upload_folder(self):
405
405
with open (join (html_fp2 , 'index.html' ), 'w' ) as fp :
406
406
fp .write (">AAA\n AAA" )
407
407
408
- # create an additional directory named 'more_files' and populate it
409
- # with two files that shouldn't be moved back into the uploads
410
- # directory when an artifact is deleted, and one that should.
411
- more_files_fp = mkdtemp ()
412
- more_files_fp = join (more_files_fp , 'more_files' )
413
- mkdir (more_files_fp )
414
- test_files = [(join (more_files_fp , x ), 1 ) for x in
415
- ['qtp-sequencing-validate-data.csv' ,
416
- 'feature-table.qza' ,
417
- 'good_file.txt' ]]
418
-
419
- # create the files
420
- for file_name , _ in test_files :
421
- with open (file_name , 'w' ) as fp :
422
- fp .write ("This is a test file.\n " )
423
-
424
- # verify that the files exist
425
- for file_name , _ in test_files :
426
- self .assertTrue (exists (file_name ))
427
-
428
408
# creating new prep info file
429
409
metadata_dict = {
430
410
'SKB8.640193' : {'center_name' : 'ANL' ,
@@ -444,35 +424,35 @@ def test_move_filepaths_to_upload_folder(self):
444
424
445
425
# inserting artifact 1
446
426
artifact1 = qdb .artifact .Artifact .create (
447
- [(seqs_fp1 , 1 ), (html_fp1 , 'html_summary' )] + test_files , "FASTQ" ,
427
+ [(seqs_fp1 , 1 ), (html_fp1 , 'html_summary' )], "FASTQ" ,
448
428
prep_template = pt1 )
429
+ filepaths = artifact1 .filepaths
449
430
# inserting artifact 2
450
431
artifact2 = qdb .artifact .Artifact .create (
451
432
[(seqs_fp2 , 1 ), (html_fp2 , 'html_summary' )], "FASTQ" ,
452
433
prep_template = pt2 )
453
-
454
- # retrieving filepaths
455
- filepaths = artifact1 .filepaths
456
434
filepaths .extend (artifact2 .filepaths )
457
435
436
+ # get before delete files in upload folders
437
+ GUPLOADS = qdb .util .get_files_from_uploads_folders
438
+ upload_files = set (GUPLOADS ("1" ))
439
+
458
440
# delete artifact 1
459
441
qdb .artifact .Artifact .delete (artifact1 .id )
460
442
461
- # now that artifact 1 is deleted, confirm that all three test files
462
- # are removed.
463
- for file_name , _ in test_files :
464
- self .assertFalse (exists (file_name ))
443
+ # confirm that _only_ the fastq from the file is recovered; this means
444
+ # that all the extra files/folders were ignored
445
+ diff_upload = set (GUPLOADS ("1" )) - set (upload_files )
446
+ self .assertEqual (len (diff_upload ), 1 )
447
+ self .assertEqual (diff_upload .pop ()[1 ], basename (seqs_fp1 ))
465
448
466
- # confirm that the 'bad_files' were not moved back into the uploads
467
- # directory, but the 'good_file.txt' was.
468
- uploads = qdb .util .get_files_from_uploads_folders ("1" )
469
- bad_files = [basename (x [0 ]) for x in test_files if
470
- 'good_file.txt' not in x [0 ]]
471
- for _ , some_path , _ in uploads :
472
- self .assertFalse (basename (some_path ) in bad_files )
473
-
474
- # finish deleting artifacts
449
+ # finish deleting artifacts :: there should be a new fastq
475
450
qdb .artifact .Artifact .delete (artifact2 .id )
451
+ diff_upload = set (GUPLOADS ("1" )) - set (upload_files )
452
+ self .assertEqual (len (diff_upload ), 2 )
453
+ self .assertCountEqual (
454
+ [x [1 ] for x in diff_upload ],
455
+ [basename (seqs_fp1 ), basename (seqs_fp2 )])
476
456
477
457
# now let's create another artifact with the same filenames that
478
458
# artifact1 so we can test successfull overlapping of names
@@ -484,32 +464,19 @@ def test_move_filepaths_to_upload_folder(self):
484
464
artifact3 = qdb .artifact .Artifact .create (
485
465
[(seqs_fp1 , 1 ), (html_fp1 , 'html_summary' )], "FASTQ" ,
486
466
prep_template = pt1 )
487
- filepaths .extend (artifact2 .filepaths )
467
+ filepaths .extend (artifact3 .filepaths )
488
468
qdb .artifact .Artifact .delete (artifact3 .id )
489
469
490
- # check that they do not exist in the old path but do in the new one
491
- path_for_removal = join (qdb .util .get_mountpoint ("uploads" )[0 ][1 ],
492
- str (study_id ))
493
- for x in filepaths :
494
- self .assertFalse (exists (x ['fp' ]))
495
-
496
- f_name = basename (x ['fp' ])
497
-
498
- if f_name in bad_files :
499
- # skip the check for file-names in bad_files,
500
- # because they were already checked above and they were
501
- # already deleted.
502
- continue
503
-
504
- new_fp = join (path_for_removal , f_name )
470
+ # files should be the same as the previous test
471
+ diff_upload = set (GUPLOADS ("1" )) - set (upload_files )
472
+ self .assertEqual (len (diff_upload ), 2 )
473
+ self .assertCountEqual (
474
+ [x [1 ] for x in diff_upload ],
475
+ [basename (seqs_fp1 ), basename (seqs_fp2 )])
505
476
506
- if x ['fp_type' ] == 'html_summary' :
507
- # The html summary gets removed, not moved
508
- self .assertFalse (exists (new_fp ))
509
- else :
510
- self .assertTrue (exists (new_fp ))
511
-
512
- self .files_to_remove .append (new_fp )
477
+ bd = qdb .util .get_mountpoint ("uploads" )[0 ][1 ]
478
+ for x in filepaths :
479
+ self .files_to_remove .append (join (bd , "1" , basename (x ['fp' ])))
513
480
514
481
def test_get_mountpoint (self ):
515
482
exp = [(5 , join (qdb .util .get_db_files_base_dir (), 'raw_data' ))]
0 commit comments