Merge "Added unit tests for command-line shell"

This commit is contained in:
Jenkins 2015-08-11 08:59:20 +00:00 committed by Gerrit Code Review
commit 38ae6f2b38
3 changed files with 70 additions and 2 deletions

View File

@ -14,6 +14,7 @@
import mock
from ironicclient.common import utils as commonutils
from ironicclient.openstack.common.apiclient import exceptions
from ironicclient.openstack.common import cliutils
from ironicclient.tests.unit import utils
@ -179,3 +180,35 @@ class ChassisShellTest(utils.BaseTestCase):
fields=[['foo', 'bar']])
self.assertRaises(exceptions.CommandError,
c_shell.do_chassis_node_list, client_mock, args)
def test_do_chassis_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
c_shell.do_chassis_create(client_mock, args)
client_mock.chassis.create.assert_called_once_with()
def test_do_chassis_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.chassis = ['chassis_uuid']
c_shell.do_chassis_delete(client_mock, args)
client_mock.chassis.delete.assert_called_once_with('chassis_uuid')
def test_do_chassis_delete_multiple(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.chassis = ['chassis_uuid1', 'chassis_uuid2']
c_shell.do_chassis_delete(client_mock, args)
client_mock.chassis.delete.assert_has_calls([
mock.call('chassis_uuid1'), mock.call('chassis_uuid2')])
def test_do_chassis_update(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.chassis = 'chassis_uuid'
args.op = 'add'
args.attributes = [['arg1=val1', 'arg2=val2']]
c_shell.do_chassis_update(client_mock, args)
patch = commonutils.args_array_to_patch(args.op, args.attributes[0])
client_mock.chassis.update.assert_called_once_with('chassis_uuid',
patch)

View File

@ -55,3 +55,26 @@ class DriverShellTest(utils.BaseTestCase):
client_mock.driver.vendor_passthru.assert_called_once_with(
args.driver_name, args.method, args={},
http_method=args.http_method)
def test_do_driver_properties(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.driver_name = 'driver_name'
d_shell.do_driver_properties(client_mock, args)
client_mock.driver.properties_called_once_with("driver_name")
def test_do_driver_show(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.driver_name = 'fake'
d_shell.do_driver_show(client_mock, args)
client_mock.driver.get.assert_called_once_with('fake')
def test_do_driver_list(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
d_shell.do_driver_list(client_mock, args)
client_mock.driver.list.assert_called_once_with()

View File

@ -147,8 +147,7 @@ class PortShellTest(utils.BaseTestCase):
def test_do_port_list_wrong_sort_key(self):
client_mock = mock.MagicMock()
args = self._get_client_mock_args(sort_key='node_uuid',
detail=False)
args = self._get_client_mock_args(sort_key='node_uuid', detail=False)
self.assertRaises(exceptions.CommandError,
p_shell.do_port_list,
@ -188,3 +187,16 @@ class PortShellTest(utils.BaseTestCase):
self.assertRaises(exceptions.CommandError,
p_shell.do_port_list,
client_mock, args)
def test_do_port_create(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
p_shell.do_port_create(client_mock, args)
client_mock.port.create.assert_called_once_with()
def test_do_port_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
args.port = ['port_uuid']
p_shell.do_port_delete(client_mock, args)
client_mock.port.delete.assert_called_once_with('port_uuid')