Merge "Update startdash/startpanel for newer Django patterns"
This commit is contained in:
commit
dd98eb5502
@ -23,21 +23,25 @@ import horizon
|
||||
|
||||
class Command(TemplateCommand):
|
||||
template = os.path.join(horizon.__path__[0], "conf", "dash_template")
|
||||
option_list = TemplateCommand.option_list + (
|
||||
make_option('--target',
|
||||
dest='target',
|
||||
action='store',
|
||||
default=None,
|
||||
help='The directory in which the panel '
|
||||
'should be created. Defaults to the '
|
||||
'current directory. The value "auto" '
|
||||
'may also be used to automatically '
|
||||
'create the panel inside the specified '
|
||||
'dashboard module.'),)
|
||||
help = ("Creates a Django app directory structure for a new dashboard "
|
||||
"with the given name in the current directory or optionally in "
|
||||
"the given directory.")
|
||||
|
||||
def add_arguments(self, parser):
|
||||
add = parser.add_argument
|
||||
add('dash_name', help='Dashboard name')
|
||||
add('--template', help='The path or URL to load the template from.')
|
||||
add('--extension', '-e', dest='extensions', action='append',
|
||||
default=["py", "tmpl", "html", "js", "css"],
|
||||
help='The file extension(s) to render (default: "py"). Separate '
|
||||
'multiple extensions with commas, or use -e multiple times.')
|
||||
add('--name', '-n', dest='files', action='append', default=[],
|
||||
help='The file name(s) to render. Separate multiple extensions '
|
||||
'with commas, or use -n multiple times.')
|
||||
add('--target', dest='target', action='store', default=None,
|
||||
help='The directory in which the dashboard should be created. '
|
||||
'Defaults to the current directory.')
|
||||
|
||||
def handle(self, dash_name=None, **options):
|
||||
if dash_name is None:
|
||||
raise CommandError("You must provide a dashboard name.")
|
||||
@ -46,9 +50,6 @@ class Command(TemplateCommand):
|
||||
if not options.get("template", None):
|
||||
options["template"] = self.template
|
||||
|
||||
# We have html templates as well, so make sure those are included.
|
||||
options["extensions"].extend(["tmpl", "html", "js", "css"])
|
||||
|
||||
# Check that the app_name cannot be imported.
|
||||
try:
|
||||
import_module(dash_name)
|
||||
|
@ -22,30 +22,32 @@ import horizon
|
||||
|
||||
|
||||
class Command(TemplateCommand):
|
||||
args = "[name] [dashboard name] [optional destination directory]"
|
||||
option_list = TemplateCommand.option_list + (
|
||||
make_option('--dashboard', '-d',
|
||||
dest='dashboard',
|
||||
action='store',
|
||||
default=None,
|
||||
help='The dotted python path to the '
|
||||
'dashboard which this panel will be '
|
||||
'registered with.'),
|
||||
make_option('--target',
|
||||
dest='target',
|
||||
action='store',
|
||||
default=None,
|
||||
help='The directory in which the panel '
|
||||
'should be created. Defaults to the '
|
||||
'current directory. The value "auto" '
|
||||
'may also be used to automatically '
|
||||
'create the panel inside the specified '
|
||||
'dashboard module.'),)
|
||||
template = os.path.join(horizon.__path__[0], "conf", "panel_template")
|
||||
help = ("Creates a Django app directory structure for a new panel "
|
||||
"with the given name in the current directory or optionally in "
|
||||
"the given directory.")
|
||||
|
||||
def add_arguments(self, parser):
|
||||
add = parser.add_argument
|
||||
add('panel_name', help='Panel name')
|
||||
add('--template', help='The path or URL to load the template from.')
|
||||
add('--extension', '-e', dest='extensions', action='append',
|
||||
default=["py", "tmpl", "html"],
|
||||
help='The file extension(s) to render (default: "py"). Separate '
|
||||
'multiple extensions with commas, or use -e multiple times.')
|
||||
add('--name', '-n', dest='files', action='append', default=[],
|
||||
help='The file name(s) to render. Separate multiple extensions '
|
||||
'with commas, or use -n multiple times.')
|
||||
add('--dashboard', '-d', dest='dashboard', action='store',
|
||||
default=None,
|
||||
help='The dotted python path to the dashboard which this panel '
|
||||
'will be registered with.')
|
||||
add('--target', dest='target', action='store', default=None,
|
||||
help='The directory in which the panel should be created. '
|
||||
'Defaults to the current directory. The value "auto" may also be '
|
||||
'used to automatically create the panel inside the specified '
|
||||
'dashboard module.')
|
||||
|
||||
def handle(self, panel_name=None, **options):
|
||||
if panel_name is None:
|
||||
raise CommandError("You must provide a panel name.")
|
||||
@ -81,9 +83,6 @@ class Command(TemplateCommand):
|
||||
if not options.get("template", None):
|
||||
options["template"] = self.template
|
||||
|
||||
# We have html templates as well, so make sure those are included.
|
||||
options["extensions"].extend(["tmpl", "html"])
|
||||
|
||||
# Check that the app_name cannot be imported.
|
||||
try:
|
||||
import_module(panel_name)
|
||||
|
51
horizon/test/tests/test_commands.py
Normal file
51
horizon/test/tests/test_commands.py
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright 2015, Rackspace, US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.core.management import CommandError
|
||||
from django.test import TestCase
|
||||
|
||||
from horizon.management.commands import startdash
|
||||
from horizon.management.commands import startpanel
|
||||
|
||||
|
||||
class CommandsTestCase(TestCase):
|
||||
def test_startdash_usage_empty(self):
|
||||
self.assertRaises(CommandError, call_command, 'startdash')
|
||||
|
||||
@mock.patch.object(startdash.Command, 'handle')
|
||||
def test_startdash_usage_correct(self, handle):
|
||||
call_command('startdash', 'test_dash')
|
||||
|
||||
handle.assert_called_with(dash_name='test_dash',
|
||||
extensions=["py", "tmpl", "html", "js",
|
||||
"css"],
|
||||
files=[], no_color=False, pythonpath=None,
|
||||
settings=None, skip_checks=True, target=None,
|
||||
template=None, traceback=False, verbosity=1)
|
||||
|
||||
def test_startpanel_usage_empty(self):
|
||||
self.assertRaises(CommandError, call_command, 'startpanel')
|
||||
|
||||
@mock.patch.object(startpanel.Command, 'handle')
|
||||
def test_startpanel_usage_correct(self, handle):
|
||||
call_command('startpanel', 'test_dash', '--dashboard=foo.bar')
|
||||
|
||||
handle.assert_called_with(panel_name='test_dash', dashboard='foo.bar',
|
||||
extensions=["py", "tmpl", "html"],
|
||||
files=[], no_color=False, pythonpath=None,
|
||||
settings=None, skip_checks=True, target=None,
|
||||
template=None, traceback=False, verbosity=1)
|
Loading…
Reference in New Issue
Block a user