Skip to content

Commit

Permalink
Merge pull request #53 from common-workflow-language/directClientCalls
Browse files Browse the repository at this point in the history
Direct client calls.
  • Loading branch information
tetron authored Aug 13, 2018
2 parents b38edfa + 87cad53 commit b463777
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 183 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
install_requires=[
'future',
'connexion==1.4.2',
'bravado==10.1.0',
'ruamel.yaml >= 0.12.4, < 0.15',
'cwlref-runner==1.0',
'schema-salad>=2.6, <3',
Expand Down
39 changes: 39 additions & 0 deletions test/test_client_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import absolute_import

import unittest
import os
import logging
import subprocess

from wes_client.util import expand_globs

logging.basicConfig(level=logging.INFO)


class IntegrationTest(unittest.TestCase):
def setUp(self):
dirname, filename = os.path.split(os.path.abspath(__file__))
self.testdata_dir = dirname + 'data'

def tearDown(self):
unittest.TestCase.tearDown(self)

def test_expand_globs(self):
"""Asserts that wes_client.expand_globs() sees the same files in the cwd as 'ls'."""
files = subprocess.check_output(['ls', '-1', '.'])

# python 2/3 bytestring/utf-8 compatibility
if isinstance(files, str):
files = files.split('\n')
else:
files = files.decode('utf-8').split('\n')

if '' in files:
files.remove('')
files = ['file://' + os.path.abspath(f) for f in files]
glob_files = expand_globs('*')
assert set(files) == glob_files, '\n' + str(set(files)) + '\n' + str(glob_files)


if __name__ == '__main__':
unittest.main() # run all tests
89 changes: 58 additions & 31 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import os
import subprocess32 as subprocess
import signal
import requests
import shutil
import logging

from wes_client.util import build_wes_request
from wes_client.util import WESClient

logging.basicConfig(level=logging.INFO)

Expand All @@ -28,7 +27,10 @@ def setUpClass(cls):
cls.wdl_local_path = os.path.abspath('testdata/md5sum.wdl')
cls.wdl_json_input = "file://" + os.path.abspath('testdata/md5sum.wdl.json')
cls.wdl_attachments = ['file://' + os.path.abspath('testdata/md5sum.input')]


# client for the swagger API methods
cls.client = WESClient({'auth': '', 'proto': 'http', 'host': 'localhost:8080'})

# manual test (wdl only working locally atm)
cls.manual = False

Expand All @@ -52,44 +54,68 @@ def tearDown(self):

def test_dockstore_md5sum(self):
"""HTTP md5sum cwl (dockstore), run it on the wes-service server, and check for the correct output."""
outfile_path, _ = run_md5sum(wf_input=self.cwl_dockstore_url,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
outfile_path, _ = self.run_md5sum(wf_input=self.cwl_dockstore_url,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))

def test_local_md5sum(self):
"""LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
outfile_path, run_id = run_md5sum(wf_input=self.cwl_local_path,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
outfile_path, run_id = self.run_md5sum(wf_input=self.cwl_local_path,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))

def test_run_attachments(self):
"""LOCAL md5sum cwl to the wes-service server, check for attachments."""
outfile_path, run_id = run_md5sum(wf_input=self.cwl_local_path,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
get_response = get_log_request(run_id)["request"]
outfile_path, run_id = self.run_md5sum(wf_input=self.cwl_local_path,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
get_response = self.client.get_run_log(run_id)["request"]
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + get_response["workflow_attachment"])
attachment_tool_path = get_response["workflow_attachment"][7:] + "/dockstore-tool-md5sum.cwl"
self.assertTrue(check_for_file(attachment_tool_path), 'Attachment file was not found: ' + get_response["workflow_attachment"])

def test_get_service_info(self):
"""
Test wes_client.util.WESClient.get_service_info()
This method will exit(1) if the response is not 200.
"""
r = self.client.get_service_info()
assert 'workflow_type_versions' in r
assert 'supported_wes_versions' in r
assert 'supported_filesystem_protocols' in r
assert 'engine_versions' in r

def test_list_runs(self):
"""
Test wes_client.util.WESClient.list_runs()
def run_md5sum(wf_input, json_input, workflow_attachment=None):
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
parts = build_wes_request(wf_input,
json_input,
attachments=workflow_attachment)
response = requests.post(endpoint, files=parts).json()
assert 'run_id' in response, str(response.json())
output_dir = os.path.abspath(os.path.join('workflows', response['run_id'], 'outdir'))
return os.path.join(output_dir, 'md5sum.txt'), response['run_id']
This method will exit(1) if the response is not 200.
"""
r = self.client.list_runs()
assert 'workflows' in r

def test_get_run_status(self):
"""
Test wes_client.util.WESClient.run_status()
def get_log_request(run_id):
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs/{}'.format(run_id)
return requests.get(endpoint).json()
This method will exit(1) if the response is not 200.
"""
outfile_path, run_id = self.run_md5sum(wf_input=self.cwl_local_path,
json_input=self.cwl_json_input,
workflow_attachment=self.cwl_attachments)
r = self.client.get_run_status(run_id)
assert 'state' in r
assert 'run_id' in r

def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
response = self.client.run(wf_input, json_input, workflow_attachment)
assert 'run_id' in response, str(response.json())
output_dir = os.path.abspath(os.path.join('workflows', response['run_id'], 'outdir'))
return os.path.join(output_dir, 'md5sum.txt'), response['run_id']


def get_server_pids():
Expand Down Expand Up @@ -143,14 +169,15 @@ def test_local_wdl(self):
"""LOCAL md5sum wdl to the wes-service server, and check for the correct output."""
# Working locally but not on travis... >.<;
if self.manual:
outfile_path, run_id = run_md5sum(wf_input=self.wdl_local_path,
json_input=self.wdl_json_input,
workflow_attachment=self.wdl_attachments)
outfile_path, run_id = self.run_md5sum(wf_input=self.wdl_local_path,
json_input=self.wdl_json_input,
workflow_attachment=self.wdl_attachments)
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))


# Prevent pytest/unittest's discovery from attempting to discover the base test class.
del IntegrationTest


if __name__ == '__main__':
unittest.main() # run all tests
Loading

0 comments on commit b463777

Please sign in to comment.