Skip to content

Commit 182fe57

Browse files
committed
Initial work on shed-based testing.
Doesn't yet bootstrap a shed - so following idiom should be used to test things with a manually configured shed on localhost:9009. TEST_TOOL_SHED_API_KEY=3dc803338b206156460d2bda85e6a1af nosetests tests/test_shed.py
1 parent 2a2444b commit 182fe57

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

planemo/shed.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ def build_tarball(tool_path):
143143
return temp_path
144144

145145

146+
def username(tsi):
147+
user = _user(tsi)
148+
return user["username"]
149+
150+
151+
def _user(tsi):
152+
""" Fetch user information from the ToolShed API for given
153+
key.
154+
"""
155+
# TODO: this should be done with an actual bioblend method,
156+
# see https://github.com/galaxyproject/bioblend/issues/130.
157+
response = tsi.make_get_request(tsi.url + "/users")
158+
return response.json()[0]
159+
160+
146161
def _tool_shed_url(kwds):
147162
url = kwds.get("shed_target")
148163
if url in SHED_SHORT_NAMES:

tests/test_shed.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
"""
3+
4+
import os
5+
import string
6+
import random
7+
8+
from bioblend import toolshed
9+
10+
from .test_utils import (
11+
skip_unless_environ,
12+
CliTestCase,
13+
)
14+
15+
from planemo.shed import username
16+
17+
SHED_TEMPLATE = string.Template("""owner: ${owner}
18+
name: ${name}
19+
description: Planemo test repository.
20+
homepage_url: https://planemo.readthedocs.org/
21+
remote_repository_url: https://github.com/galaxyproject/planemo/
22+
type: tool_dependency_definition
23+
categories:
24+
- cooltools
25+
""")
26+
27+
28+
class ShedTestCase(CliTestCase):
29+
30+
@skip_unless_environ("TEST_TOOL_SHED_API_KEY")
31+
def test_shed(self):
32+
shed_url = os.environ.get("TEST_TOOL_SHED_URL", "http://localhost:9009")
33+
shed_api_key = os.environ.get("TEST_TOOL_SHED_API_KEY")
34+
tsi = toolshed.ToolShedInstance(shed_url, key=shed_api_key)
35+
owner = username(tsi)
36+
with self._isolate():
37+
shed_yml_contents = SHED_TEMPLATE.safe_substitute(
38+
owner=owner,
39+
name="planemotestrepo%d" % random.randint(0, 1000000),
40+
)
41+
open(".shed.yml", "w").write(shed_yml_contents)
42+
# init_cmd = ["shed_repo_create", "--shed_key", shed_api_key, "--shed_target", shed_url]
43+
# self._check_exit_code(init_cmd)

tests/test_utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
""" Provide abstractions over click testing of the
22
app and unittest.
33
"""
4+
import os
5+
46
from click.testing import CliRunner
57

68
from planemo import cli
79
from sys import version_info
810

911
if version_info < (2, 7):
10-
from unittest2 import TestCase
12+
from unittest2 import TestCase, skip
1113
else:
12-
from unittest import TestCase
14+
from unittest import TestCase, skip
1315

1416

1517
EXIT_CODE_MESSAGE = ("Planemo command [%s] resulted in unexpected exit code "
@@ -49,6 +51,13 @@ def _check_exit_code(self, command_list, exit_code=0):
4951
return result
5052

5153

54+
def skip_unless_environ(var):
55+
if var in os.environ:
56+
return lambda func: func
57+
template = "Environment variable %s not found, dependent test skipped."
58+
return skip(template % var)
59+
60+
5261
__all__ = [
5362
"TestCase",
5463
"CliTestCase",

0 commit comments

Comments
 (0)