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

[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(
diff_fields=["declaration", "code", "description"],
push_fields=["name", "declaration", "code", "description"],
def databases(ctx):
"""Database commands"""
ctx.meta["asset_type"] = "database"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
......@@ -668,9 +675,10 @@ CMD_LIST = [
("rm", "rm_local"),
commands.initialise_asset_commands(databases, CMD_LIST)
commands.initialise_asset_commands(databases, CMD_LIST, DatabaseCommand)
......@@ -693,38 +701,6 @@ def pull(ctx, db_names, force):
return pull_impl(webapi, configuration.path, db_names, force, 0, {})
@click.argument("db_names", nargs=-1)
"--force", help="Performs operation regardless of conflicts", is_flag=True
@click.option("--dry-run", help="Dry run", is_flag=True)
def push(ctx, db_names, force, dry_run):
"""Uploads databases to the server (must provide a valid admin token).
$ beat databases push [<name>]...
Database name formatted as "<database>/<version>"
configuration = ctx.meta["config"]
with common.make_webapi(configuration) as webapi:
return common.push(
["name", "declaration", "code", "description"],
@click.argument("db_names", nargs=-1)
......@@ -36,6 +36,7 @@
# Basic tests for the command line beat program: databases
import nose
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):
......@@ -87,14 +88,19 @@ class TestOnlineDatabases(core.OnlineAssetTestCase):
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 ="push", asset_name, prefix=tmp_prefix)
exit_code, output ="push", asset_name), 1, output)
exit_code, output ="rm", "--remote", asset_name, prefix=tmp_prefix)
exit_code, output ="rm", "--remote", asset_name), 2, output)
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"
Supports Markdown
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