summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-12-11 20:19:17 +0000
committerGerrit Code Review <review@openstack.org>2015-12-11 20:19:17 +0000
commit5f7a295b52ae5311b625f4fb5c3a70838a2e8104 (patch)
treebf71d1291d5f35b8af18a88398e27240c1e85045 /openstackclient
parenta25222cae5c9ddb64b26714f60b796fc0794581f (diff)
parent185412f28c6eea825760617548e4256ac35003bb (diff)
downloadpython-openstackclient-5f7a295b52ae5311b625f4fb5c3a70838a2e8104.tar.gz
Merge "Router: Add class FakeRouter to test "router xxx" command"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/tests/network/v2/fakes.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index abb88ee4..284a40b7 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -140,3 +140,84 @@ class FakeNetwork(object):
if networks is None:
networks = FakeNetwork.create_networks(count)
return mock.MagicMock(side_effect=networks)
+
+
+class FakeRouter(object):
+ """Fake one or more routers."""
+
+ @staticmethod
+ def create_one_router(attrs={}, methods={}):
+ """Create a fake router.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, name, admin_state_up,
+ status, tenant_id
+ """
+ # Set default attributes.
+ router_attrs = {
+ 'id': 'router-id-' + uuid.uuid4().hex,
+ 'name': 'router-name-' + uuid.uuid4().hex,
+ 'status': 'ACTIVE',
+ 'admin_state_up': True,
+ 'distributed': False,
+ 'ha': False,
+ 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'routes': [],
+ 'external_gateway_info': {},
+ }
+
+ # Overwrite default attributes.
+ router_attrs.update(attrs)
+
+ # Set default methods.
+ router_methods = {}
+
+ # Overwrite default methods.
+ router_methods.update(methods)
+
+ router = fakes.FakeResource(info=copy.deepcopy(router_attrs),
+ methods=copy.deepcopy(router_methods),
+ loaded=True)
+ return router
+
+ @staticmethod
+ def create_routers(attrs={}, methods={}, count=2):
+ """Create multiple fake routers.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of routers to fake
+ :return:
+ A list of FakeResource objects faking the routers
+ """
+ routers = []
+ for i in range(0, count):
+ routers.append(FakeRouter.create_one_router(attrs, methods))
+
+ return routers
+
+ @staticmethod
+ def get_routers(routers=None, count=2):
+ """Get an iterable MagicMock object with a list of faked routers.
+
+ If routers list is provided, then initialize the Mock object with the
+ list. Otherwise create one.
+
+ :param List routers:
+ A list of FakeResource objects faking routers
+ :param int count:
+ The number of routers to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ routers
+ """
+ if routers is None:
+ routers = FakeRouter.create_routers(count)
+ return mock.MagicMock(side_effect=routers)