summaryrefslogtreecommitdiff
path: root/openstackclient/tests/network
diff options
context:
space:
mode:
authorTang Chen <tangchen@cn.fujitsu.com>2015-12-12 17:19:10 +0800
committerTerry Howe <terrylhowe@gmail.com>2015-12-11 17:52:19 +0000
commit185412f28c6eea825760617548e4256ac35003bb (patch)
treec3bba5ce9cc0195c20a9996cd78d4c054d91c252 /openstackclient/tests/network
parent823ba770e0baafa707c89723c576db060b1b4742 (diff)
downloadpython-openstackclient-185412f28c6eea825760617548e4256ac35003bb.tar.gz
Router: Add class FakeRouter to test "router xxx" command
A unit test class similar to FakeServer, which is able to fake one or more routers. It will be used by the router CRUD patches. Change-Id: I9b87c6c95282902c3a829da51229a35d4265a1e4 Implements: blueprint neutron-client Partial-bug: #1519503
Diffstat (limited to 'openstackclient/tests/network')
-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)