5
5
import os
6
6
import subprocess32 as subprocess
7
7
import signal
8
- import requests
9
8
import shutil
10
9
import logging
11
10
12
- from wes_client .util import build_wes_request
11
+ from wes_client .util import WESClient
13
12
14
13
logging .basicConfig (level = logging .INFO )
15
14
@@ -28,7 +27,10 @@ def setUpClass(cls):
28
27
cls .wdl_local_path = os .path .abspath ('testdata/md5sum.wdl' )
29
28
cls .wdl_json_input = "file://" + os .path .abspath ('testdata/md5sum.wdl.json' )
30
29
cls .wdl_attachments = ['file://' + os .path .abspath ('testdata/md5sum.input' )]
31
-
30
+
31
+ # client for the swagger API methods
32
+ cls .client = WESClient ({'auth' : '' , 'proto' : 'http' , 'host' : 'localhost:8080' })
33
+
32
34
# manual test (wdl only working locally atm)
33
35
cls .manual = False
34
36
@@ -52,44 +54,68 @@ def tearDown(self):
52
54
53
55
def test_dockstore_md5sum (self ):
54
56
"""HTTP md5sum cwl (dockstore), run it on the wes-service server, and check for the correct output."""
55
- outfile_path , _ = run_md5sum (wf_input = self .cwl_dockstore_url ,
56
- json_input = self .cwl_json_input ,
57
- workflow_attachment = self .cwl_attachments )
57
+ outfile_path , _ = self . run_md5sum (wf_input = self .cwl_dockstore_url ,
58
+ json_input = self .cwl_json_input ,
59
+ workflow_attachment = self .cwl_attachments )
58
60
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
59
-
61
+
60
62
def test_local_md5sum (self ):
61
63
"""LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
62
- outfile_path , run_id = run_md5sum (wf_input = self .cwl_local_path ,
63
- json_input = self .cwl_json_input ,
64
- workflow_attachment = self .cwl_attachments )
64
+ outfile_path , run_id = self . run_md5sum (wf_input = self .cwl_local_path ,
65
+ json_input = self .cwl_json_input ,
66
+ workflow_attachment = self .cwl_attachments )
65
67
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
66
-
68
+
67
69
def test_run_attachments (self ):
68
70
"""LOCAL md5sum cwl to the wes-service server, check for attachments."""
69
- outfile_path , run_id = run_md5sum (wf_input = self .cwl_local_path ,
70
- json_input = self .cwl_json_input ,
71
- workflow_attachment = self .cwl_attachments )
72
- get_response = get_log_request (run_id )["request" ]
71
+ outfile_path , run_id = self . run_md5sum (wf_input = self .cwl_local_path ,
72
+ json_input = self .cwl_json_input ,
73
+ workflow_attachment = self .cwl_attachments )
74
+ get_response = self . client . get_run_log (run_id )["request" ]
73
75
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
74
76
attachment_tool_path = get_response ["workflow_attachment" ][7 :] + "/dockstore-tool-md5sum.cwl"
75
77
self .assertTrue (check_for_file (attachment_tool_path ), 'Attachment file was not found: ' + get_response ["workflow_attachment" ])
76
78
79
+ def test_get_service_info (self ):
80
+ """
81
+ Test wes_client.util.WESClient.get_service_info()
82
+
83
+ This method will exit(1) if the response is not 200.
84
+ """
85
+ r = self .client .get_service_info ()
86
+ assert 'workflow_type_versions' in r
87
+ assert 'supported_wes_versions' in r
88
+ assert 'supported_filesystem_protocols' in r
89
+ assert 'engine_versions' in r
90
+
91
+ def test_list_runs (self ):
92
+ """
93
+ Test wes_client.util.WESClient.list_runs()
77
94
78
- def run_md5sum (wf_input , json_input , workflow_attachment = None ):
79
- """Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
80
- endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
81
- parts = build_wes_request (wf_input ,
82
- json_input ,
83
- attachments = workflow_attachment )
84
- response = requests .post (endpoint , files = parts ).json ()
85
- assert 'run_id' in response , str (response .json ())
86
- output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
87
- return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
95
+ This method will exit(1) if the response is not 200.
96
+ """
97
+ r = self .client .list_runs ()
98
+ assert 'workflows' in r
88
99
100
+ def test_get_run_status (self ):
101
+ """
102
+ Test wes_client.util.WESClient.run_status()
89
103
90
- def get_log_request (run_id ):
91
- endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs/{}' .format (run_id )
92
- return requests .get (endpoint ).json ()
104
+ This method will exit(1) if the response is not 200.
105
+ """
106
+ outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_local_path ,
107
+ json_input = self .cwl_json_input ,
108
+ workflow_attachment = self .cwl_attachments )
109
+ r = self .client .get_run_status (run_id )
110
+ assert 'state' in r
111
+ assert 'run_id' in r
112
+
113
+ def run_md5sum (self , wf_input , json_input , workflow_attachment = None ):
114
+ """Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
115
+ response = self .client .run (wf_input , json_input , workflow_attachment )
116
+ assert 'run_id' in response , str (response .json ())
117
+ output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
118
+ return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
93
119
94
120
95
121
def get_server_pids ():
@@ -143,14 +169,15 @@ def test_local_wdl(self):
143
169
"""LOCAL md5sum wdl to the wes-service server, and check for the correct output."""
144
170
# Working locally but not on travis... >.<;
145
171
if self .manual :
146
- outfile_path , run_id = run_md5sum (wf_input = self .wdl_local_path ,
147
- json_input = self .wdl_json_input ,
148
- workflow_attachment = self .wdl_attachments )
172
+ outfile_path , run_id = self . run_md5sum (wf_input = self .wdl_local_path ,
173
+ json_input = self .wdl_json_input ,
174
+ workflow_attachment = self .wdl_attachments )
149
175
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
150
176
151
177
152
178
# Prevent pytest/unittest's discovery from attempting to discover the base test class.
153
179
del IntegrationTest
154
180
181
+
155
182
if __name__ == '__main__' :
156
183
unittest .main () # run all tests
0 commit comments