Update package-import command

Categories is now an optional parameter during package uploading.
Also, ability to add list of categories were added.

Change-Id: I1cce9487147c4dce4fdf3e382ecf4c40660e1e0c
Targets: blueprint murano-cli-client
This commit is contained in:
Ekaterina Fedorova 2014-06-24 13:51:19 +04:00
parent d62b0f2d6e
commit ba40a6799f
3 changed files with 67 additions and 13 deletions

View File

@ -24,6 +24,7 @@ from testtools import matchers
from muranoclient.openstack.common.apiclient import exceptions
import muranoclient.shell
from muranoclient.tests import base
from muranoclient.v1 import shell as v1_shell
FIXTURE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'fixture_data'))
@ -40,6 +41,10 @@ FAKE_ENV2 = {'OS_USERNAME': 'username',
'OS_AUTH_URL': 'http://no.where'}
class TestArgs(object):
pass
class ShellTest(base.TestCaseShell):
def make_env(self, exclude=None, fake_env=FAKE_ENV):
@ -50,6 +55,7 @@ class ShellTest(base.TestCaseShell):
super(ShellTest, self).setUp()
self.useFixture(fixtures.MonkeyPatch(
'keystoneclient.v2_0.client.Client', mock.MagicMock))
self.client = mock.MagicMock()
def shell(self, argstr, exitcodes=(0,)):
orig = sys.stdout
@ -155,6 +161,13 @@ class ShellTest(base.TestCaseShell):
else:
self.fail('CommandError not raised')
class ShellPackagesOperations(ShellTest):
def tearDown(self):
super(ShellPackagesOperations, self).tearDown()
if os.path.exists(RESULT_PACKAGE):
os.remove(RESULT_PACKAGE)
def test_create_hot_based_package(self):
self.useFixture(fixtures.MonkeyPatch(
'muranoclient.v1.client.Client', mock.MagicMock))
@ -182,3 +195,37 @@ class ShellTest(base.TestCaseShell):
matchers.MatchesRegex((stdout + stderr),
"Application package "
"is available at {0}".format(RESULT_PACKAGE))
def test_package_import(self):
open(RESULT_PACKAGE, 'a').close()
args = TestArgs()
args.filename = RESULT_PACKAGE
args.categories = ['Cat1', 'Cat2 with space']
v1_shell.do_package_import(self.client, args)
self.client.packages.create.assert_called_once_with(
{'categories': ['Cat1', 'Cat2 with space']},
((RESULT_PACKAGE, mock.ANY),)
)
def test_package_import_no_categories(self):
open(RESULT_PACKAGE, 'a').close()
args = TestArgs()
args.filename = RESULT_PACKAGE
args.categories = None
v1_shell.do_package_import(self.client, args)
self.client.packages.create.assert_called_once_with(
None,
((RESULT_PACKAGE, mock.ANY),)
)
def test_package_import_wrong_file(self):
args = TestArgs()
args.filename = '/home/this/path/does/not/exist'
args.categories = None
self.assertRaises(IOError,
v1_shell.do_package_import, self.client, args)

View File

@ -177,12 +177,17 @@ def do_package_delete(mc, args):
do_package_list(mc)
@utils.arg("filename", metavar="file", help="Zip file containing package")
@utils.arg("category", nargs="+",
help="One or more categories to which the package belongs")
@utils.arg('filename', metavar='<FILE>', help='Zip file containing package')
@utils.arg('-c', '--categories', metavar='<CAT1 CAT2 CAT3>', nargs='*',
help='Category list to attach')
def do_package_import(mc, args):
"""Import a package. `file` should be the path to a zip file."""
data = {"categories": args.category}
"""Import a package.
`FILE` should be the path to a zip file.
`categories` could be separated by a comma
"""
data = None
if args.categories:
data = {"categories": args.categories}
mc.packages.create(data, ((args.filename, open(args.filename, 'rb')),))
do_package_list(mc)

18
tox.ini
View File

@ -5,23 +5,25 @@ skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
DISCOVER_DIRECTORY=muranoclient/tests
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py test --slowest --testr-args="{posargs}"
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
commands =
flake8 {posargs}
commands = flake8 {posargs}
[testenv:venv]
commands = {posargs}
[testenv:uitests]
commands = python setup.py testr --slowest --testr-args="--concurrency 1 {posargs}"
[testenv:cover]
commands = python setup.py test --coverage --testr-args='{posargs}'
commands = python setup.py testr --coverage --testr-args='--concurrency 1 {posargs}'
[tox:jenkins]
downloadcache = ~/cache/pip