Skip to content

Commit b463777

Browse files
authored
Merge pull request #53 from common-workflow-language/directClientCalls
Direct client calls.
2 parents b38edfa + 87cad53 commit b463777

File tree

8 files changed

+233
-183
lines changed

8 files changed

+233
-183
lines changed

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
install_requires=[
2626
'future',
2727
'connexion==1.4.2',
28-
'bravado==10.1.0',
2928
'ruamel.yaml >= 0.12.4, < 0.15',
3029
'cwlref-runner==1.0',
3130
'schema-salad>=2.6, <3',

test/test_client_util.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import absolute_import
2+
3+
import unittest
4+
import os
5+
import logging
6+
import subprocess
7+
8+
from wes_client.util import expand_globs
9+
10+
logging.basicConfig(level=logging.INFO)
11+
12+
13+
class IntegrationTest(unittest.TestCase):
14+
def setUp(self):
15+
dirname, filename = os.path.split(os.path.abspath(__file__))
16+
self.testdata_dir = dirname + 'data'
17+
18+
def tearDown(self):
19+
unittest.TestCase.tearDown(self)
20+
21+
def test_expand_globs(self):
22+
"""Asserts that wes_client.expand_globs() sees the same files in the cwd as 'ls'."""
23+
files = subprocess.check_output(['ls', '-1', '.'])
24+
25+
# python 2/3 bytestring/utf-8 compatibility
26+
if isinstance(files, str):
27+
files = files.split('\n')
28+
else:
29+
files = files.decode('utf-8').split('\n')
30+
31+
if '' in files:
32+
files.remove('')
33+
files = ['file://' + os.path.abspath(f) for f in files]
34+
glob_files = expand_globs('*')
35+
assert set(files) == glob_files, '\n' + str(set(files)) + '\n' + str(glob_files)
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main() # run all tests

test/test_integration.py

+58-31
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import os
66
import subprocess32 as subprocess
77
import signal
8-
import requests
98
import shutil
109
import logging
1110

12-
from wes_client.util import build_wes_request
11+
from wes_client.util import WESClient
1312

1413
logging.basicConfig(level=logging.INFO)
1514

@@ -28,7 +27,10 @@ def setUpClass(cls):
2827
cls.wdl_local_path = os.path.abspath('testdata/md5sum.wdl')
2928
cls.wdl_json_input = "file://" + os.path.abspath('testdata/md5sum.wdl.json')
3029
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+
3234
# manual test (wdl only working locally atm)
3335
cls.manual = False
3436

@@ -52,44 +54,68 @@ def tearDown(self):
5254

5355
def test_dockstore_md5sum(self):
5456
"""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)
5860
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))
59-
61+
6062
def test_local_md5sum(self):
6163
"""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)
6567
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))
66-
68+
6769
def test_run_attachments(self):
6870
"""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"]
7375
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + get_response["workflow_attachment"])
7476
attachment_tool_path = get_response["workflow_attachment"][7:] + "/dockstore-tool-md5sum.cwl"
7577
self.assertTrue(check_for_file(attachment_tool_path), 'Attachment file was not found: ' + get_response["workflow_attachment"])
7678

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()
7794
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
8899

100+
def test_get_run_status(self):
101+
"""
102+
Test wes_client.util.WESClient.run_status()
89103
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']
93119

94120

95121
def get_server_pids():
@@ -143,14 +169,15 @@ def test_local_wdl(self):
143169
"""LOCAL md5sum wdl to the wes-service server, and check for the correct output."""
144170
# Working locally but not on travis... >.<;
145171
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)
149175
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))
150176

151177

152178
# Prevent pytest/unittest's discovery from attempting to discover the base test class.
153179
del IntegrationTest
154180

181+
155182
if __name__ == '__main__':
156183
unittest.main() # run all tests

0 commit comments

Comments
 (0)