Merge "Make sure queue create works for cli"
This commit is contained in:
commit
d80f715edf
@ -27,3 +27,4 @@ sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
|||||||
os-client-config!=1.6.2,>=1.4.0
|
os-client-config!=1.6.2,>=1.4.0
|
||||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||||
openstack-doc-tools>=0.23
|
openstack-doc-tools>=0.23
|
||||||
|
python-openstackclient>=2.0.0
|
||||||
|
0
tests/unit/cli/__init__.py
Normal file
0
tests/unit/cli/__init__.py
Normal file
31
tests/unit/cli/fakes.py
Normal file
31
tests/unit/cli/fakes.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Copyright (c) 2015 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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 openstackclient.tests import utils
|
||||||
|
|
||||||
|
|
||||||
|
class TestMessaging(utils.TestCommand):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestMessaging, self).setUp()
|
||||||
|
|
||||||
|
self.messaging_client = mock.MagicMock()
|
||||||
|
# TODO(flwang): It would be nice if we can figure out a better way to
|
||||||
|
# get the mocked request and transport.
|
||||||
|
req_trans = (mock.MagicMock(), mock.MagicMock())
|
||||||
|
self.messaging_client._request_and_transport.return_value = req_trans
|
||||||
|
self.app.client_manager.messaging = self.messaging_client
|
0
tests/unit/cli/v1/__init__.py
Normal file
0
tests/unit/cli/v1/__init__.py
Normal file
69
tests/unit/cli/v1/test_queues.py
Normal file
69
tests/unit/cli/v1/test_queues.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# Copyright (c) 2015 Catalyst IT Ltd.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from tests.unit.cli import fakes
|
||||||
|
|
||||||
|
from zaqarclient.queues.v1 import cli as v1_cli
|
||||||
|
from zaqarclient.queues.v1 import iterator
|
||||||
|
from zaqarclient.queues.v1 import queues as v1_api_queues
|
||||||
|
|
||||||
|
|
||||||
|
class TestQueues(fakes.TestMessaging):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestQueues, self).setUp()
|
||||||
|
|
||||||
|
|
||||||
|
class TestV1ListQueues(TestQueues):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestV1ListQueues, self).setUp()
|
||||||
|
queues_list = iterator._Iterator(self, [{'name': 'fake_queue'}],
|
||||||
|
'queues',
|
||||||
|
v1_api_queues.create_object(self))
|
||||||
|
self.app.client_manager.messaging.queues.return_value = queues_list
|
||||||
|
|
||||||
|
# Command to test
|
||||||
|
self.cmd = v1_cli.ListQueues(self.app, None)
|
||||||
|
|
||||||
|
def test_queues_list(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Check that columns are correct
|
||||||
|
expected_columns = ('Name',)
|
||||||
|
self.assertEqual(expected_columns, columns)
|
||||||
|
# Check that data is correct
|
||||||
|
expected_data = [('fake_queue',)]
|
||||||
|
self.assertEqual(expected_data, list(data))
|
||||||
|
|
||||||
|
|
||||||
|
class TestV1CreateQueue(TestQueues):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestV1CreateQueue, self).setUp()
|
||||||
|
|
||||||
|
# Command to test
|
||||||
|
self.cmd = v1_cli.CreateQueue(self.app, None)
|
||||||
|
|
||||||
|
def test_queue_create(self):
|
||||||
|
arglist = ['fake_queue']
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.messaging_client.queue.assert_called_with('fake_queue',
|
||||||
|
force_create=True)
|
@ -43,7 +43,7 @@ class CreateQueue(show.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
client = _get_client(self, parsed_args)
|
client = _get_client(self, parsed_args)
|
||||||
queue_name = parsed_args.queue_name
|
queue_name = parsed_args.queue_name
|
||||||
data = client.queue(queue_name)
|
data = client.queue(queue_name, force_create=True)
|
||||||
columns = ('Name',)
|
columns = ('Name',)
|
||||||
return columns, utils.get_item_properties(data, columns)
|
return columns, utils.get_item_properties(data, columns)
|
||||||
|
|
||||||
|
@ -23,7 +23,20 @@ from zaqarclient.queues.v1 import message
|
|||||||
|
|
||||||
class Queue(object):
|
class Queue(object):
|
||||||
|
|
||||||
def __init__(self, client, name, auto_create=True):
|
def __init__(self, client, name, auto_create=True, force_create=False):
|
||||||
|
"""Initialize queue object
|
||||||
|
|
||||||
|
:param client: The client object of Zaqar.
|
||||||
|
:type client: `object`
|
||||||
|
:param name: Name of the queue.
|
||||||
|
:type name: `six.string_type`
|
||||||
|
:param auto_create: If create the queue automatically in database.
|
||||||
|
:type auto_create: `boolean`
|
||||||
|
:param force_create: If create the queue and skip the API version
|
||||||
|
check, which is useful for command line interface.
|
||||||
|
:type force_create: `boolean`
|
||||||
|
:returns: The queue object.
|
||||||
|
"""
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
if name == "":
|
if name == "":
|
||||||
@ -34,7 +47,7 @@ class Queue(object):
|
|||||||
self._metadata = None
|
self._metadata = None
|
||||||
|
|
||||||
if auto_create:
|
if auto_create:
|
||||||
self.ensure_exists()
|
self.ensure_exists(force_create=force_create)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -48,7 +61,7 @@ class Queue(object):
|
|||||||
else:
|
else:
|
||||||
return core.queue_exists(trans, req, self._name)
|
return core.queue_exists(trans, req, self._name)
|
||||||
|
|
||||||
def ensure_exists(self):
|
def ensure_exists(self, force_create=False):
|
||||||
"""Ensures a queue exists
|
"""Ensures a queue exists
|
||||||
|
|
||||||
This method is not race safe,
|
This method is not race safe,
|
||||||
@ -56,7 +69,7 @@ class Queue(object):
|
|||||||
right after it was called.
|
right after it was called.
|
||||||
"""
|
"""
|
||||||
req, trans = self.client._request_and_transport()
|
req, trans = self.client._request_and_transport()
|
||||||
if req.api.is_supported('queue_set_metadata'):
|
if force_create or req.api.is_supported('queue_set_metadata'):
|
||||||
core.queue_create(trans, req, self._name)
|
core.queue_create(trans, req, self._name)
|
||||||
|
|
||||||
def metadata(self, new_meta=None, force_reload=False):
|
def metadata(self, new_meta=None, force_reload=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user