Skip to content

Commit 6d05514

Browse files
committed
Change tests to use new client.
1 parent 877d167 commit 6d05514

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

test/test_integration.py

Lines changed: 20 additions & 27 deletions
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,6 +27,9 @@ 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')]
30+
31+
# houses the API methods
32+
cls.client = WESClient({'auth': '', 'proto': 'http', 'host': 'localhost:8080'})
3133

3234
# manual test (wdl only working locally atm)
3335
cls.manual = False
@@ -52,44 +54,35 @@ 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))
5961

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))
6668

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

7779

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']
88-
89-
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()
80+
def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
81+
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
82+
response = self.client.run(wf_input, json_input, workflow_attachment)
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']
9386

9487

9588
def get_server_pids():

wes_client/util.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import json
3-
from bravado.requests_client import RequestsClient
3+
import requests
44
import urllib
55
import logging
66
import schema_salad.ref_resolver
@@ -102,7 +102,6 @@ def __init__(self, service):
102102
self.auth = service['auth']
103103
self.proto = service['proto']
104104
self.host = service['host']
105-
self.http_client = RequestsClient()
106105

107106
def get_service_info(self):
108107
"""
@@ -118,8 +117,8 @@ def get_service_info(self):
118117
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
119118
:return: The body of the get result as a dictionary.
120119
"""
121-
postresult = self.http_client.session.get("%s://%s/ga4gh/wes/v1/service-info" % (self.proto, self.host),
122-
headers={"Authorization": self.auth})
120+
postresult = requests.get("%s://%s/ga4gh/wes/v1/service-info" % (self.proto, self.host),
121+
headers={"Authorization": self.auth})
123122
return wes_reponse(postresult)
124123

125124
def list_runs(self):
@@ -135,8 +134,8 @@ def list_runs(self):
135134
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
136135
:return: The body of the get result as a dictionary.
137136
"""
138-
postresult = self.http_client.session.get("%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
139-
headers={"Authorization": self.auth})
137+
postresult = requests.get("%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
138+
headers={"Authorization": self.auth})
140139
return wes_reponse(postresult)
141140

142141
def run(self, wf, jsonyaml, attachments):
@@ -154,52 +153,52 @@ def run(self, wf, jsonyaml, attachments):
154153
:return: The body of the post result as a dictionary.
155154
"""
156155
parts = build_wes_request(wf, jsonyaml, attachments)
157-
postresult = self.http_client.session.post("%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
158-
files=parts,
159-
headers={"Authorization": self.auth})
156+
postresult = requests.post("%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
157+
files=parts,
158+
headers={"Authorization": self.auth})
160159
return wes_reponse(postresult)
161160

162161
def cancel(self, run_id):
163162
"""
164163
Cancel a running workflow.
165164
166-
:param run_id:
165+
:param run_id: String (typically a uuid) identifying the run.
167166
:param object http_client: bravado.requests_client.RequestsClient
168167
:param str auth: String to send in the auth header.
169168
:param proto: Schema where the server resides (http, https)
170169
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
171170
:return: The body of the delete result as a dictionary.
172171
"""
173-
postresult = self.http_client.session.delete("%s://%s/ga4gh/wes/v1/runs/%s" % (self.proto, self.host, run_id),
174-
headers={"Authorization": self.auth})
172+
postresult = requests.delete("%s://%s/ga4gh/wes/v1/runs/%s" % (self.proto, self.host, run_id),
173+
headers={"Authorization": self.auth})
175174
return wes_reponse(postresult)
176175

177176
def get_run_log(self, run_id):
178177
"""
179178
Get detailed info about a running workflow.
180179
181-
:param run_id:
180+
:param run_id: String (typically a uuid) identifying the run.
182181
:param object http_client: bravado.requests_client.RequestsClient
183182
:param str auth: String to send in the auth header.
184183
:param proto: Schema where the server resides (http, https)
185184
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
186185
:return: The body of the get result as a dictionary.
187186
"""
188-
postresult = self.http_client.session.get("%s://%s/ga4gh/wes/v1/runs/%s" % (self.proto, self.host, run_id),
189-
headers={"Authorization": self.auth})
187+
postresult = requests.get("%s://%s/ga4gh/wes/v1/runs/%s" % (self.proto, self.host, run_id),
188+
headers={"Authorization": self.auth})
190189
return wes_reponse(postresult)
191190

192191
def get_run_status(self, run_id):
193192
"""
194193
Get quick status info about a running workflow.
195194
196-
:param run_id:
195+
:param run_id: String (typically a uuid) identifying the run.
197196
:param object http_client: bravado.requests_client.RequestsClient
198197
:param str auth: String to send in the auth header.
199198
:param proto: Schema where the server resides (http, https)
200199
:param host: Port where the post request will be sent and the wes server listens at (default 8080)
201200
:return: The body of the get result as a dictionary.
202201
"""
203-
postresult = self.http_client.session.get("%s://%s/ga4gh/wes/v1/runs/%s/status" % (self.proto, self.host, run_id),
204-
headers={"Authorization": self.auth})
202+
postresult = requests.get("%s://%s/ga4gh/wes/v1/runs/%s/status" % (self.proto, self.host, run_id),
203+
headers={"Authorization": self.auth})
205204
return wes_reponse(postresult)

0 commit comments

Comments
 (0)