Commit d45c057e authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][core] Refactor call handling

Now cleaner and centralized
parent 559904cd
......@@ -83,6 +83,17 @@ class AssetBaseTest:
def tearDown(self):
cleanup()
@classmethod
def get_cmd_group(cls, asset_type):
try:
cmd_group = common.TYPE_PLURAL[asset_type]
except KeyError:
return asset_type
if "/" in cmd_group:
cmd_group = cmd_group.split("/")[-1]
return cmd_group
@classmethod
def call(cls, *args, **kwargs):
"""A central mechanism to call the main routine with the right parameters"""
......@@ -92,9 +103,7 @@ class AssetBaseTest:
use_cache = kwargs.get("cache", "cache")
asset_type = kwargs.get("asset_type", cls.asset_type)
cmd_group = common.TYPE_PLURAL[asset_type]
if "/" in cmd_group:
cmd_group = cmd_group.split("/")[-1]
cmd_group = cls.get_cmd_group(asset_type)
runner = CliRunner()
with runner.isolated_filesystem():
......@@ -201,16 +210,9 @@ class AssetLocalTest(AssetBaseTest):
nose.tools.assert_false(storage.exists())
class OnlineTestCase(LiveServerTestCase):
class OnlineTestCase(LiveServerTestCase, AssetBaseTest):
"""Test case using django live server for test of remote functions"""
asset_type = None
@classmethod
def setUpClass(cls):
super().setUpClass()
nose.tools.assert_is_not_none(cls.asset_type)
def setUp(self):
"""Cache a copy of the database to avoid the need to call make install
on each tests.
......@@ -227,44 +229,10 @@ class OnlineTestCase(LiveServerTestCase):
else:
shutil.copyfile(db_backup, database_path)
def tearDown(self):
cleanup()
@classmethod
def call(cls, *args, **kwargs):
"""A central mechanism to call the main routine with the right parameters"""
"""Re-implement for platform URL handling"""
use_prefix = kwargs.get("prefix", prefix)
use_platform = kwargs.get("platform", cls.live_server_url)
use_cache = kwargs.get("cache", "cache")
asset_type = kwargs.get("asset_type", cls.asset_type)
cmd_group = common.TYPE_PLURAL[asset_type]
if "/" in cmd_group:
cmd_group = cmd_group.split("/")[-1]
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,
cmd_group,
]
+ list(args),
catch_exceptions=False,
)
kwargs["platform"] = cls.live_server_url
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code, result.output
return super().call(*args, **kwargs)
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