Skip to content

Commit a76deec

Browse files
committed
Fixing util tests
1 parent ddb26d5 commit a76deec

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

qiita_db/test/test_util.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
from os.path import join, exists, basename
1313
from shutil import rmtree
1414

15+
import pandas as pd
16+
1517
from qiita_core.util import qiita_test_checker
1618
from qiita_core.exceptions import IncompetentQiitaDeveloperError
1719
from qiita_db.exceptions import QiitaDBColumnError, QiitaDBError
1820
from qiita_db.data import RawData
1921
from qiita_db.study import Study
2022
from qiita_db.reference import Reference
23+
from qiita_db.metadata_template import PrepTemplate
2124
from qiita_db.util import (exists_table, exists_dynamic_table, scrub_data,
2225
compute_checksum, check_table_cols,
2326
check_required_columns, convert_to_id,
@@ -367,6 +370,18 @@ def _common_purge_filpeaths_test(self):
367370
join(raw_data_mp, '2_sequences_barcodes.fastq.gz'),
368371
join(raw_data_mp, '2_sequences.fastq.gz')]
369372

373+
for fp in removed_fps:
374+
with open(fp, 'w') as f:
375+
f.write('\n')
376+
377+
sql = """INSERT INTO qiita.filepath
378+
(filepath, filepath_type_id, checksum,
379+
checksum_algorithm_id, data_directory_id)
380+
VALUES ('2_sequences_barcodes.fastq.gz', 3, '852952723', 1, 5),
381+
('2_sequences.fastq.gz', 1, '852952723', 1, 5)
382+
RETURNING filepath_id"""
383+
fp_ids = self.conn_handler.execute_fetchall(sql)
384+
370385
fps = set(fps).difference(removed_fps)
371386

372387
# Check that the files exist
@@ -387,9 +402,9 @@ def _common_purge_filpeaths_test(self):
387402
# Check that the 2 rows that have been removed are the correct ones
388403
sql = """SELECT EXISTS(
389404
SELECT * FROM qiita.filepath WHERE filepath_id = %s)"""
390-
obs = self.conn_handler.execute_fetchone(sql, (3,))[0]
405+
obs = self.conn_handler.execute_fetchone(sql, (fp_ids[0][0],))[0]
391406
self.assertFalse(obs)
392-
obs = self.conn_handler.execute_fetchone(sql, (4,))[0]
407+
obs = self.conn_handler.execute_fetchone(sql, (fp_ids[1][0],))[0]
393408
self.assertFalse(obs)
394409

395410
# Check that the files have been successfully removed
@@ -421,9 +436,19 @@ def test_move_filepaths_to_upload_folder(self):
421436
# files
422437
fd, seqs_fp = mkstemp(suffix='_seqs.fastq')
423438
close(fd)
424-
study_id = 1
425-
426-
rd = RawData.create(2, [Study(study_id)], [(seqs_fp, 1)])
439+
st = Study(1)
440+
metadata_dict = {
441+
'SKB8.640193': {'center_name': 'ANL',
442+
'primer': 'GTGCCAGCMGCCGCGGTAA',
443+
'barcode': 'GTCCGCAAGTTA',
444+
'run_prefix': "s_G1_L001_sequences",
445+
'platform': 'ILLUMINA',
446+
'library_construction_protocol': 'AAAA',
447+
'experiment_design_description': 'BBBB'}}
448+
metadata = pd.DataFrame.from_dict(metadata_dict, orient='index')
449+
pt = PrepTemplate.create(metadata, Study(1), "16S")
450+
451+
rd = RawData.create(2, [pt], [(seqs_fp, 1)])
427452
filepaths = rd.get_filepaths()
428453
# deleting reference so we can directly call
429454
# move_filepaths_to_upload_folder
@@ -432,10 +457,10 @@ def test_move_filepaths_to_upload_folder(self):
432457
"DELETE FROM qiita.raw_filepath WHERE filepath_id=%s", (fid,))
433458

434459
# moving filepaths
435-
move_filepaths_to_upload_folder(study_id, filepaths)
460+
move_filepaths_to_upload_folder(st.id, filepaths)
436461

437462
# check that they do not exist in the old path but do in the new one
438-
path_for_removal = join(get_mountpoint("uploads")[0][1], str(study_id))
463+
path_for_removal = join(get_mountpoint("uploads")[0][1], str(st.id))
439464
for _, fp, _ in filepaths:
440465
self.assertFalse(exists(fp))
441466
new_fp = join(path_for_removal, basename(fp).split('_', 1)[1])
@@ -615,21 +640,21 @@ def test_filepath_id_to_rel_path(self):
615640
exp = 'raw_data/1_s_G1_L001_sequences.fastq.gz'
616641
self.assertEqual(obs, exp)
617642

618-
obs = filepath_id_to_rel_path(5)
643+
obs = filepath_id_to_rel_path(3)
619644
exp = 'preprocessed_data/1_seqs.fna'
620645
self.assertEqual(obs, exp)
621646

622647
def test_filepath_ids_to_rel_paths(self):
623648
obs = filepath_ids_to_rel_paths([1, 3])
624649
exp = {1: 'raw_data/1_s_G1_L001_sequences.fastq.gz',
625-
3: 'raw_data/2_sequences.fastq.gz'}
650+
3: 'preprocessed_data/1_seqs.fna'}
626651

627652
self.assertEqual(obs, exp)
628653

629654
def test_check_access_to_analysis_result(self):
630655
obs = check_access_to_analysis_result('test@foo.bar',
631656
'1_job_result.txt')
632-
exp = [12]
657+
exp = [10]
633658

634659
self.assertEqual(obs, exp)
635660

0 commit comments

Comments
 (0)