diff options
Diffstat (limited to 'openstackclient/tests/unit')
| -rw-r--r-- | openstackclient/tests/unit/common/test_module.py | 43 | ||||
| -rw-r--r-- | openstackclient/tests/unit/identity/v3/test_project.py | 46 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/fakes.py | 3 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_port.py | 87 |
4 files changed, 141 insertions, 38 deletions
diff --git a/openstackclient/tests/unit/common/test_module.py b/openstackclient/tests/unit/common/test_module.py index eb54dbe0..4b586d3b 100644 --- a/openstackclient/tests/unit/common/test_module.py +++ b/openstackclient/tests/unit/common/test_module.py @@ -26,19 +26,28 @@ from openstackclient.tests.unit import utils # currently == '*client*' module_name_1 = 'fakeclient' module_version_1 = '0.1.2' -MODULE_1 = { - '__version__': module_version_1, -} module_name_2 = 'zlib' module_version_2 = '1.1' -MODULE_2 = { - '__version__': module_version_2, -} + +# module_3 match openstacksdk +module_name_3 = 'openstack' +module_version_3 = '0.9.13' + +# module_4 match sub module of fakeclient +module_name_4 = 'fakeclient.submodule' +module_version_4 = '0.2.2' + +# module_5 match private module +module_name_5 = '_private_module.lib' +module_version_5 = '0.0.1' MODULES = { module_name_1: fakes.FakeModule(module_name_1, module_version_1), module_name_2: fakes.FakeModule(module_name_2, module_version_2), + module_name_3: fakes.FakeModule(module_name_3, module_version_3), + module_name_4: fakes.FakeModule(module_name_4, module_version_4), + module_name_5: fakes.FakeModule(module_name_5, module_version_5), } @@ -105,9 +114,18 @@ class TestModuleList(utils.TestCommand): # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) - # Additional modules may be present, just check our additions + # Output xxxclient and openstacksdk, but not regular module, like: zlib self.assertIn(module_name_1, columns) self.assertIn(module_version_1, data) + self.assertNotIn(module_name_2, columns) + self.assertNotIn(module_version_2, data) + self.assertIn(module_name_3, columns) + self.assertIn(module_version_3, data) + # Filter sub and private modules + self.assertNotIn(module_name_4, columns) + self.assertNotIn(module_version_4, data) + self.assertNotIn(module_name_5, columns) + self.assertNotIn(module_version_5, data) def test_module_list_all(self): arglist = [ @@ -123,8 +141,15 @@ class TestModuleList(utils.TestCommand): # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) - # Additional modules may be present, just check our additions + # Output xxxclient, openstacksdk and regular module, like: zlib self.assertIn(module_name_1, columns) - self.assertIn(module_name_2, columns) self.assertIn(module_version_1, data) + self.assertIn(module_name_2, columns) self.assertIn(module_version_2, data) + self.assertIn(module_name_3, columns) + self.assertIn(module_version_3, data) + # Filter sub and private modules + self.assertNotIn(module_name_4, columns) + self.assertNotIn(module_version_4, data) + self.assertNotIn(module_name_5, columns) + self.assertNotIn(module_version_5, data) diff --git a/openstackclient/tests/unit/identity/v3/test_project.py b/openstackclient/tests/unit/identity/v3/test_project.py index 2b898090..b99eaf85 100644 --- a/openstackclient/tests/unit/identity/v3/test_project.py +++ b/openstackclient/tests/unit/identity/v3/test_project.py @@ -14,6 +14,7 @@ # import mock +from mock import call from osc_lib import exceptions from osc_lib import utils @@ -763,8 +764,6 @@ class TestProjectShow(TestProject): def test_project_show(self): - self.projects_mock.get.side_effect = [Exception("Not found"), - self.project] self.projects_mock.get.return_value = self.project arglist = [ @@ -790,11 +789,7 @@ class TestProjectShow(TestProject): # data to be shown. columns, data = self.cmd.take_action(parsed_args) - self.projects_mock.get.assert_called_with( - self.project.id, - parents_as_list=False, - subtree_as_list=False, - ) + self.projects_mock.get.assert_called_once_with(self.project.id) collist = ( 'description', @@ -824,8 +819,6 @@ class TestProjectShow(TestProject): 'parents': [{'project': {'id': self.project.parent_id}}] } ) - self.projects_mock.get.side_effect = [Exception("Not found"), - self.project] self.projects_mock.get.return_value = self.project arglist = [ @@ -849,11 +842,12 @@ class TestProjectShow(TestProject): } columns, data = self.cmd.take_action(parsed_args) - self.projects_mock.get.assert_called_with( - self.project.id, - parents_as_list=True, - subtree_as_list=False, - ) + + self.projects_mock.get.assert_has_calls([call(self.project.id), + call(self.project.id, + parents_as_list=True, + subtree_as_list=False, + )]) collist = ( 'description', @@ -885,8 +879,6 @@ class TestProjectShow(TestProject): 'subtree': [{'project': {'id': 'children-id'}}] } ) - self.projects_mock.get.side_effect = [Exception("Not found"), - self.project] self.projects_mock.get.return_value = self.project arglist = [ @@ -910,11 +902,11 @@ class TestProjectShow(TestProject): } columns, data = self.cmd.take_action(parsed_args) - self.projects_mock.get.assert_called_with( - self.project.id, - parents_as_list=False, - subtree_as_list=True, - ) + self.projects_mock.get.assert_has_calls([call(self.project.id), + call(self.project.id, + parents_as_list=False, + subtree_as_list=True, + )]) collist = ( 'description', @@ -947,8 +939,6 @@ class TestProjectShow(TestProject): 'subtree': [{'project': {'id': 'children-id'}}] } ) - self.projects_mock.get.side_effect = [Exception("Not found"), - self.project] self.projects_mock.get.return_value = self.project arglist = [ @@ -973,11 +963,11 @@ class TestProjectShow(TestProject): } columns, data = self.cmd.take_action(parsed_args) - self.projects_mock.get.assert_called_with( - self.project.id, - parents_as_list=True, - subtree_as_list=True, - ) + self.projects_mock.get.assert_has_calls([call(self.project.id), + call(self.project.id, + parents_as_list=True, + subtree_as_list=True, + )]) collist = ( 'description', diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index eb965339..4b266efb 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -470,7 +470,8 @@ class FakePort(object): 'dns_assignment': [{}], 'dns_name': 'dns-name-' + uuid.uuid4().hex, 'extra_dhcp_opts': [{}], - 'fixed_ips': [{}], + 'fixed_ips': [{'ip_address': '10.0.0.3', + 'subnet_id': 'subnet-id-' + uuid.uuid4().hex}], 'id': 'port-id-' + uuid.uuid4().hex, 'mac_address': 'fa:16:3e:a9:4e:72', 'name': 'port-name-' + uuid.uuid4().hex, diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index fc626685..bfffc5c0 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -727,6 +727,92 @@ class TestListPort(TestPort): self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + def test_port_list_fixed_ip_opt_ip_address(self): + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "ip-address=%s" % ip_address, + ] + verifylist = [ + ('fixed_ip', [{'ip-address': ip_address}]) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ip_opt_subnet_id(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + arglist = [ + '--fixed-ip', "subnet=%s" % subnet_id, + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ip_opts(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "subnet=%s,ip-address=%s" % (subnet_id, + ip_address) + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id, + 'ip-address': ip_address}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id, + 'ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_port_list_fixed_ips(self): + subnet_id = self._ports[0].fixed_ips[0]['subnet_id'] + ip_address = self._ports[0].fixed_ips[0]['ip_address'] + arglist = [ + '--fixed-ip', "subnet=%s" % subnet_id, + '--fixed-ip', "ip-address=%s" % ip_address, + ] + verifylist = [ + ('fixed_ip', [{'subnet': subnet_id}, + {'ip-address': ip_address}]) + ] + + self.fake_subnet = network_fakes.FakeSubnet.create_one_subnet( + {'id': subnet_id}) + self.network.find_subnet = mock.Mock(return_value=self.fake_subnet) + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + self.network.ports.assert_called_once_with(**{ + 'fixed_ips': ['subnet_id=%s' % subnet_id, + 'ip_address=%s' % ip_address]}) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + def test_list_port_with_long(self): arglist = [ '--long', @@ -801,6 +887,7 @@ class TestSetPort(TestPort): arglist = [ '--fixed-ip', 'ip-address=10.0.0.11', self._port.name, + '--no-fixed-ip', ] verifylist = [ ('fixed_ip', [{'ip-address': '10.0.0.11'}]), |
