Commit 15ccafdb authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][protocoltemplates] Port tests to AssetLocalTest class

parent 0a32239b
......@@ -36,121 +36,18 @@
# Basic tests for the command line beat program: protocoltemplates
import nose.tools
import click
from click.testing import CliRunner
from beat.core.test.utils import cleanup
from beat.core.protocoltemplate import Storage
from beat.cmdline.scripts import main_cli
from .. import common
from . import platform, prefix, tmp_prefix, user, token
ASSET_TYPE = "protocoltemplate"
def call(*args, **kwargs):
"""A central mechanism to call the main routine with the right parameters"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", platform)
use_cache = kwargs.get("cache", "cache")
print(use_prefix, use_platform, use_cache)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(
main_cli.main,
[
"--test-mode",
"--prefix",
use_prefix,
"--token",
token,
"--user",
user,
"--cache",
use_cache,
"--platform",
use_platform,
"protocoltemplates",
]
+ list(args),
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
@nose.tools.with_setup(teardown=cleanup)
def test_local_list():
nose.tools.eq_(call("list"), 0)
def test_check_valid():
obj = "double/1"
nose.tools.eq_(call("check", obj), 0)
def test_check_invalid():
obj = "invalid/1"
nose.tools.eq_(call("check", obj), 1)
@nose.tools.with_setup(teardown=cleanup)
def test_create(obj=None):
obj = obj or "newprotocoltemplate/1"
nose.tools.eq_(call("create", obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj)
nose.tools.assert_true(s.exists())
return s
@nose.tools.with_setup(teardown=cleanup)
def test_new_version():
obj = "newprotocoltemplate/1"
obj2 = "newprotocoltemplate/2"
test_create(obj)
nose.tools.eq_(call("version", obj, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj2)
nose.tools.assert_true(s.exists())
# check version status
with common.Selector(tmp_prefix) as selector:
nose.tools.eq_(selector.version_of(ASSET_TYPE, obj2), obj)
@nose.tools.with_setup(teardown=cleanup)
def test_fork():
obj = "newprotocoltemplate/1"
obj2 = "different/1"
test_create(obj)
nose.tools.eq_(call("fork", obj, obj2, prefix=tmp_prefix), 0)
s = Storage(tmp_prefix, obj2)
nose.tools.assert_true(s.exists())
# check fork status
with common.Selector(tmp_prefix) as selector:
nose.tools.eq_(selector.forked_from(ASSET_TYPE, obj2), obj)
@nose.tools.with_setup(teardown=cleanup)
def test_delete_local():
obj = "newprotocoltemplate/1"
storage = test_create(obj)
nose.tools.eq_(call("rm", obj, prefix=tmp_prefix), 0)
nose.tools.assert_false(storage.exists())
from . import core
@nose.tools.with_setup(teardown=cleanup)
def test_delete_local_unexisting():
obj = "newprotocoltemplate/1"
storage = Storage(tmp_prefix, obj)
nose.tools.assert_false(storage.exists())
nose.tools.eq_(call("rm", obj, prefix=tmp_prefix), 1)
nose.tools.assert_false(storage.exists())
class TestProtocolTemplateLocal(core.AssetLocalTest):
storage_cls = Storage
asset_type = "protocoltemplate"
object_map = {
"valid": "double/1",
"invalid": "invalid/1",
"create": "new_protocoltemplate/1",
"new": "new_protocoltemplate/2",
"fork": "forked_protocoltemplate/1",
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment