1
1
from __future__ import absolute_import
2
2
3
- import json
4
3
import unittest
5
4
import time
6
5
import os
7
6
import subprocess32 as subprocess
8
7
import signal
9
- import requests
10
8
import shutil
11
9
import logging
12
10
13
- from wes_client .util import build_wes_request
11
+ from wes_client .util import WESClient
14
12
15
13
logging .basicConfig (level = logging .INFO )
16
14
@@ -30,6 +28,12 @@ def setUpClass(cls):
30
28
cls .wdl_json_input = "file://" + os .path .abspath ('testdata/md5sum.wdl.json' )
31
29
cls .wdl_attachments = ['file://' + os .path .abspath ('testdata/md5sum.input' )]
32
30
31
+ # client for the swagger API methods
32
+ cls .client = WESClient ({'auth' : '' , 'proto' : 'http' , 'host' : 'localhost:8080' })
33
+
34
+ # manual test (wdl only working locally atm)
35
+ cls .manual = False
36
+
33
37
def setUp (self ):
34
38
"""Start a (local) wes-service server to make requests against."""
35
39
raise NotImplementedError
@@ -44,50 +48,74 @@ def tearDown(self):
44
48
time .sleep (3 )
45
49
except OSError as e :
46
50
print (e )
47
- # if os.path.exists('workflows'):
48
- # shutil.rmtree('workflows')
51
+ if os .path .exists ('workflows' ):
52
+ shutil .rmtree ('workflows' )
49
53
unittest .TestCase .tearDown (self )
50
54
51
55
def test_dockstore_md5sum (self ):
52
56
"""HTTP md5sum cwl (dockstore), run it on the wes-service server, and check for the correct output."""
53
- outfile_path , _ = run_cwl_md5sum ( cwl_input = self .cwl_dockstore_url ,
54
- json_input = self .cwl_json_input ,
55
- 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 )
56
60
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
57
61
58
62
def test_local_md5sum (self ):
59
63
"""LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
60
- outfile_path , run_id = run_cwl_md5sum ( cwl_input = self .cwl_local_path ,
61
- json_input = self .cwl_json_input ,
62
- 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 )
63
67
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
64
68
65
69
def test_run_attachments (self ):
66
70
"""LOCAL md5sum cwl to the wes-service server, check for attachments."""
67
- outfile_path , run_id = run_cwl_md5sum ( cwl_input = self .cwl_local_path ,
68
- json_input = self .cwl_json_input ,
69
- workflow_attachment = self .cwl_attachments )
70
- 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" ]
71
75
self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
72
76
attachment_tool_path = get_response ["workflow_attachment" ][7 :] + "/dockstore-tool-md5sum.cwl"
73
77
self .assertTrue (check_for_file (attachment_tool_path ), 'Attachment file was not found: ' + get_response ["workflow_attachment" ])
74
78
79
+ def test_get_service_info (self ):
80
+ """
81
+ Test wes_client.util.WESClient.get_service_info()
75
82
76
- def run_cwl_md5sum (cwl_input , json_input , workflow_attachment = None ):
77
- """Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
78
- endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
79
- parts = build_wes_request (cwl_input ,
80
- json_input ,
81
- attachments = workflow_attachment )
82
- response = requests .post (endpoint , files = parts ).json ()
83
- assert 'run_id' in response , str (response .json ())
84
- output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
85
- return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
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
86
90
91
+ def test_list_runs (self ):
92
+ """
93
+ Test wes_client.util.WESClient.list_runs()
87
94
88
- def get_log_request (run_id ):
89
- endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs/{}' .format (run_id )
90
- return requests .get (endpoint ).json ()
95
+ This method will exit(1) if the response is not 200.
96
+ """
97
+ r = self .client .list_runs ()
98
+ assert 'workflows' in r
99
+
100
+ def test_get_run_status (self ):
101
+ """
102
+ Test wes_client.util.WESClient.run_status()
103
+
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' ]
91
119
92
120
93
121
def get_server_pids ():
@@ -98,7 +126,7 @@ def get_server_pids():
98
126
return pids
99
127
100
128
101
- def check_for_file (filepath , seconds = 40 ):
129
+ def check_for_file (filepath , seconds = 120 ):
102
130
"""Return True if a file exists within a certain amount of time."""
103
131
wait_counter = 0
104
132
while not os .path .exists (filepath ):
@@ -130,21 +158,26 @@ def setUp(self):
130
158
Start a (local) wes-service server to make requests against.
131
159
Use toil as the wes-service server 'backend'.
132
160
"""
133
- self .wes_server_process = subprocess .Popen ('python {} --backend=wes_service.toil_wes --opt="extra=--logLevel=CRITICAL"'
161
+ self .wes_server_process = subprocess .Popen ('python {} --backend=wes_service.toil_wes '
162
+ '--opt="extra=--logLevel=CRITICAL" '
163
+ '--opt="extra=--clean=never"'
134
164
'' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
135
165
shell = True )
136
166
time .sleep (5 )
137
167
138
168
def test_local_wdl (self ):
139
169
"""LOCAL md5sum wdl to the wes-service server, and check for the correct output."""
140
- outfile_path , run_id = run_cwl_md5sum (cwl_input = self .wdl_local_path ,
141
- json_input = self .wdl_json_input ,
142
- workflow_attachment = self .wdl_attachments )
143
- self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
170
+ # Working locally but not on travis... >.<;
171
+ if self .manual :
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 )
175
+ self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
144
176
145
177
146
178
# Prevent pytest/unittest's discovery from attempting to discover the base test class.
147
179
del IntegrationTest
148
180
181
+
149
182
if __name__ == '__main__' :
150
183
unittest .main () # run all tests
0 commit comments