summaryrefslogtreecommitdiff
path: root/openstackclient/tests/network/v2/fakes.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-18 09:03:27 +0000
committerGerrit Code Review <review@openstack.org>2016-02-18 09:03:27 +0000
commitbb153b705a14c2fbf9b3a0936f8a7ca4c56895e3 (patch)
treea22e15cedb191346286f8c0cd01f93a65d63dabb /openstackclient/tests/network/v2/fakes.py
parent272ac55776dcc945cdad3d6d38e3356e0c099e45 (diff)
parenta29c9732d7434902fd36e0417e16bb760875591f (diff)
downloadpython-openstackclient-bb153b705a14c2fbf9b3a0936f8a7ca4c56895e3.tar.gz
Merge "Refactor security group rule delete to use SDK"
Diffstat (limited to 'openstackclient/tests/network/v2/fakes.py')
-rw-r--r--openstackclient/tests/network/v2/fakes.py74
1 files changed, 61 insertions, 13 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 77720ee0..8591a09a 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -462,28 +462,76 @@ class FakeSecurityGroup(object):
security_groups = []
for i in range(0, count):
security_groups.append(
- FakeRouter.create_one_security_group(attrs, methods))
+ FakeSecurityGroup.create_one_security_group(attrs, methods))
return security_groups
+
+class FakeSecurityGroupRule(object):
+ """Fake one or more security group rules."""
+
@staticmethod
- def get_security_groups(security_groups=None, count=2):
- """Get an iterable MagicMock object with a list of faked security groups.
+ def create_one_security_group_rule(attrs={}, methods={}):
+ """Create a fake security group rule.
- If security group list is provided, then initialize the Mock object
- with the list. Otherwise create one.
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, name, 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,
+ 'remote_group_id': 'remote-security-group-id-' + uuid.uuid4().hex,
+ 'remote_ip_prefix': None,
+ 'security_group_id': 'security-group-id-' + uuid.uuid4().hex,
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes.
+ security_group_rule_attrs.update(attrs)
- :param List security groups:
- A list of FakeResource objects faking security groups
+ # Set default methods.
+ security_group_rule_methods = {}
+
+ # Overwrite default methods.
+ security_group_rule_methods.update(methods)
+
+ security_group_rule = fakes.FakeResource(
+ info=copy.deepcopy(security_group_rule_attrs),
+ methods=copy.deepcopy(security_group_rule_methods),
+ loaded=True)
+ return security_group_rule
+
+ @staticmethod
+ def create_security_group_rules(attrs={}, methods={}, count=2):
+ """Create multiple fake security group rules.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
:param int count:
- The number of security groups to fake
+ The number of security group rules to fake
:return:
- An iterable Mock object with side_effect set to a list of faked
- security groups
+ A list of FakeResource objects faking the security group rules
"""
- if security_groups is None:
- security_groups = FakeRouter.create_security_groups(count)
- return mock.MagicMock(side_effect=security_groups)
+ security_group_rules = []
+ for i in range(0, count):
+ security_group_rules.append(
+ FakeSecurityGroupRule.create_one_security_group_rule(
+ attrs, methods))
+
+ return security_group_rules
class FakeSubnet(object):