66# The full license is in the file LICENSE, distributed with this software. 
77# ----------------------------------------------------------------------------- 
88from  unittest  import  TestCase , main 
9+ from  datetime  import  datetime 
10+ from  os .path  import  join 
911
10- from  qiita_pet .handlers .api_proxy .artifact  import  artifact_graph_get_req 
12+ from  qiita_core .util  import  qiita_test_checker 
13+ from  qiita_core .qiita_settings  import  qiita_config 
14+ from  qiita_db .artifact  import  Artifact 
15+ from  qiita_db .exceptions  import  QiitaDBUnknownIDError 
16+ from  qiita_pet .handlers .api_proxy .artifact  import  (
17+     artifact_get_req , artifact_status_put_req , artifact_graph_get_req ,
18+     artifact_delete_req )
1119
1220
21+ @qiita_test_checker () 
1322class  TestArtifactAPI (TestCase ):
23+     def  tearDown (self ):
24+         Artifact (1 ).visibility  =  'private' 
25+ 
26+     def  test_artifact_get_req (self ):
27+         obs  =  artifact_get_req (1 , 'test@foo.bar' )
28+         exp  =  {'is_submitted_to_vamps' : False ,
29+                'data_type' : '18S' ,
30+                'can_be_submitted_to_vamps' : False ,
31+                'can_be_submitted_to_ebi' : False ,
32+                'timestamp' : datetime (2012 , 10 , 1 , 9 , 30 , 27 ),
33+                'prep_templates' : [1 ],
34+                'visibility' : 'private' ,
35+                'study' : 1 ,
36+                'processing_parameters' : None ,
37+                'ebi_run_accessions' : None ,
38+                'parents' : [],
39+                'filepaths' : [
40+                    (1 , join (qiita_config .base_data_dir ,
41+                             'raw_data/1_s_G1_L001_sequences.fastq.gz' ),
42+                     'raw_forward_seqs' ),
43+                    (2 , join (qiita_config .base_data_dir ,
44+                             'raw_data/1_s_G1_L001_sequences_barcodes.' 
45+                             'fastq.gz' ),
46+                     'raw_barcodes' )],
47+                'artifact_type' : 'FASTQ' }
48+         self .assertEqual (obs , exp )
49+ 
50+     def  test_artifact_get_req_no_access (self ):
51+         obs  =  artifact_get_req (1 , 'demo@microbio.me' )
52+         exp  =  {'status' : 'error' ,
53+                'message' : 'User does not have access to study' }
54+         self .assertEqual (obs , exp )
55+ 
56+     def  test_artifact_delete_req (self ):
57+         obs  =  artifact_delete_req (3 , 'test@foo.bar' )
58+         exp  =  {'status' : 'success' , 'message' : '' }
59+         self .assertEqual (obs , exp )
60+ 
61+         with  self .assertRaises (QiitaDBUnknownIDError ):
62+             Artifact (3 )
63+ 
64+     def  test_artifact_delete_req_error (self ):
65+         obs  =  artifact_delete_req (1 , 'test@foo.bar' )
66+         exp  =  {'status' : 'error' ,
67+                'message' : 'Cannot delete artifact 1: it has children: 2, 3' }
68+         self .assertEqual (obs , exp )
69+ 
70+     def  test_artifact_delete_req_no_access (self ):
71+         obs  =  artifact_delete_req (3 , 'demo@microbio.me' )
72+         exp  =  {'status' : 'error' ,
73+                'message' : 'User does not have access to study' }
74+         self .assertEqual (obs , exp )
75+ 
76+     def  test_artifact_status_put_req (self ):
77+         obs  =  artifact_status_put_req (1 , 'test@foo.bar' , 'sandbox' )
78+         exp  =  {'status' : 'success' ,
79+                'message' : 'Artifact visibility changed to sandbox' }
80+         self .assertEqual (obs , exp )
81+ 
82+     def  test_artifact_status_put_req_private (self ):
83+         obs  =  artifact_status_put_req (1 , 'admin@foo.bar' , 'private' )
84+         exp  =  {'status' : 'success' ,
85+                'message' : 'Artifact visibility changed to private' }
86+         self .assertEqual (obs , exp )
87+ 
88+     def  test_artifact_status_put_req_private_bad_permissions (self ):
89+         obs  =  artifact_status_put_req (1 , 'test@foo.bar' , 'private' )
90+         exp  =  {'status' : 'error' ,
91+                'message' : 'User does not have permissions to approve change' }
92+         self .assertEqual (obs , exp )
93+ 
94+     def  test_artifact_status_put_req_no_access (self ):
95+         obs  =  artifact_status_put_req (1 , 'demo@microbio.me' , 'sandbox' )
96+         exp  =  {'status' : 'error' ,
97+                'message' : 'User does not have access to study' }
98+         self .assertEqual (obs , exp )
99+ 
100+     def  test_artifact_status_put_req_unknown_status (self ):
101+         obs  =  artifact_status_put_req (1 , 'test@foo.bar' , 'BADSTAT' )
102+         exp  =  {'status' : 'error' ,
103+                'message' : 'Unknown visiblity value: BADSTAT' }
104+         self .assertEqual (obs , exp )
105+ 
14106    def  test_artifact_graph_get_req_ancestors (self ):
15107        obs  =  artifact_graph_get_req (1 , 'ancestors' , 'test@foo.bar' )
16108        exp  =  {'status' : 'success' ,
@@ -23,25 +115,24 @@ def test_artifact_graph_get_req_descendants(self):
23115        obs  =  artifact_graph_get_req (1 , 'descendants' , 'test@foo.bar' )
24116        exp  =  {'status' : 'success' ,
25117               'message' : '' ,
26-                'edge_list' : [(1 , 3 ), (1 , 2 ), (2 , 4 )],
27118               'node_labels' : [(1 , 'Raw data 1 - FASTQ' ),
28119                               (3 , 'Demultiplexed 2 - Demultiplexed' ),
29120                               (2 , 'Demultiplexed 1 - Demultiplexed' ),
30-                                (4 , 'BIOM - BIOM' )]}
31-         self .assertEqual (obs , exp )
32- 
33-     def  test_artifact_graph_get_req_bad (self ):
34-         obs  =  artifact_graph_get_req (1 , 'UNKNOWN' , 'test@foo.bar' )
35-         exp  =  {'status' : 'error' ,
36-                'message' : 'Unknown directon UNKNOWN' }
121+                                (4 , 'BIOM - BIOM' )],
122+                'edge_list' : [(1 , 3 ), (1 , 2 ), (2 , 4 )]}
37123        self .assertEqual (obs , exp )
38124
39125    def  test_artifact_graph_get_req_no_access (self ):
40-         obs  =  artifact_graph_get_req (1 , 'descendants ' , 'demo@microbio.me' )
126+         obs  =  artifact_graph_get_req (1 , 'ancestors ' , 'demo@microbio.me' )
41127        exp  =  {'status' : 'error' ,
42128               'message' : 'User does not have access to study' }
43129        self .assertEqual (obs , exp )
44130
131+     def  test_artifact_graph_get_req_bad_direction (self ):
132+         obs  =  artifact_graph_get_req (1 , 'WRONG' , 'test@foo.bar' )
133+         exp  =  {'status' : 'error' , 'message' : 'Unknown directon WRONG' }
134+         self .assertEqual (obs , exp )
135+ 
45136
46137if  __name__  ==  "__main__" :
47138    main ()
0 commit comments