summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-23 18:02:55 +0000
committerGerrit Code Review <review@openstack.org>2016-02-23 18:02:56 +0000
commitc2f5945ef62117771d6cff411d6071052c085d30 (patch)
treefa573e702f658a1fa20a7c0c9c41381768b4dd2e /openstackclient/tests
parentab40add0c6a46bbdbbd7d90764c4ea5076373a64 (diff)
parentdccde70c57baf9266a795a54198238515d7fdda6 (diff)
downloadpython-openstackclient-c2f5945ef62117771d6cff411d6071052c085d30.tar.gz
Merge "Add "security group rule show" command"
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/network/v2/fakes.py14
-rw-r--r--openstackclient/tests/network/v2/test_security_group_rule.py112
2 files changed, 122 insertions, 4 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index c24410e1..b1784b60 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -480,15 +480,13 @@ class FakeSecurityGroupRule(object):
:param Dictionary methods:
A dictionary with all methods
:return:
- A FakeResource object, with id, name, etc.
+ A FakeResource object, with id, etc.
"""
# Set default attributes.
security_group_rule_attrs = {
- 'description': 'security-group-rule-desc-' + uuid.uuid4().hex,
'direction': 'ingress',
'ethertype': 'IPv4',
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
- 'name': 'security-group-rule-name-' + uuid.uuid4().hex,
'port_range_max': None,
'port_range_min': None,
'protocol': None,
@@ -502,7 +500,11 @@ class FakeSecurityGroupRule(object):
security_group_rule_attrs.update(attrs)
# Set default methods.
- security_group_rule_methods = {}
+ security_group_rule_methods = {
+ 'keys': ['direction', 'ethertype', 'id', 'port_range_max',
+ 'port_range_min', 'protocol', 'remote_group_id',
+ 'remote_ip_prefix', 'security_group_id', 'tenant_id'],
+ }
# Overwrite default methods.
security_group_rule_methods.update(methods)
@@ -511,6 +513,10 @@ class FakeSecurityGroupRule(object):
info=copy.deepcopy(security_group_rule_attrs),
methods=copy.deepcopy(security_group_rule_methods),
loaded=True)
+
+ # Set attributes with special mappings.
+ security_group_rule.project_id = security_group_rule_attrs['tenant_id']
+
return security_group_rule
@staticmethod
diff --git a/openstackclient/tests/network/v2/test_security_group_rule.py b/openstackclient/tests/network/v2/test_security_group_rule.py
index c6ef3884..db15d0e2 100644
--- a/openstackclient/tests/network/v2/test_security_group_rule.py
+++ b/openstackclient/tests/network/v2/test_security_group_rule.py
@@ -11,11 +11,14 @@
# under the License.
#
+import copy
import mock
from openstackclient.network.v2 import security_group_rule
from openstackclient.tests.compute.v2 import fakes as compute_fakes
+from openstackclient.tests import fakes
from openstackclient.tests.network.v2 import fakes as network_fakes
+from openstackclient.tests import utils as tests_utils
class TestSecurityGroupRuleNetwork(network_fakes.TestNetworkV2):
@@ -98,3 +101,112 @@ class TestDeleteSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
self.compute.security_group_rules.delete.assert_called_with(
self._security_group_rule.id)
self.assertIsNone(result)
+
+
+class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
+
+ # The security group rule to be shown.
+ _security_group_rule = \
+ network_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
+
+ columns = (
+ 'direction',
+ 'ethertype',
+ 'id',
+ 'port_range_max',
+ 'port_range_min',
+ 'project_id',
+ 'protocol',
+ 'remote_group_id',
+ 'remote_ip_prefix',
+ 'security_group_id',
+ )
+
+ data = (
+ _security_group_rule.direction,
+ _security_group_rule.ethertype,
+ _security_group_rule.id,
+ _security_group_rule.port_range_max,
+ _security_group_rule.port_range_min,
+ _security_group_rule.project_id,
+ _security_group_rule.protocol,
+ _security_group_rule.remote_group_id,
+ _security_group_rule.remote_ip_prefix,
+ _security_group_rule.security_group_id,
+ )
+
+ def setUp(self):
+ super(TestShowSecurityGroupRuleNetwork, self).setUp()
+
+ self.network.find_security_group_rule = mock.Mock(
+ return_value=self._security_group_rule)
+
+ # Get the command object to test
+ self.cmd = security_group_rule.ShowSecurityGroupRule(
+ self.app, self.namespace)
+
+ def test_show_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_show_all_options(self):
+ arglist = [
+ self._security_group_rule.id,
+ ]
+ verifylist = [
+ ('rule', self._security_group_rule.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.find_security_group_rule.assert_called_with(
+ self._security_group_rule.id, ignore_missing=False)
+ self.assertEqual(tuple(self.columns), columns)
+ self.assertEqual(self.data, data)
+
+
+class TestShowSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
+
+ # The security group rule to be shown.
+ _security_group_rule = \
+ compute_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
+
+ columns, data = \
+ security_group_rule._format_security_group_rule_show(
+ _security_group_rule._info)
+
+ def setUp(self):
+ super(TestShowSecurityGroupRuleCompute, self).setUp()
+
+ self.app.client_manager.network_endpoint_enabled = False
+
+ # 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]
+
+ # Get the command object to test
+ self.cmd = security_group_rule.ShowSecurityGroupRule(self.app, None)
+
+ def test_show_no_options(self):
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, [], [])
+
+ def test_show_all_options(self):
+ arglist = [
+ self._security_group_rule.id,
+ ]
+ verifylist = [
+ ('rule', self._security_group_rule.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.compute.security_groups.list.assert_called_with()
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)