diff options
Diffstat (limited to 'openstackclient/tests/unit/network')
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_security_group_compute.py | 200 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py | 172 |
2 files changed, 195 insertions, 177 deletions
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_compute.py index 2fd44188..db9831bb 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_compute.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_compute.py @@ -31,10 +31,14 @@ class TestSecurityGroupCompute(compute_fakes.TestComputev2): self.compute = self.app.client_manager.compute +@mock.patch( + 'openstackclient.api.compute_v2.APIv2.security_group_create' +) class TestCreateSecurityGroupCompute(TestSecurityGroupCompute): project = identity_fakes.FakeProject.create_one_project() domain = identity_fakes.FakeDomain.create_one_domain() + # The security group to be shown. _security_group = \ compute_fakes.FakeSecurityGroup.create_one_security_group() @@ -48,10 +52,10 @@ class TestCreateSecurityGroupCompute(TestSecurityGroupCompute): ) data = ( - _security_group.description, - _security_group.id, - _security_group.name, - _security_group.tenant_id, + _security_group['description'], + _security_group['id'], + _security_group['name'], + _security_group['tenant_id'], '', ) @@ -60,61 +64,57 @@ class TestCreateSecurityGroupCompute(TestSecurityGroupCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.create.return_value = self._security_group - # Get the command object to test self.cmd = security_group.CreateSecurityGroup(self.app, None) - def test_create_no_options(self): + def test_security_group_create_no_options(self, sg_mock): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_create_network_options(self): - arglist = [ - '--project', self.project.name, - '--project-domain', self.domain.name, - self._security_group.name, - ] - self.assertRaises(tests_utils.ParserException, - self.check_parser, self.cmd, arglist, []) - - def test_create_min_options(self): + def test_security_group_create_min_options(self, sg_mock): + sg_mock.return_value = self._security_group arglist = [ - self._security_group.name, + self._security_group['name'], ] verifylist = [ - ('name', self._security_group.name), + ('name', self._security_group['name']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.create.assert_called_once_with( - self._security_group.name, - self._security_group.name) + sg_mock.assert_called_once_with( + self._security_group['name'], + self._security_group['name'], + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) - def test_create_all_options(self): + def test_security_group_create_all_options(self, sg_mock): + sg_mock.return_value = self._security_group arglist = [ - '--description', self._security_group.description, - self._security_group.name, + '--description', self._security_group['description'], + self._security_group['name'], ] verifylist = [ - ('description', self._security_group.description), - ('name', self._security_group.name), + ('description', self._security_group['description']), + ('name', self._security_group['name']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.create.assert_called_once_with( - self._security_group.name, - self._security_group.description) + sg_mock.assert_called_once_with( + self._security_group['name'], + self._security_group['description'], + ) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) +@mock.patch( + 'openstackclient.api.compute_v2.APIv2.security_group_delete' +) class TestDeleteSecurityGroupCompute(TestSecurityGroupCompute): # The security groups to be deleted. @@ -126,9 +126,7 @@ class TestDeleteSecurityGroupCompute(TestSecurityGroupCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.delete = mock.Mock(return_value=None) - - self.compute.security_groups.get = ( + self.compute.api.security_group_find = ( compute_fakes.FakeSecurityGroup.get_security_groups( self._security_groups) ) @@ -136,27 +134,30 @@ class TestDeleteSecurityGroupCompute(TestSecurityGroupCompute): # Get the command object to test self.cmd = security_group.DeleteSecurityGroup(self.app, None) - def test_security_group_delete(self): + def test_security_group_delete(self, sg_mock): + sg_mock.return_value = mock.Mock(return_value=None) arglist = [ - self._security_groups[0].id, + self._security_groups[0]['id'], ] verifylist = [ - ('group', [self._security_groups[0].id]), + ('group', [self._security_groups[0]['id']]), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.compute.security_groups.delete.assert_called_once_with( - self._security_groups[0].id) + sg_mock.assert_called_once_with( + self._security_groups[0]['id'], + ) self.assertIsNone(result) - def test_multi_security_groups_delete(self): + def test_security_group_multi_delete(self, sg_mock): + sg_mock.return_value = mock.Mock(return_value=None) arglist = [] verifylist = [] for s in self._security_groups: - arglist.append(s.id) + arglist.append(s['id']) verifylist = [ ('group', arglist), ] @@ -166,43 +167,39 @@ class TestDeleteSecurityGroupCompute(TestSecurityGroupCompute): calls = [] for s in self._security_groups: - calls.append(call(s.id)) - self.compute.security_groups.delete.assert_has_calls(calls) + calls.append(call(s['id'])) + sg_mock.assert_has_calls(calls) self.assertIsNone(result) - def test_multi_security_groups_delete_with_exception(self): + def test_security_group_multi_delete_with_exception(self, sg_mock): + sg_mock.return_value = mock.Mock(return_value=None) + sg_mock.side_effect = ([ + mock.Mock(return_value=None), + exceptions.CommandError, + ]) arglist = [ - self._security_groups[0].id, + self._security_groups[0]['id'], 'unexist_security_group', ] verifylist = [ ('group', - [self._security_groups[0].id, 'unexist_security_group']), + [self._security_groups[0]['id'], 'unexist_security_group']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - find_mock_result = [self._security_groups[0], exceptions.CommandError] - self.compute.security_groups.get = ( - mock.Mock(side_effect=find_mock_result) - ) - self.compute.security_groups.find.side_effect = ( - exceptions.NotFound(None)) - try: self.cmd.take_action(parsed_args) self.fail('CommandError should be raised.') except exceptions.CommandError as e: self.assertEqual('1 of 2 groups failed to delete.', str(e)) - self.compute.security_groups.get.assert_any_call( - self._security_groups[0].id) - self.compute.security_groups.get.assert_any_call( - 'unexist_security_group') - self.compute.security_groups.delete.assert_called_once_with( - self._security_groups[0].id - ) + sg_mock.assert_any_call(self._security_groups[0]['id']) + sg_mock.assert_any_call('unexist_security_group') +@mock.patch( + 'openstackclient.api.compute_v2.APIv2.security_group_list' +) class TestListSecurityGroupCompute(TestSecurityGroupCompute): # The security group to be listed. @@ -224,29 +221,29 @@ class TestListSecurityGroupCompute(TestSecurityGroupCompute): data = [] for grp in _security_groups: data.append(( - grp.id, - grp.name, - grp.description, + grp['id'], + grp['name'], + grp['description'], )) data_all_projects = [] for grp in _security_groups: data_all_projects.append(( - grp.id, - grp.name, - grp.description, - grp.tenant_id, + grp['id'], + grp['name'], + grp['description'], + grp['tenant_id'], )) def setUp(self): super(TestListSecurityGroupCompute, self).setUp() self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.list.return_value = self._security_groups # Get the command object to test self.cmd = security_group.ListSecurityGroup(self.app, None) - def test_security_group_list_no_options(self): + def test_security_group_list_no_options(self, sg_mock): + sg_mock.return_value = self._security_groups arglist = [] verifylist = [ ('all_projects', False), @@ -256,11 +253,12 @@ class TestListSecurityGroupCompute(TestSecurityGroupCompute): columns, data = self.cmd.take_action(parsed_args) kwargs = {'search_opts': {'all_tenants': False}} - self.compute.security_groups.list.assert_called_once_with(**kwargs) + sg_mock.assert_called_once_with(**kwargs) self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) - def test_security_group_list_all_projects(self): + def test_security_group_list_all_projects(self, sg_mock): + sg_mock.return_value = self._security_groups arglist = [ '--all-projects', ] @@ -272,11 +270,14 @@ class TestListSecurityGroupCompute(TestSecurityGroupCompute): columns, data = self.cmd.take_action(parsed_args) kwargs = {'search_opts': {'all_tenants': True}} - self.compute.security_groups.list.assert_called_once_with(**kwargs) + sg_mock.assert_called_once_with(**kwargs) self.assertEqual(self.columns_all_projects, columns) self.assertEqual(self.data_all_projects, list(data)) +@mock.patch( + 'openstackclient.api.compute_v2.APIv2.security_group_set' +) class TestSetSecurityGroupCompute(TestSecurityGroupCompute): # The security group to be set. @@ -288,54 +289,54 @@ class TestSetSecurityGroupCompute(TestSecurityGroupCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.update = mock.Mock(return_value=None) - - self.compute.security_groups.get = mock.Mock( + self.compute.api.security_group_find = mock.Mock( return_value=self._security_group) # Get the command object to test self.cmd = security_group.SetSecurityGroup(self.app, None) - def test_set_no_options(self): + def test_security_group_set_no_options(self, sg_mock): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_set_no_updates(self): + def test_security_group_set_no_updates(self, sg_mock): + sg_mock.return_value = mock.Mock(return_value=None) arglist = [ - self._security_group.name, + self._security_group['name'], ] verifylist = [ - ('group', self._security_group.name), + ('group', self._security_group['name']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.compute.security_groups.update.assert_called_once_with( + sg_mock.assert_called_once_with( self._security_group, - self._security_group.name, - self._security_group.description + self._security_group['name'], + self._security_group['description'], ) self.assertIsNone(result) - def test_set_all_options(self): - new_name = 'new-' + self._security_group.name - new_description = 'new-' + self._security_group.description + def test_security_group_set_all_options(self, sg_mock): + sg_mock.return_value = mock.Mock(return_value=None) + new_name = 'new-' + self._security_group['name'] + new_description = 'new-' + self._security_group['description'] arglist = [ '--name', new_name, '--description', new_description, - self._security_group.name, + self._security_group['name'], ] verifylist = [ ('description', new_description), - ('group', self._security_group.name), + ('group', self._security_group['name']), ('name', new_name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) result = self.cmd.take_action(parsed_args) - self.compute.security_groups.update.assert_called_once_with( + sg_mock.assert_called_once_with( self._security_group, new_name, new_description @@ -343,6 +344,9 @@ class TestSetSecurityGroupCompute(TestSecurityGroupCompute): self.assertIsNone(result) +@mock.patch( + 'openstackclient.api.compute_v2.APIv2.security_group_find' +) class TestShowSecurityGroupCompute(TestSecurityGroupCompute): # The security group rule to be shown with the group. @@ -364,10 +368,10 @@ class TestShowSecurityGroupCompute(TestSecurityGroupCompute): ) data = ( - _security_group.description, - _security_group.id, - _security_group.name, - _security_group.tenant_id, + _security_group['description'], + _security_group['id'], + _security_group['name'], + _security_group['tenant_id'], security_group._format_compute_security_group_rules( [_security_group_rule._info]), ) @@ -377,27 +381,25 @@ class TestShowSecurityGroupCompute(TestSecurityGroupCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.get.return_value = self._security_group - # Get the command object to test self.cmd = security_group.ShowSecurityGroup(self.app, None) - def test_show_no_options(self): + def test_security_group_show_no_options(self, sg_mock): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_show_all_options(self): + def test_security_group_show_all_options(self, sg_mock): + sg_mock.return_value = self._security_group arglist = [ - self._security_group.id, + self._security_group['id'], ] verifylist = [ - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.get.assert_called_once_with( - self._security_group.id) + sg_mock.assert_called_once_with(self._security_group['id']) self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py index 7833c0d9..06a7a25d 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py @@ -11,7 +11,6 @@ # under the License. # -import copy import mock from mock import call @@ -20,7 +19,6 @@ from osc_lib import exceptions from openstackclient.network import utils as network_utils from openstackclient.network.v2 import security_group_rule from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes -from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes from openstackclient.tests.unit import utils as tests_utils @@ -38,6 +36,7 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): project = identity_fakes.FakeProject.create_one_project() domain = identity_fakes.FakeDomain.create_one_domain() + # The security group rule to be created. _security_group_rule = None @@ -61,51 +60,53 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.get.return_value = self._security_group + self.compute.api.security_group_find = mock.Mock( + return_value=self._security_group, + ) # Get the command object to test self.cmd = security_group_rule.CreateSecurityGroupRule(self.app, None) - def test_create_no_options(self): + def test_security_group_rule_create_no_options(self): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_create_all_source_options(self): + def test_security_group_rule_create_all_source_options(self): arglist = [ '--src-ip', '10.10.0.0/24', - '--src-group', self._security_group.id, - self._security_group.id, + '--src-group', self._security_group['id'], + self._security_group['id'], ] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) - def test_create_all_remote_options(self): + def test_security_group_rule_create_all_remote_options(self): arglist = [ '--remote-ip', '10.10.0.0/24', - '--remote-group', self._security_group.id, - self._security_group.id, + '--remote-group', self._security_group['id'], + self._security_group['id'], ] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) - def test_create_bad_protocol(self): + def test_security_group_rule_create_bad_protocol(self): arglist = [ '--protocol', 'foo', - self._security_group.id, + self._security_group['id'], ] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) - def test_create_all_protocol_options(self): + def test_security_group_rule_create_all_protocol_options(self): arglist = [ '--protocol', 'tcp', '--proto', 'tcp', - self._security_group.id, + self._security_group['id'], ] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) - def test_create_network_options(self): + def test_security_group_rule_create_network_options(self): arglist = [ '--ingress', '--ethertype', 'IPv4', @@ -113,30 +114,32 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): '--icmp-code', '11', '--project', self.project.name, '--project-domain', self.domain.name, - self._security_group.id, + self._security_group['id'], ] self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, arglist, []) - def test_create_default_rule(self): + def test_security_group_rule_create_default_rule(self): expected_columns, expected_data = self._setup_security_group_rule() dst_port = str(self._security_group_rule.from_port) + ':' + \ str(self._security_group_rule.to_port) arglist = [ '--dst-port', dst_port, - self._security_group.id, + self._security_group['id'], ] verifylist = [ ('dst_port', (self._security_group_rule.from_port, self._security_group_rule.to_port)), - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, @@ -146,71 +149,75 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.assertEqual(expected_columns, columns) self.assertEqual(expected_data, data) - def test_create_source_group(self): + def test_security_group_rule_create_source_group(self): expected_columns, expected_data = self._setup_security_group_rule({ 'from_port': 22, 'to_port': 22, - 'group': {'name': self._security_group.name}, + 'group': {'name': self._security_group['name']}, }) arglist = [ '--dst-port', str(self._security_group_rule.from_port), - '--src-group', self._security_group.name, - self._security_group.id, + '--src-group', self._security_group['name'], + self._security_group['id'], ] verifylist = [ ('dst_port', (self._security_group_rule.from_port, self._security_group_rule.to_port)), - ('src_group', self._security_group.name), - ('group', self._security_group.id), + ('src_group', self._security_group['name']), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, self._security_group_rule.ip_range['cidr'], - self._security_group.id, + self._security_group['id'], ) self.assertEqual(expected_columns, columns) self.assertEqual(expected_data, data) - def test_create_remote_group(self): + def test_security_group_rule_create_remote_group(self): expected_columns, expected_data = self._setup_security_group_rule({ 'from_port': 22, 'to_port': 22, - 'group': {'name': self._security_group.name}, + 'group': {'name': self._security_group['name']}, }) arglist = [ '--dst-port', str(self._security_group_rule.from_port), - '--remote-group', self._security_group.name, - self._security_group.id, + '--remote-group', self._security_group['name'], + self._security_group['id'], ] verifylist = [ ('dst_port', (self._security_group_rule.from_port, self._security_group_rule.to_port)), - ('remote_group', self._security_group.name), - ('group', self._security_group.id), + ('remote_group', self._security_group['name']), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, self._security_group_rule.ip_range['cidr'], - self._security_group.id, + self._security_group['id'], ) self.assertEqual(expected_columns, columns) self.assertEqual(expected_data, data) - def test_create_source_ip(self): + def test_security_group_rule_create_source_ip(self): expected_columns, expected_data = self._setup_security_group_rule({ 'ip_protocol': 'icmp', 'from_port': -1, @@ -220,19 +227,21 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): arglist = [ '--protocol', self._security_group_rule.ip_protocol, '--src-ip', self._security_group_rule.ip_range['cidr'], - self._security_group.id, + self._security_group['id'], ] verifylist = [ ('protocol', self._security_group_rule.ip_protocol), ('src_ip', self._security_group_rule.ip_range['cidr']), - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, @@ -242,7 +251,7 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.assertEqual(expected_columns, columns) self.assertEqual(expected_data, data) - def test_create_remote_ip(self): + def test_security_group_rule_create_remote_ip(self): expected_columns, expected_data = self._setup_security_group_rule({ 'ip_protocol': 'icmp', 'from_port': -1, @@ -252,19 +261,21 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): arglist = [ '--protocol', self._security_group_rule.ip_protocol, '--remote-ip', self._security_group_rule.ip_range['cidr'], - self._security_group.id, + self._security_group['id'], ] verifylist = [ ('protocol', self._security_group_rule.ip_protocol), ('remote_ip', self._security_group_rule.ip_range['cidr']), - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, @@ -274,7 +285,7 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.assertEqual(expected_columns, columns) self.assertEqual(expected_data, data) - def test_create_proto_option(self): + def test_security_group_rule_create_proto_option(self): expected_columns, expected_data = self._setup_security_group_rule({ 'ip_protocol': 'icmp', 'from_port': -1, @@ -284,20 +295,22 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): arglist = [ '--proto', self._security_group_rule.ip_protocol, '--src-ip', self._security_group_rule.ip_range['cidr'], - self._security_group.id, + self._security_group['id'], ] verifylist = [ ('proto', self._security_group_rule.ip_protocol), ('protocol', None), ('src_ip', self._security_group_rule.ip_range['cidr']), - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) + # TODO(dtroyer): save this for the security group rule changes + # self.compute.api.security_group_rule_create.assert_called_once_with( self.compute.security_group_rules.create.assert_called_once_with( - self._security_group.id, + self._security_group['id'], self._security_group_rule.ip_protocol, self._security_group_rule.from_port, self._security_group_rule.to_port, @@ -338,7 +351,7 @@ class TestDeleteSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self._security_group_rules[0].id) self.assertIsNone(result) - def test_multi_security_group_rules_delete(self): + def test_security_group_rule_multi_delete(self): arglist = [] verifylist = [] @@ -357,7 +370,7 @@ class TestDeleteSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.compute.security_group_rules.delete.assert_has_calls(calls) self.assertIsNone(result) - def test_multi_security_group_rules_delete_with_exception(self): + def test_security_group_rule_multi_delete_with_exception(self): arglist = [ self._security_group_rules[0].id, 'unexist_rule', @@ -397,7 +410,7 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): 'ip_protocol': 'tcp', 'from_port': 80, 'to_port': 80, - 'group': {'name': _security_group.name}, + 'group': {'name': _security_group['name']}, }) _security_group_rule_icmp = \ compute_fakes.FakeSecurityGroupRule.create_one_security_group_rule({ @@ -405,10 +418,12 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): 'from_port': -1, 'to_port': -1, 'ip_range': {'cidr': '10.0.2.0/24'}, - 'group': {'name': _security_group.name}, + 'group': {'name': _security_group['name']}, }) - _security_group.rules = [_security_group_rule_tcp._info, - _security_group_rule_icmp._info] + _security_group['rules'] = [ + _security_group_rule_tcp._info, + _security_group_rule_icmp._info, + ] expected_columns_with_group = ( 'ID', @@ -422,7 +437,7 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): expected_data_with_group = [] expected_data_no_group = [] - for _security_group_rule in _security_group.rules: + for _security_group_rule in _security_group['rules']: rule = network_utils.transform_compute_security_group_rule( _security_group_rule ) @@ -443,41 +458,43 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): self.app.client_manager.network_endpoint_enabled = False - self.compute.security_groups.get.return_value = \ - self._security_group - self.compute.security_groups.list.return_value = \ - [self._security_group] + self.compute.api.security_group_find = mock.Mock( + return_value=self._security_group, + ) + self.compute.api.security_group_list = mock.Mock( + return_value=[self._security_group], + ) # Get the command object to test self.cmd = security_group_rule.ListSecurityGroupRule(self.app, None) - def test_list_default(self): + def test_security_group_rule_list_default(self): parsed_args = self.check_parser(self.cmd, [], []) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.list.assert_called_once_with( + self.compute.api.security_group_list.assert_called_once_with( search_opts={'all_tenants': False} ) self.assertEqual(self.expected_columns_no_group, columns) self.assertEqual(self.expected_data_no_group, list(data)) - def test_list_with_group(self): + def test_security_group_rule_list_with_group(self): arglist = [ - self._security_group.id, + self._security_group['id'], ] verifylist = [ - ('group', self._security_group.id), + ('group', self._security_group['id']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.get.assert_called_once_with( - self._security_group.id + self.compute.api.security_group_find.assert_called_once_with( + self._security_group['id'] ) self.assertEqual(self.expected_columns_with_group, columns) self.assertEqual(self.expected_data_with_group, list(data)) - def test_list_all_projects(self): + def test_security_group_rule_list_all_projects(self): arglist = [ '--all-projects', ] @@ -487,13 +504,13 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.list.assert_called_once_with( + self.compute.api.security_group_list.assert_called_once_with( search_opts={'all_tenants': True} ) self.assertEqual(self.expected_columns_no_group, columns) self.assertEqual(self.expected_data_no_group, list(data)) - def test_list_with_ignored_options(self): + def test_security_group_rule_list_with_ignored_options(self): arglist = [ '--long', ] @@ -503,7 +520,7 @@ class TestListSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.list.assert_called_once_with( + self.compute.api.security_group_list.assert_called_once_with( search_opts={'all_tenants': False} ) self.assertEqual(self.expected_columns_no_group, columns) @@ -527,20 +544,19 @@ class TestShowSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): # Build a security group fake customized for this test. security_group_rules = [self._security_group_rule._info] - security_group = fakes.FakeResource( - info=copy.deepcopy({'rules': security_group_rules}), - loaded=True) - security_group.rules = security_group_rules - self.compute.security_groups.list.return_value = [security_group] + security_group = {'rules': security_group_rules} + self.compute.api.security_group_list = mock.Mock( + return_value=[security_group], + ) # Get the command object to test self.cmd = security_group_rule.ShowSecurityGroupRule(self.app, None) - def test_show_no_options(self): + def test_security_group_rule_show_no_options(self): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_show_all_options(self): + def test_security_group_rule_show_all_options(self): arglist = [ self._security_group_rule.id, ] @@ -551,6 +567,6 @@ class TestShowSecurityGroupRuleCompute(TestSecurityGroupRuleCompute): columns, data = self.cmd.take_action(parsed_args) - self.compute.security_groups.list.assert_called_once_with() + self.compute.api.security_group_list.assert_called_once_with() self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) |
