|
| 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 | + |
| 9 | +from unittest import main |
| 10 | + |
| 11 | +from tornado.escape import json_decode |
| 12 | + |
| 13 | +from qiita_db.study import Study |
| 14 | +from qiita_pet.test.rest.test_base import RESTHandlerTestCase |
| 15 | + |
| 16 | + |
| 17 | +class StudyAssociationTests(RESTHandlerTestCase): |
| 18 | + def test_get_valid(self): |
| 19 | + IGNORE = IGNORE |
| 20 | + exp = {'study': 1, |
| 21 | + 'prep_templates': [{'prep_id': 1, |
| 22 | + 'prep_filepath': IGNORE, |
| 23 | + 'prep_datatype': '18S', |
| 24 | + 'prep_human_filtering': 'The greatest human filtering method', |
| 25 | + 'prep_artifacts': [{'artifact_id': 1, |
| 26 | + 'artifact_parent_ids': [1], |
| 27 | + 'artifact_basal_id': 1, |
| 28 | + 'artifact_processing_id': None, |
| 29 | + 'artifact_processing_name': None, |
| 30 | + 'artifact_processing_arguments': None, |
| 31 | + 'artifact_filepaths': [{'artifact_filepath_id': 1, |
| 32 | + 'artifact_filepath': IGNORE, |
| 33 | + 'artifact_filepath_type': 'raw_forward_seqs'}, |
| 34 | + {'artifact_filepath_id': 2, |
| 35 | + 'artifact_filepath': IGNORE, |
| 36 | + 'artifact_filepath_type': 'raw_barcodes'}]}, |
| 37 | + {'artifact_id': 2, |
| 38 | + 'artifact_parent_ids': None, |
| 39 | + 'artifact_basal_id': 1, |
| 40 | + 'artifact_processing_id': 1, |
| 41 | + 'artifact_processing_name': 'Split libraries FASTQ', |
| 42 | + 'artifact_processing_arguments': {'input_data': '1', |
| 43 | + 'max_bad_run_length': '3', |
| 44 | + 'min_per_read_length_fraction': '0.75', |
| 45 | + 'sequence_max_n': '0', |
| 46 | + 'rev_comp_barcode': 'False', |
| 47 | + 'rev_comp_mapping_barcodes': 'False', |
| 48 | + 'rev_comp': 'False', |
| 49 | + 'phred_quality_threshold': '3', |
| 50 | + 'barcode_type': 'golay_12', |
| 51 | + 'max_barcode_errors': '1.5', |
| 52 | + 'phred_offset': 'auto'}, |
| 53 | + 'artifact_filepaths': [{'artifact_filepath_id': 3, |
| 54 | + 'artifact_filepath': IGNORE, |
| 55 | + 'artifact_filepath_type': 'preprocessed_fasta'}, |
| 56 | + {'artifact_filepath': IGNORE, |
| 57 | + 'artifact_filepath_id': 4, |
| 58 | + 'artifact_filepath_type': 'preprocessed_fastq'}, |
| 59 | + {'artifact_filepath': IGNORE, |
| 60 | + 'artifact_filepath_id': 5, |
| 61 | + 'artifact_filepath_type': 'preprocessed_demux'}]}, |
| 62 | + {'artifact_id': 3, |
| 63 | + 'artifact_parent_ids': [1], |
| 64 | + 'artifact_basal_id': 1, |
| 65 | + 'artifact_processing_id': 1, |
| 66 | + 'artifact_processing_name': 'Split libraries FASTQ', |
| 67 | + 'artifact_processing_arguments': {'input_data': '1', |
| 68 | + 'max_bad_run_length': '3', |
| 69 | + 'min_per_read_length_fraction': '0.75', |
| 70 | + 'sequence_max_n': '0', |
| 71 | + 'rev_comp_barcode': 'False', |
| 72 | + 'rev_comp_mapping_barcodes': 'False', |
| 73 | + 'rev_comp': 'False', |
| 74 | + 'phred_quality_threshold': '3', |
| 75 | + 'barcode_type': 'golay_12', |
| 76 | + 'max_barcode_errors': '1.5', |
| 77 | + 'phred_offset': 'auto'}, |
| 78 | + 'artifact_filepaths': []}, |
| 79 | + {'artifact_id': 4, |
| 80 | + 'artifact_parent_ids': [2], |
| 81 | + 'artifact_basal_id': 1, |
| 82 | + 'artifact_processing_id': 3, |
| 83 | + 'artifact_processing_name': 'Pick closed-reference OTUs', |
| 84 | + 'artifact_processing_arguments': {'input_data': '2', |
| 85 | + 'reference': '1', |
| 86 | + 'sortmerna_e_value': '1', |
| 87 | + 'sortmerna_max_pos': '10000', |
| 88 | + 'similarity': '0.97', |
| 89 | + 'sortmerna_coverage': '0.97', |
| 90 | + 'threads': '1'}, |
| 91 | + 'artifact_filepaths': [{'artifact_filepath_id': 9, |
| 92 | + 'artifact_filepath': IGNORE, |
| 93 | + 'artifact_filepath_type': 'biom'}]}, |
| 94 | + {'artifact_id': 5, |
| 95 | + 'artifact_parent_ids': [2], |
| 96 | + 'artifact_basal_id': 1, |
| 97 | + 'artifact_processing_id': 3, |
| 98 | + 'artifact_processing_name': 'Pick closed-reference OTUs', |
| 99 | + 'artifact_processing_arguments': {'input_data': '2', |
| 100 | + 'reference': '1', |
| 101 | + 'sortmerna_e_value': '1', |
| 102 | + 'sortmerna_max_pos': '10000', |
| 103 | + 'similarity': '0.97', |
| 104 | + 'sortmerna_coverage': '0.97', |
| 105 | + 'threads': '1'}, |
| 106 | + 'artifact_filepaths': [{'artifact_filepath_id': 9, |
| 107 | + 'artifact_filepath': IGNORE, |
| 108 | + 'artifact_filepath_type': 'biom'}]}, |
| 109 | + {'artifact_id': 6, |
| 110 | + 'artifact_parent_ids': [2], |
| 111 | + 'artifact_basal_id': 1, |
| 112 | + 'artifact_processing_id': 3, |
| 113 | + 'artifact_processing_name': 'Pick closed-reference OTUs', |
| 114 | + 'artifact_processing_arguments': {'input_data': '2', |
| 115 | + 'reference': '2', |
| 116 | + 'sortmerna_e_value': '1', |
| 117 | + 'sortmerna_max_pos': '10000', |
| 118 | + 'similarity': '0.97', |
| 119 | + 'sortmerna_coverage': '0.97', |
| 120 | + 'threads': '1'}, |
| 121 | + 'artifact_filepaths': [{'artifact_filepath_id': 12, |
| 122 | + 'artifact_filepath': IGNORE, |
| 123 | + 'artifact_filepath_type': 'biom'}]}]}, |
| 124 | + {'prep_id': 2, |
| 125 | + 'prep_filepath': IGNORE, |
| 126 | + 'prep_datatype': '18S', |
| 127 | + 'prep_human_filtering': None, |
| 128 | + 'prep_artifacts': [{'artifact_id': 7, |
| 129 | + 'artifact_parent_ids': [], |
| 130 | + 'artifact_basal_id': 7, |
| 131 | + 'artifact_processing_id': None, |
| 132 | + 'artifact_processing_name': None, |
| 133 | + 'artifact_processing_arguments': None, |
| 134 | + 'artifact_filepaths': [{'artifact_filepath_id': 22, |
| 135 | + 'artifact_filepath': IGNORE, |
| 136 | + 'artifact_filepath_type': 'biom'}]}]}]} |
| 137 | + |
| 138 | + response = self.get('/api/v1/study-association/1', headers=self.headers) |
| 139 | + self.assertEqual(response.code, 200) |
| 140 | + obs = json_decode(response.body) |
| 141 | + self.assertEqual(obs, exp) |
| 142 | + |
| 143 | + def test_get_invalid(self): |
| 144 | + response = self.get('/api/v1/study-association/0', headers=self.headers) |
| 145 | + self.assertEqual(response.code, 404) |
| 146 | + self.assertEqual(json_decode(response.body), |
| 147 | + {'message': 'Study not found'}) |
| 148 | + |
| 149 | + |
| 150 | +if __name__ == '__main__': |
| 151 | + main() |
0 commit comments