55import os
66import subprocess32 as subprocess
77import signal
8- import requests
98import shutil
109import logging
1110
12- from wes_client .util import build_wes_request
11+ from wes_client .util import WESClient
1312
1413logging .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
95121def 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.
153179del IntegrationTest
154180
181+
155182if __name__ == '__main__' :
156183 unittest .main () # run all tests
0 commit comments