11from __future__ import absolute_import
2+
3+ import json
24import unittest
35import time
46import os
1012
1113class IntegrationTest (unittest .TestCase ):
1214 """A baseclass that's inherited for use with different cwl backends."""
15+
1316 def setUp (self ):
1417 """Start a (local) wes-service server to make requests against."""
1518 raise NotImplementedError
@@ -30,28 +33,51 @@ def tearDown(self):
3033 def test_dockstore_md5sum (self ):
3134 """Fetch the md5sum cwl from dockstore, run it on the wes-service server, and check for the correct output."""
3235 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 )
3437
3538 self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
3639 shutil .rmtree ('workflows' )
3740
3841 def test_local_md5sum (self ):
3942 """Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
4043 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 )
4245
4346 self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
4447 shutil .rmtree ('workflows' )
4548
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+
4660
4761def run_md5sum (cwl_input ):
4862 """Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
4963 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 ()
5374 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 ()
5581
5682
5783def get_server_pids ():
@@ -77,18 +103,21 @@ def check_for_file(filepath, seconds=20):
77103
78104class CwltoolTest (IntegrationTest ):
79105 """Test using cwltool."""
106+
80107 def setUp (self ):
81108 """
82109 Start a (local) wes-service server to make requests against.
83110 Use cwltool as the wes-service server 'backend'.
84111 """
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 )
87115 time .sleep (5 )
88116
89117
90118class ToilTest (IntegrationTest ):
91119 """Test using Toil."""
120+
92121 def setUp (self ):
93122 """
94123 Start a (local) wes-service server to make requests against.
@@ -97,13 +126,12 @@ def setUp(self):
97126 self .wes_server_process = subprocess .Popen ('python {} '
98127 '--opt runner=cwltoil --opt extra=--logLevel=CRITICAL'
99128 '' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
100- shell = True , stdout = subprocess . DEVNULL , stderr = subprocess . DEVNULL )
129+ shell = True )
101130 time .sleep (5 )
102131
103132
104133# Prevent pytest/unittest's discovery from attempting to discover the base test class.
105134del IntegrationTest
106135
107-
108136if __name__ == '__main__' :
109137 unittest .main () # run all tests
0 commit comments