[879b32]: / qiita_pet / test / test_qiita_redbiom.py

Download this file

159 lines (139 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from unittest import main
from copy import deepcopy
from json import loads
from qiita_pet.test.tornado_test_base import TestHandlerBase
class TestRedbiom(TestHandlerBase):
def test_get(self):
response = self.get('/redbiom/')
self.assertEqual(response.code, 200)
def test_post_metadata(self):
post_args = {
'search': 'Diesel',
'search_on': 'metadata'
}
response = self.post('/redbiom/', post_args)
self.assertEqual(response.code, 200)
exp_artifact_biom_ids = {
'5': ['1.SKD2.640178'],
'4': sorted(['1.SKD2.640178', '1.SKD8.640184'])}
response_body = loads(response.body)
obs_artifact_biom_ids = response_body['data'][0].pop(
'artifact_biom_ids')
# making sure they are in the same order
obs_artifact_biom_ids['4'] = sorted(obs_artifact_biom_ids['4'])
self.assertDictEqual(obs_artifact_biom_ids, exp_artifact_biom_ids)
exp = {'status': 'success', 'message': '', 'data': DATA}
self.assertEqual(response_body, exp)
post_args = {
'search': 'inf',
'search_on': 'metadata'
}
response = self.post('/redbiom/', post_args)
self.assertEqual(response.code, 200)
exp = {'status': 'success',
'message': 'No samples were found! Try again ...', 'data': []}
self.assertEqual(loads(response.body), exp)
post_args = {
'search': '4353076',
'search_on': 'metadata'
}
response = self.post('/redbiom/', post_args)
self.assertEqual(response.code, 200)
exp = {'status': 'success',
'message': ('The query ("4353076") did not work and may be '
'malformed. Please check the search help for more '
'information on the queries.'), 'data': []}
self.assertEqual(loads(response.body), exp)
def test_post_features(self):
post_args = {
'search': '4479944',
'search_on': 'feature'
}
response = self.post('/redbiom/', post_args)
data = deepcopy(DATA)
data[0]['artifact_biom_ids'] = {
'5': ['1.SKM3.640197'], '4': ['1.SKM3.640197']}
exp = {'status': 'success', 'message': '', 'data': data}
self.assertEqual(response.code, 200)
self.assertEqual(loads(response.body), exp)
post_args = {
'search': 'TT',
'search_on': 'feature'
}
response = self.post('/redbiom/', post_args)
exp = {'status': 'success',
'message': 'No samples were found! Try again ...', 'data': []}
self.assertEqual(response.code, 200)
self.assertEqual(loads(response.body), exp)
def test_post_taxon(self):
post_args = {
'search': 'o__0319-7L14',
'search_on': 'taxon'
}
data = deepcopy(DATA)
data[0]['artifact_biom_ids'] = {
'5': sorted(['1.SKD2.640178', '1.SKM3.640197']),
'4': sorted(['1.SKM3.640197', '1.SKD2.640178'])}
response = self.post('/redbiom/', post_args)
exp = {'status': 'success', 'message': '', 'data': data}
# making sure they are in the same order
obs = loads(response.body)
obs['data'][0]['artifact_biom_ids'] = {
'4': sorted(obs['data'][0]['artifact_biom_ids']['4']),
'5': sorted(obs['data'][0]['artifact_biom_ids']['5'])}
self.assertEqual(response.code, 200)
self.assertEqual(obs, exp)
post_args = {
'search': 'o_0319-7L14',
'search_on': 'taxon'
}
response = self.post('/redbiom/', post_args)
exp = {'status': 'success',
'message': 'No samples were found! Try again ...', 'data': []}
self.assertEqual(response.code, 200)
self.assertEqual(loads(response.body), exp)
def test_post_errors(self):
post_args = {
'search_on': 'metadata'
}
response = self.post('/redbiom/', post_args)
self.assertEqual(response.code, 400)
post_args = {
'search': 'infant',
'search_on': 'error'
}
response = self.post('/redbiom/', post_args)
self.assertEqual(response.code, 200)
exp = {'status': 'success',
'message': ('Incorrect search by: you can use metadata, '
'features or taxon and you passed: error'),
'data': []}
self.assertEqual(loads(response.body), exp)
DATA = [
{'study_title': 'Identification of the Microbiomes for Cannabis Soils',
'metadata_complete': True, 'publication_pid': ['123456', '7891011'],
'autoloaded': False,
'study_id': 1, 'ebi_study_accession': 'EBI123456-BB',
'study_abstract': ('This is a preliminary study to examine the '
'microbiota associated with the Cannabis plant. Soils '
'samples from the bulk soil, soil associated with the '
'roots, and the rhizosphere were extracted and the '
'DNA sequenced. Roots from three independent plants '
'of different strains were examined. These roots were '
'obtained November 11, 2011 from plants that had been '
'harvested in the summer. Future studies will attempt '
'to analyze the soils and rhizospheres from the same '
'location at different time points in the plant '
'lifecycle.'),
'pi': ['PI_dude@foo.bar', 'PIDude'],
'publication_doi': ['10.100/123456', '10.100/7891011'],
'study_alias': 'Cannabis Soils', 'number_samples_collected': 27}]
if __name__ == "__main__":
main()