1
1
from unittest import main
2
2
from collections import namedtuple
3
+ from json import loads
3
4
4
5
from qiita_pet .test .tornado_test_base import TestHandlerBase
5
6
from qiita_db .study import StudyPerson , Study
12
13
class TestHelpers (TestHandlerBase ):
13
14
database = True
14
15
15
- def test_get_shared_links_for_study (self ):
16
- obs = _get_shared_links_for_study (Study (1 ))
17
- exp = '<a target="_blank" href="mailto:shared@foo.bar">Shared</a>'
18
- self .assertEqual (obs , exp )
19
-
20
- def test_build_study_info (self ):
21
- Study (1 ).status = 'public'
22
- obs = _build_study_info ('public' , User ('test@foo.bar' ))
23
- StudyTuple = namedtuple ('StudyInfo' , 'id title meta_complete '
24
- 'num_samples_collected shared num_raw_data pi '
25
- 'pmids owner status, abstract' )
26
- exp = [
27
- StudyTuple (
16
+ def setUp (self ):
17
+ self .StudyTuple = namedtuple ('StudyInfo' , 'id title meta_complete '
18
+ 'num_samples_collected shared '
19
+ 'num_raw_data pi pmids owner status '
20
+ 'abstract' )
21
+ self .exp_studies = {
22
+ self .StudyTuple (
28
23
id = 1 ,
29
24
title = 'Identification of the Microbiomes for Cannabis Soils' ,
30
25
meta_complete = True , num_samples_collected = 27 ,
@@ -48,9 +43,19 @@ def test_build_study_info(self):
48
43
'These roots were obtained November 11, 2011 from plants that '
49
44
'had been harvested in the summer. Future studies will '
50
45
'attempt to analyze the soils and rhizospheres from the same '
51
- 'location at different time points in the plant lifecycle.' )]
46
+ 'location at different time points in the plant lifecycle.' )}
47
+ super (TestHelpers , self ).setUp ()
48
+
49
+ def test_get_shared_links_for_study (self ):
50
+ obs = _get_shared_links_for_study (Study (1 ))
51
+ exp = '<a target="_blank" href="mailto:shared@foo.bar">Shared</a>'
52
52
self .assertEqual (obs , exp )
53
53
54
+ def test_build_study_info (self ):
55
+ Study (1 ).status = 'public'
56
+ obs = _build_study_info ('standard' , User ('test@foo.bar' ))
57
+ self .assertItemsEqual (obs , self .exp_studies )
58
+
54
59
def test_build_study_info_new_study (self ):
55
60
info = {
56
61
'timeseries_type_id' : 1 ,
@@ -62,30 +67,20 @@ def test_build_study_info_new_study(self):
62
67
'study_description' : 'desc' ,
63
68
'study_alias' : 'alias' ,
64
69
'study_abstract' : 'abstract' }
65
- user = User ('shared @foo.bar' )
70
+ user = User ('test @foo.bar' )
66
71
67
72
Study .create (user , 'test_study_1' , efo = [1 ], info = info )
68
73
69
- obs = _build_study_info ('private' , user )
70
-
71
- StudyTuple = namedtuple ('StudyInfo' , 'id title meta_complete '
72
- 'num_samples_collected shared num_raw_data pi '
73
- 'pmids owner status, abstract' )
74
- exp = [
75
- StudyTuple (
76
- id = 2 ,
77
- title = 'test_study_1' ,
78
- meta_complete = False , num_samples_collected = None ,
79
- shared = '' ,
80
- num_raw_data = 0 ,
74
+ obs = _build_study_info ('standard' , user )
75
+ self .exp_studies .add (
76
+ self .StudyTuple (
77
+ id = 2 , title = 'test_study_1' , meta_complete = False ,
78
+ num_samples_collected = None , shared = '' , num_raw_data = 0 ,
81
79
pi = '<a target="_blank" href="mailto:PI_dude@foo.bar">'
82
- 'PIDude</a>' ,
83
- pmids = '' ,
84
- owner = '<a target="_blank" href="mailto:shared@foo.bar">'
85
- 'shared@foo.bar</a>' ,
86
- status = 'sandbox' ,
87
- abstract = 'abstract' )]
88
- self .assertEqual (obs , exp )
80
+ 'PIDude</a>' , pmids = '' , owner = '<a target="_blank" '
81
+ 'href="mailto:test@foo.bar">test@foo.bar</a>' ,
82
+ status = 'sandbox' , abstract = 'abstract' ))
83
+ self .assertItemsEqual (obs , self .exp_studies )
89
84
90
85
91
86
class TestStudyEditorForm (TestHandlerBase ):
@@ -98,15 +93,9 @@ class TestStudyEditorExtendedForm(TestHandlerBase):
98
93
pass
99
94
100
95
101
- class TestPrivateStudiesHandler (TestHandlerBase ):
96
+ class TestListStudiesHandler (TestHandlerBase ):
102
97
def test_get (self ):
103
- response = self .get ('/study/private/' )
104
- self .assertEqual (response .code , 200 )
105
-
106
-
107
- class TestPublicStudiesHandler (TestHandlerBase ):
108
- def test_get (self ):
109
- response = self .get ('/study/public/' )
98
+ response = self .get ('/study/list/' )
110
99
self .assertEqual (response .code , 200 )
111
100
112
101
@@ -274,6 +263,87 @@ def test_get(self):
274
263
self .assertEqual (response .body , 'False' )
275
264
276
265
266
+ class TestSearchStudiesAJAX (TestHandlerBase ):
267
+ database = False
268
+
269
+ json = {
270
+ 'iTotalRecords' : 1 ,
271
+ 'aaData' : [[
272
+ "<input type='checkbox' value='1'>" ,
273
+ '<a href=\' #\' \' data-toggle=\' modal\' data-target=\' #study-'
274
+ 'abstract-modal\' onclick=\' fillAbstract("user-studies-table", 0)'
275
+ '\' ><span class=\' glyphicon glyphicon-file\' aria-hidden=\' true\' '
276
+ '></span></a> | <a href=\' /study/description/1\' id=\' study0-title'
277
+ '\' >Identification of the Microbiomes for Cannabis Soils</a>' ,
278
+ 'This is a preliminary study to examine the microbiota associated '
279
+ 'with the Cannabis plant. Soils samples from the bulk soil, soil '
280
+ 'associated with the roots, and the rhizosphere were extracted and'
281
+ ' the DNA sequenced. Roots from three independent plants of '
282
+ 'different strains were examined. These roots were obtained '
283
+ 'November 11, 2011 from plants that had been harvested in the '
284
+ 'summer. Future studies will attempt to analyze the soils and '
285
+ 'rhizospheres from the same location at different time points in '
286
+ 'the plant lifecycle.' , 1 ,
287
+ "<span class='glyphicon glyphicon-ok'></span>" , 27 , 4 ,
288
+ '<span id=\' shared_html_1\' ><a target="_blank" href="mailto:shared'
289
+ '@foo.bar">Shared</a></span><br/><a class=\' btn btn-primary\' '
290
+ 'data-toggle=\' modal\' data-target=\' #share-study-modal-view\' '
291
+ 'onclick=\' modify_sharing(1);\' >Modify</a>' ,
292
+ '<a target="_blank" href="mailto:PI_dude@foo.bar">PIDude</a>' ,
293
+ '<a target="_blank" href="http://www.ncbi.nlm.nih.gov/pubmed/'
294
+ '123456">123456</a>, <a target="_blank" href="http://www.ncbi.nlm.'
295
+ 'nih.gov/pubmed/7891011">7891011</a>' , 'private' ]],
296
+ 'sEcho' : 1021 , 'iTotalDisplayRecords' : 1 }
297
+
298
+ empty = {'aaData' : [],
299
+ 'iTotalDisplayRecords' : 0 ,
300
+ 'iTotalRecords' : 0 ,
301
+ 'sEcho' : 1021 }
302
+
303
+ def test_get (self ):
304
+ response = self .get ('/study/search/' , {
305
+ 'type' : 'standard' ,
306
+ 'user' : 'test@foo.bar' ,
307
+ 'query' : '' ,
308
+ 'sEcho' : '1021'
309
+ })
310
+ self .assertEqual (response .code , 200 )
311
+ # make sure responds properly
312
+ self .assertEqual (loads (response .body ), self .json )
313
+
314
+ response = self .get ('/study/search/' , {
315
+ 'type' : 'shared' ,
316
+ 'user' : 'test@foo.bar' ,
317
+ 'query' : '' ,
318
+ 'sEcho' : '1021'
319
+ })
320
+ self .assertEqual (response .code , 200 )
321
+ # make sure responds properly
322
+ self .assertEqual (loads (response .body ), self .empty )
323
+
324
+ response = self .get ('/study/search/' , {
325
+ 'type' : 'standard' ,
326
+ 'user' : 'test@foo.bar' ,
327
+ 'query' : 'ph > 50' ,
328
+ 'sEcho' : '1021'
329
+ })
330
+ self .assertEqual (response .code , 200 )
331
+ # make sure responds properly
332
+ self .assertEqual (loads (response .body ), self .empty )
333
+
334
+ def test_get_failure (self ):
335
+ response = self .get ('/study/search/' , {
336
+ 'type' : 'standard' ,
337
+ 'user' : 'test@foo.bar' ,
338
+ 'query' : 'ph' ,
339
+ 'sEcho' : '1021'
340
+ })
341
+ self .assertEqual (response .code , 400 )
342
+ # make sure responds properly
343
+ self .assertEqual (response .body , 'Malformed search query. '
344
+ 'Please read "search help" and try again.' )
345
+
346
+
277
347
class TestMetadataSummaryHandler (TestHandlerBase ):
278
348
def test_error_prep_and_sample (self ):
279
349
response = self .get ('/metadata_summary/' , {'sample_template' : 1 ,
0 commit comments