Commit dac5b8ff authored by Samuel GAIST's avatar Samuel GAIST

[databases] Port to AssetCommand

parent 986b1d79
......@@ -56,6 +56,8 @@ from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
from .click_helper import AssetCommand
from .click_helper import AssetInfo
logger = logging.getLogger(__name__)
......@@ -649,14 +651,19 @@ def view_outputs(
# ----------------------------------------------------------
class DatabaseCommand(AssetCommand):
asset_info = AssetInfo(
asset_type="database",
diff_fields=["declaration", "code", "description"],
push_fields=["name", "declaration", "code", "description"],
)
@click.group(cls=AliasedGroup)
@click.pass_context
def databases(ctx):
"""Database commands"""
ctx.meta["asset_type"] = "database"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
CMD_LIST = [
"list",
......@@ -668,9 +675,10 @@ CMD_LIST = [
"version",
("rm", "rm_local"),
"diff",
"push",
]
commands.initialise_asset_commands(databases, CMD_LIST)
commands.initialise_asset_commands(databases, CMD_LIST, DatabaseCommand)
@databases.command()
......@@ -693,38 +701,6 @@ def pull(ctx, db_names, force):
return pull_impl(webapi, configuration.path, db_names, force, 0, {})
@databases.command()
@click.argument("db_names", nargs=-1)
@click.option(
"--force", help="Performs operation regardless of conflicts", is_flag=True
)
@click.option("--dry-run", help="Dry run", is_flag=True)
@click.pass_context
@raise_on_error
def push(ctx, db_names, force, dry_run):
"""Uploads databases to the server (must provide a valid admin token).
$ beat databases push [<name>]...
<name>:
Database name formatted as "<database>/<version>"
"""
configuration = ctx.meta["config"]
with common.make_webapi(configuration) as webapi:
return common.push(
webapi,
configuration.path,
"database",
db_names,
["name", "declaration", "code", "description"],
{},
force,
dry_run,
0,
)
@databases.command()
@click.argument("db_names", nargs=-1)
@click.option(
......
......@@ -36,6 +36,7 @@
# Basic tests for the command line beat program: databases
import nose
import nose.tools
from beat.backend.python.test.test_database import INTEGERS_DBS
......@@ -71,7 +72,7 @@ class TestDatabaseLocal(core.AssetLocalTest):
class TestOnlineDatabases(core.OnlineAssetTestCase):
asset_type = "database"
storage_cls = Storage
object_map = {"pull": "simple/1", "diff": "simple/1"}
object_map = {"pull": "simple/1", "diff": "simple/1", "push": "simple/1"}
def _modify_asset(self, asset_name):
"""Re-imp"""
......@@ -87,14 +88,19 @@ class TestOnlineDatabases(core.OnlineAssetTestCase):
@core.skip_disconnected
def test_push_and_delete(self):
asset_name = self.object_map["pull"]
asset_name = self.object_map["push"]
# now push the new object and then delete it remotely
exit_code, output = self.call("push", asset_name, prefix=tmp_prefix)
exit_code, output = self.call("push", asset_name)
nose.tools.eq_(exit_code, 1, output)
exit_code, output = self.call("rm", "--remote", asset_name, prefix=tmp_prefix)
exit_code, output = self.call("rm", "--remote", asset_name)
nose.tools.eq_(exit_code, 2, output)
@core.skip_disconnected
def test_fail_not_owner_push(self):
"""No owner so not need to test"""
raise nose.SkipTest("Database have no owner")
class TestView(core.AssetBaseTest):
asset_type = "database"
......
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