Skip to content

Commit 8e3f68d

Browse files
Merge pull request #3298 from antgonza/fix-3222-fp_type
fix 3222 via fp_type
2 parents a4b6fcb + 83dbc5f commit 8e3f68d

File tree

2 files changed

+32
-65
lines changed

2 files changed

+32
-65
lines changed

qiita_db/test/test_util.py

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -405,26 +405,6 @@ def test_move_filepaths_to_upload_folder(self):
405405
with open(join(html_fp2, 'index.html'), 'w') as fp:
406406
fp.write(">AAA\nAAA")
407407

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-
428408
# creating new prep info file
429409
metadata_dict = {
430410
'SKB8.640193': {'center_name': 'ANL',
@@ -444,35 +424,35 @@ def test_move_filepaths_to_upload_folder(self):
444424

445425
# inserting artifact 1
446426
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",
448428
prep_template=pt1)
429+
filepaths = artifact1.filepaths
449430
# inserting artifact 2
450431
artifact2 = qdb.artifact.Artifact.create(
451432
[(seqs_fp2, 1), (html_fp2, 'html_summary')], "FASTQ",
452433
prep_template=pt2)
453-
454-
# retrieving filepaths
455-
filepaths = artifact1.filepaths
456434
filepaths.extend(artifact2.filepaths)
457435

436+
# get before delete files in upload folders
437+
GUPLOADS = qdb.util.get_files_from_uploads_folders
438+
upload_files = set(GUPLOADS("1"))
439+
458440
# delete artifact 1
459441
qdb.artifact.Artifact.delete(artifact1.id)
460442

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))
465448

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
475450
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)])
476456

477457
# now let's create another artifact with the same filenames that
478458
# artifact1 so we can test successfull overlapping of names
@@ -484,32 +464,19 @@ def test_move_filepaths_to_upload_folder(self):
484464
artifact3 = qdb.artifact.Artifact.create(
485465
[(seqs_fp1, 1), (html_fp1, 'html_summary')], "FASTQ",
486466
prep_template=pt1)
487-
filepaths.extend(artifact2.filepaths)
467+
filepaths.extend(artifact3.filepaths)
488468
qdb.artifact.Artifact.delete(artifact3.id)
489469

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)])
505476

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'])))
513480

514481
def test_get_mountpoint(self):
515482
exp = [(5, join(qdb.util.get_db_files_base_dir(), 'raw_data'))]

qiita_db/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,17 +958,17 @@ def move_filepaths_to_upload_folder(study_id, filepaths):
958958

959959
path_builder = partial(join, uploads_fp)
960960

961-
# do not move these files back to upload folder.
962-
do_not_move = ['qtp-sequencing-validate-data.csv', 'feature-table.qza']
961+
# do not move these files-types back to upload folder.
962+
do_not_move = ['preprocessed_fasta', 'preprocessed_fastq',
963+
'preprocessed_demux', 'directory', 'log',
964+
'html_summary', 'tgz', 'html_summary_dir', 'qzv', 'qza']
963965

964966
# We can now go over and remove all the filepaths
965967
sql = """DELETE FROM qiita.filepath WHERE filepath_id = %s"""
966968
for x in filepaths:
967969
qdb.sql_connection.TRN.add(sql, [x['fp_id']])
968970

969-
if (x['fp_type'] in ('html_summary',
970-
'html_summary_dir') or
971-
basename(x['fp']) in do_not_move):
971+
if x['fp_type'] in do_not_move:
972972
_rm_files(qdb.sql_connection.TRN, x['fp'])
973973
continue
974974

0 commit comments

Comments
 (0)