1
1
from __future__ import absolute_import
2
+
3
+ import json
2
4
import unittest
3
5
import time
4
6
import os
10
12
11
13
class IntegrationTest (unittest .TestCase ):
12
14
"""A baseclass that's inherited for use with different cwl backends."""
15
+
13
16
def setUp (self ):
14
17
"""Start a (local) wes-service server to make requests against."""
15
18
raise NotImplementedError
@@ -30,28 +33,51 @@ def tearDown(self):
30
33
def test_dockstore_md5sum (self ):
31
34
"""Fetch the md5sum cwl from dockstore, run it on the wes-service server, and check for the correct output."""
32
35
cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
33
- output_filepath = run_md5sum (cwl_input = cwl_dockstore_url )
36
+ output_filepath , _ = run_md5sum (cwl_input = cwl_dockstore_url )
34
37
35
38
self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
36
39
shutil .rmtree ('workflows' )
37
40
38
41
def test_local_md5sum (self ):
39
42
"""Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
40
43
cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
41
- output_filepath = run_md5sum (cwl_input = 'file://' + cwl_local_path )
44
+ output_filepath , _ = run_md5sum (cwl_input = 'file://' + cwl_local_path )
42
45
43
46
self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
44
47
shutil .rmtree ('workflows' )
45
48
49
+ def test_multipart_upload (self ):
50
+ """Pass a local md5sum cwl to the wes-service server, and check for uploaded file in service."""
51
+ cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
52
+ _ , run_id = run_md5sum (cwl_input = 'file://' + cwl_local_path )
53
+
54
+ get_response = get_log_request (run_id )["request" ]
55
+
56
+ self .assertTrue (check_for_file (get_response ["workflow_url" ][7 :]), 'Output file was not found: '
57
+ + get_response ["workflow_url" ][:7 ])
58
+ shutil .rmtree ('workflows' )
59
+
46
60
47
61
def run_md5sum (cwl_input ):
48
62
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
49
63
endpoint = 'http://localhost:8080/ga4gh/wes/v1/workflows'
50
- params = {'output_file' : {'path' : '/tmp/md5sum.txt' , 'class' : 'File' }, 'input_file' : {'path' : '../../testdata/md5sum.input' , 'class' : 'File' }}
51
- body = {'workflow_url' : cwl_input , 'workflow_params' : params , 'workflow_type' : 'CWL' , 'workflow_type_version' : 'v1.0' }
52
- response = requests .post (endpoint , json = body ).json ()
64
+ params = {'output_file' : {'path' : '/tmp/md5sum.txt' , 'class' : 'File' },
65
+ 'input_file' : {'path' : '../../testdata/md5sum.input' , 'class' : 'File' }}
66
+
67
+ parts = [("workflow_params" , json .dumps (params )), ("workflow_type" , "CWL" ), ("workflow_type_version" , "v1.0" )]
68
+ if cwl_input .startswith ("file://" ):
69
+ parts .append (("workflow_descriptor" , ("md5sum.cwl" , open (cwl_input [7 :], "rb" ))))
70
+ parts .append (("workflow_url" , os .path .basename (cwl_input [7 :])))
71
+ else :
72
+ parts .append (("workflow_url" , cwl_input ))
73
+ response = requests .post (endpoint , files = parts ).json ()
53
74
output_dir = os .path .abspath (os .path .join ('workflows' , response ['workflow_id' ], 'outdir' ))
54
- return os .path .join (output_dir , 'md5sum.txt' )
75
+ return os .path .join (output_dir , 'md5sum.txt' ), response ['workflow_id' ]
76
+
77
+
78
+ def get_log_request (run_id ):
79
+ endpoint = 'http://localhost:8080/ga4gh/wes/v1/workflows/{}' .format (run_id )
80
+ return requests .get (endpoint ).json ()
55
81
56
82
57
83
def get_server_pids ():
@@ -77,18 +103,21 @@ def check_for_file(filepath, seconds=20):
77
103
78
104
class CwltoolTest (IntegrationTest ):
79
105
"""Test using cwltool."""
106
+
80
107
def setUp (self ):
81
108
"""
82
109
Start a (local) wes-service server to make requests against.
83
110
Use cwltool as the wes-service server 'backend'.
84
111
"""
85
- self .wes_server_process = subprocess .Popen ('python {}' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
86
- shell = True , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
112
+ self .wes_server_process = subprocess .Popen (
113
+ 'python {}' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
114
+ shell = True )
87
115
time .sleep (5 )
88
116
89
117
90
118
class ToilTest (IntegrationTest ):
91
119
"""Test using Toil."""
120
+
92
121
def setUp (self ):
93
122
"""
94
123
Start a (local) wes-service server to make requests against.
@@ -97,13 +126,12 @@ def setUp(self):
97
126
self .wes_server_process = subprocess .Popen ('python {} '
98
127
'--opt runner=cwltoil --opt extra=--logLevel=CRITICAL'
99
128
'' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
100
- shell = True , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
129
+ shell = True )
101
130
time .sleep (5 )
102
131
103
132
104
133
# Prevent pytest/unittest's discovery from attempting to discover the base test class.
105
134
del IntegrationTest
106
135
107
-
108
136
if __name__ == '__main__' :
109
137
unittest .main () # run all tests
0 commit comments