Add tests for 'list' and 'show' for volume qos v1

Change-Id: I1b4d998f3ec1bd5cb8dd4c9e0d04fd3b3049e9d7
This commit is contained in:
David Moreau Simard 2015-06-29 17:15:31 -04:00
parent 1051a46944
commit 4d832e7beb
2 changed files with 111 additions and 0 deletions

View File

@ -95,6 +95,11 @@ qos_specs = {
'foo': 'bar',
'iops': '9001'
}
qos_association = {
'association_type': 'volume_type',
'name': type_name,
'id': type_id
}
QOS = {
'id': qos_id,
@ -115,6 +120,14 @@ QOS_WITH_SPECS = {
'specs': qos_specs
}
QOS_WITH_ASSOCIATIONS = {
'id': qos_id,
'consumer': qos_consumer,
'name': qos_name,
'specs': qos_specs,
'associations': [qos_association]
}
class FakeImagev1Client(object):
def __init__(self, **kwargs):

View File

@ -15,6 +15,7 @@
import copy
from openstackclient.common import utils
from openstackclient.tests import fakes
from openstackclient.tests.volume.v1 import fakes as volume_fakes
from openstackclient.volume.v1 import qos_specs
@ -285,6 +286,52 @@ class TestQosDisassociate(TestQos):
self.qos_mock.disassociate_all.assert_called_with(volume_fakes.qos_id)
class TestQosList(TestQos):
def setUp(self):
super(TestQosList, self).setUp()
self.qos_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.QOS_WITH_ASSOCIATIONS),
loaded=True,
)
self.qos_mock.list.return_value = [self.qos_mock.get.return_value]
self.qos_mock.get_associations.return_value = [fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.qos_association),
loaded=True,
)]
# Get the command object to test
self.cmd = qos_specs.ListQos(self.app, None)
def test_qos_list(self):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.qos_mock.list.assert_called()
collist = (
'ID',
'Name',
'Consumer',
'Associations',
'Specs',
)
self.assertEqual(collist, columns)
datalist = ((
volume_fakes.qos_id,
volume_fakes.qos_name,
volume_fakes.qos_consumer,
volume_fakes.type_name,
utils.format_dict(volume_fakes.qos_specs),
), )
self.assertEqual(datalist, tuple(data))
class TestQosSet(TestQos):
def setUp(self):
super(TestQosSet, self).setUp()
@ -316,6 +363,57 @@ class TestQosSet(TestQos):
)
class TestQosShow(TestQos):
def setUp(self):
super(TestQosShow, self).setUp()
self.qos_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.QOS_WITH_ASSOCIATIONS),
loaded=True,
)
self.qos_mock.get_associations.return_value = [fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.qos_association),
loaded=True,
)]
# Get the command object to test
self.cmd = qos_specs.ShowQos(self.app, None)
def test_qos_show(self):
arglist = [
volume_fakes.qos_id
]
verifylist = [
('qos_specs', volume_fakes.qos_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.qos_mock.get.assert_called_with(
volume_fakes.qos_id
)
collist = (
'associations',
'consumer',
'id',
'name',
'specs'
)
self.assertEqual(collist, columns)
datalist = (
volume_fakes.type_name,
volume_fakes.qos_consumer,
volume_fakes.qos_id,
volume_fakes.qos_name,
utils.format_dict(volume_fakes.qos_specs),
)
self.assertEqual(datalist, tuple(data))
class TestQosUnset(TestQos):
def setUp(self):
super(TestQosUnset, self).setUp()