Skip to content

Commit

Permalink
Initial work on shed-based testing.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jmchilton committed Mar 19, 2015
1 parent 2a2444b commit 182fe57
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
15 changes: 15 additions & 0 deletions planemo/shed.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def build_tarball(tool_path):
return temp_path


def username(tsi):
user = _user(tsi)
return user["username"]


def _user(tsi):
""" Fetch user information from the ToolShed API for given
key.
"""
# TODO: this should be done with an actual bioblend method,
# see https://github.com/galaxyproject/bioblend/issues/130.
response = tsi.make_get_request(tsi.url + "/users")
return response.json()[0]


def _tool_shed_url(kwds):
url = kwds.get("shed_target")
if url in SHED_SHORT_NAMES:
Expand Down
43 changes: 43 additions & 0 deletions tests/test_shed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
"""

import os
import string
import random

from bioblend import toolshed

from .test_utils import (
skip_unless_environ,
CliTestCase,
)

from planemo.shed import username

SHED_TEMPLATE = string.Template("""owner: ${owner}
name: ${name}
description: Planemo test repository.
homepage_url: https://planemo.readthedocs.org/
remote_repository_url: https://github.com/galaxyproject/planemo/
type: tool_dependency_definition
categories:
- cooltools
""")


class ShedTestCase(CliTestCase):

@skip_unless_environ("TEST_TOOL_SHED_API_KEY")
def test_shed(self):
shed_url = os.environ.get("TEST_TOOL_SHED_URL", "http://localhost:9009")
shed_api_key = os.environ.get("TEST_TOOL_SHED_API_KEY")
tsi = toolshed.ToolShedInstance(shed_url, key=shed_api_key)
owner = username(tsi)
with self._isolate():
shed_yml_contents = SHED_TEMPLATE.safe_substitute(
owner=owner,
name="planemotestrepo%d" % random.randint(0, 1000000),
)
open(".shed.yml", "w").write(shed_yml_contents)
# init_cmd = ["shed_repo_create", "--shed_key", shed_api_key, "--shed_target", shed_url]
# self._check_exit_code(init_cmd)
13 changes: 11 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
""" Provide abstractions over click testing of the
app and unittest.
"""
import os

from click.testing import CliRunner

from planemo import cli
from sys import version_info

if version_info < (2, 7):
from unittest2 import TestCase
from unittest2 import TestCase, skip
else:
from unittest import TestCase
from unittest import TestCase, skip


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


def skip_unless_environ(var):
if var in os.environ:
return lambda func: func
template = "Environment variable %s not found, dependent test skipped."
return skip(template % var)


__all__ = [
"TestCase",
"CliTestCase",
Expand Down

0 comments on commit 182fe57

Please sign in to comment.