10
10
import shutil
11
11
import logging
12
12
13
+ from wes_client .util import build_wes_request
14
+
13
15
logging .basicConfig (level = logging .INFO )
14
16
15
17
16
18
class IntegrationTest (unittest .TestCase ):
17
19
"""A baseclass that's inherited for use with different cwl backends."""
20
+ @classmethod
21
+ def setUpClass (cls ):
22
+
23
+ cls .cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
24
+ cls .cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
25
+ cls .json_input = "file://" + os .path .abspath ('testdata/md5sum.json' )
26
+ cls .attachments = ['file://' + os .path .abspath ('testdata/md5sum.input' ),
27
+ 'file://' + os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )]
18
28
19
29
def setUp (self ):
20
30
"""Start a (local) wes-service server to make requests against."""
@@ -35,72 +45,54 @@ def tearDown(self):
35
45
unittest .TestCase .tearDown (self )
36
46
37
47
def test_dockstore_md5sum (self ):
38
- """Fetch the md5sum cwl from dockstore, run it on the wes-service server, and check for the correct output."""
39
- cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
40
- output_filepath , _ = run_cwl_md5sum ( cwl_input = cwl_dockstore_url )
41
-
42
- self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
48
+ """HTTP md5sum cwl ( dockstore) , run it on the wes-service server, and check for the correct output."""
49
+ outfile_path , _ = run_cwl_md5sum ( cwl_input = self . cwl_dockstore_url ,
50
+ json_input = self . json_input ,
51
+ workflow_attachment = self . attachments )
52
+ self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
43
53
44
54
def test_local_md5sum (self ):
45
- """Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
46
- cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
47
- workflow_attachment_path = os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )
48
- output_filepath , _ = run_cwl_md5sum (cwl_input = 'file://' + cwl_local_path ,
49
- workflow_attachment = 'file://' + workflow_attachment_path )
50
-
51
- self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
55
+ """LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
56
+ outfile_path , run_id = run_cwl_md5sum (cwl_input = self .cwl_local_path ,
57
+ json_input = self .json_input ,
58
+ workflow_attachment = self .attachments )
59
+ self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
52
60
53
61
def test_multipart_upload (self ):
54
- """Pass a local md5sum cwl to the wes-service server, and check for uploaded file in service."""
55
- cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
56
- workflow_attachment_path = os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )
57
- out_file_path , run_id = run_cwl_md5sum (cwl_input = 'file://' + cwl_local_path ,
58
- workflow_attachment = 'file://' + workflow_attachment_path )
59
-
62
+ """LOCAL md5sum cwl to the wes-service server, and check for uploaded file in service."""
63
+ outfile_path , run_id = run_cwl_md5sum (cwl_input = self .cwl_local_path ,
64
+ json_input = self .json_input ,
65
+ workflow_attachment = self .attachments )
60
66
get_response = get_log_request (run_id )["request" ]
61
-
62
- self .assertTrue (check_for_file (out_file_path ), 'Output file was not found: '
63
- + get_response ["workflow_attachment" ])
64
- self .assertTrue (check_for_file (get_response ["workflow_url" ][7 :]), 'Output file was not found: '
65
- + get_response ["workflow_url" ][:7 ])
67
+ self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
68
+ self .assertTrue (check_for_file (get_response ["workflow_url" ][7 :]), 'Output file was not found: ' + get_response ["workflow_url" ][:7 ])
66
69
67
70
def test_run_attachments (self ):
68
- """Pass a local md5sum cwl to the wes-service server, check for attachments."""
69
- cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
70
- workflow_attachment_path = os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )
71
- out_file_path , run_id = run_cwl_md5sum (cwl_input = 'file://' + cwl_local_path ,
72
- workflow_attachment = 'file://' + workflow_attachment_path )
73
-
71
+ """LOCAL md5sum cwl to the wes-service server, check for attachments."""
72
+ outfile_path , run_id = run_cwl_md5sum (cwl_input = self .cwl_local_path ,
73
+ json_input = self .json_input ,
74
+ workflow_attachment = self .attachments )
74
75
get_response = get_log_request (run_id )["request" ]
75
76
attachment_tool_path = get_response ["workflow_attachment" ][7 :] + "/dockstore-tool-md5sum.cwl"
76
- self .assertTrue (check_for_file (out_file_path ), 'Output file was not found: '
77
- + get_response ["workflow_attachment" ])
78
- self .assertTrue (check_for_file (attachment_tool_path ), 'Attachment file was not found: '
79
- + get_response ["workflow_attachment" ])
77
+ self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
78
+ self .assertTrue (check_for_file (attachment_tool_path ), 'Attachment file was not found: ' + get_response ["workflow_attachment" ])
80
79
81
80
82
- def run_cwl_md5sum (cwl_input , workflow_attachment = None ):
81
+ def run_cwl_md5sum (cwl_input , json_input , workflow_attachment = None ):
83
82
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
84
83
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
85
- params = {'output_file' : {'path' : '/tmp/md5sum.txt' , 'class' : 'File' },
86
- 'input_file' : {'path' : os .path .abspath ('testdata/md5sum.input' ), 'class' : 'File' }}
87
-
88
- parts = [("workflow_params" , json .dumps (params )), ("workflow_type" , "CWL" ), ("workflow_type_version" , "v1.0" )]
89
- if cwl_input .startswith ("file://" ):
90
- parts .append (("workflow_attachment" , ("md5sum.cwl" , open (cwl_input [7 :], "rb" ))))
91
- parts .append (("workflow_url" , os .path .basename (cwl_input [7 :])))
92
- if workflow_attachment :
93
- parts .append (("workflow_attachment" , ("dockstore-tool-md5sum.cwl" , open (workflow_attachment [7 :], "rb" ))))
94
- else :
95
- parts .append (("workflow_url" , cwl_input ))
84
+ parts = build_wes_request (cwl_input ,
85
+ json_input ,
86
+ attachments = workflow_attachment )
96
87
response = requests .post (endpoint , files = parts ).json ()
88
+
97
89
output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
98
90
return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
99
91
100
92
101
93
def run_wdl_md5sum (wdl_input ):
102
94
"""Pass a local md5sum wdl to the wes-service server, and return the path of the output file that was created."""
103
- endpoint = 'http://localhost:8080/ga4gh/wes/v1/workflows '
95
+ endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs '
104
96
params = '{"ga4ghMd5.inputFile": "' + os .path .abspath ('testdata/md5sum.input' ) + '"}'
105
97
parts = [("workflow_params" , params ),
106
98
("workflow_type" , "WDL" ),
@@ -136,8 +128,6 @@ def check_for_file(filepath, seconds=40):
136
128
while not os .path .exists (filepath ):
137
129
time .sleep (1 )
138
130
wait_counter += 1
139
- if os .path .exists (filepath ):
140
- return True
141
131
if wait_counter > seconds :
142
132
return False
143
133
return True
0 commit comments