|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Copyright (c) 2014--, The Qiita Development Team. |
| 3 | +# |
| 4 | +# Distributed under the terms of the BSD 3-clause License. |
| 5 | +# |
| 6 | +# The full license is in the file LICENSE, distributed with this software. |
| 7 | +# ----------------------------------------------------------------------------- |
| 8 | + |
1 | 9 | from os import remove, close
|
2 |
| -from os.path import exists, abspath, join, basename |
| 10 | +from os.path import exists, join, basename |
3 | 11 | from tempfile import mkstemp
|
4 | 12 | from unittest import TestCase, main
|
5 | 13 | from future.utils.six import StringIO
|
|
10 | 18 | # Python 3
|
11 | 19 | from configparser import NoOptionError
|
12 | 20 |
|
13 |
| -from qiita_db.commands import make_study_from_cmd, load_raw_data_cmd |
14 |
| -from qiita_db.study import StudyPerson |
| 21 | +from qiita_db.commands import (make_study_from_cmd, load_raw_data_cmd, |
| 22 | + sample_template_adder) |
| 23 | +from qiita_db.study import Study, StudyPerson |
15 | 24 | from qiita_db.user import User
|
16 | 25 | from qiita_db.util import get_count, check_count, get_db_files_base_dir
|
17 | 26 | from qiita_core.util import qiita_test_checker
|
@@ -40,6 +49,37 @@ def test_make_study_from_cmd(self):
|
40 | 49 | make_study_from_cmd('test@test.com', 'newstudy2', fh2)
|
41 | 50 |
|
42 | 51 |
|
| 52 | +@qiita_test_checker() |
| 53 | +class SampleTemplateAdderTests(TestCase): |
| 54 | + def setUp(self): |
| 55 | + # Create a sample template file |
| 56 | + self.st_contents = SAMPLE_TEMPLATE |
| 57 | + |
| 58 | + # create a new study to attach the sample template |
| 59 | + info = { |
| 60 | + "timeseries_type_id": 1, |
| 61 | + "metadata_complete": True, |
| 62 | + "mixs_compliant": True, |
| 63 | + "number_samples_collected": 4, |
| 64 | + "number_samples_promised": 4, |
| 65 | + "portal_type_id": 3, |
| 66 | + "study_alias": "TestStudy", |
| 67 | + "study_description": "Description of a test study", |
| 68 | + "study_abstract": "No abstract right now...", |
| 69 | + "emp_person_id": StudyPerson(2), |
| 70 | + "principal_investigator_id": StudyPerson(3), |
| 71 | + "lab_person_id": StudyPerson(1) |
| 72 | + } |
| 73 | + self.study = Study.create(User('test@foo.bar'), |
| 74 | + "Test study", [1], info) |
| 75 | + |
| 76 | + def test_sample_template_adder(self): |
| 77 | + """Correctly adds a sample template to the DB""" |
| 78 | + fh = StringIO(self.st_contents) |
| 79 | + st = sample_template_adder(fh, self.study.id) |
| 80 | + self.assertEqual(st.id, self.study.id) |
| 81 | + |
| 82 | + |
43 | 83 | @qiita_test_checker()
|
44 | 84 | class TestLoadRawDataFromCmd(TestCase):
|
45 | 85 | def setUp(self):
|
@@ -79,7 +119,6 @@ def test_load_data_from_cmd(self):
|
79 | 119 | initial_raw_count = get_count('qiita.raw_data')
|
80 | 120 | initial_fp_count = get_count('qiita.filepath')
|
81 | 121 | initial_raw_fp_count = get_count('qiita.raw_filepath')
|
82 |
| - initial_study_raw_data_count = get_count('qiita.study_raw_data') |
83 | 122 |
|
84 | 123 | new = load_raw_data_cmd(filepaths, filepath_types, filetype,
|
85 | 124 | study_ids)
|
@@ -146,5 +185,18 @@ def test_load_data_from_cmd(self):
|
146 | 185 | vamps_id = vamps_id
|
147 | 186 | """
|
148 | 187 |
|
| 188 | +SAMPLE_TEMPLATE = ( |
| 189 | + "#SampleID\trequired_sample_info_status_id\tcollection_timestamp\t" |
| 190 | + "sample_type\thas_physical_specimen\tphysical_location\thas_extracted_data" |
| 191 | + "\thost_subject_id\tTreatment\tDOB\tDescription\n" |
| 192 | + "PC.354\t1\t2014-06-18 16:44\ttype_1\tTrue\tLocation_1\tTrue\tHS_ID_PC.354" |
| 193 | + "\tControl\t20061218\tControl_mouse_I.D._354\n" |
| 194 | + "PC.593\t1\t2014-06-18 16:44\ttype_1\tTrue\tLocation_1\tTrue\tHS_ID_PC.593" |
| 195 | + "\tControl\t20071210\tControl_mouse_I.D._593\n" |
| 196 | + "PC.607\t1\t2014-06-18 16:44\ttype_1\tTrue\tLocation_1\tTrue\tHS_ID_PC.607" |
| 197 | + "\tFast\t20071112\tFasting_mouse_I.D._607\n" |
| 198 | + "PC.636\t1\t2014-06-18 16:44\ttype_1\tTrue\tLocation_1\tTrue\tHS_ID_PC.636" |
| 199 | + "\tFast\t20080116\tFasting_mouse_I.D._636") |
| 200 | + |
149 | 201 | if __name__ == "__main__":
|
150 | 202 | main()
|
0 commit comments