From 4d832e7beb9860419eb00fb6f5a2a454dcd86494 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Mon, 29 Jun 2015 17:15:31 -0400 Subject: [PATCH] Add tests for 'list' and 'show' for volume qos v1 Change-Id: I1b4d998f3ec1bd5cb8dd4c9e0d04fd3b3049e9d7 --- openstackclient/tests/volume/v1/fakes.py | 13 +++ .../tests/volume/v1/test_qos_specs.py | 98 +++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/openstackclient/tests/volume/v1/fakes.py b/openstackclient/tests/volume/v1/fakes.py index 84cfaf31e8..c6b4f0b858 100644 --- a/openstackclient/tests/volume/v1/fakes.py +++ b/openstackclient/tests/volume/v1/fakes.py @@ -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): diff --git a/openstackclient/tests/volume/v1/test_qos_specs.py b/openstackclient/tests/volume/v1/test_qos_specs.py index da7adc32e5..0a5d14e60d 100644 --- a/openstackclient/tests/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/volume/v1/test_qos_specs.py @@ -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()