summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute/v2/fakes.py
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-05-25 13:06:39 +0800
committerTang Chen <chen.tang@easystack.cn>2016-05-25 13:06:39 +0800
commit8ce5d90136363322b33f78b705670eeadd76f1b1 (patch)
treed689b91d95987e42b50662493aabe887fa703bba /openstackclient/tests/compute/v2/fakes.py
parente45b1c63f40b4e94e43bec71b44f00e4143fe9af (diff)
downloadpython-openstackclient-8ce5d90136363322b33f78b705670eeadd76f1b1.tar.gz
Refactor service unit tests
Add a FakeService class, and refactor service unit tests to use this class. Change-Id: I650ad83386a58205ebe42274d2bf2f508436bfa6
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py59
1 files changed, 48 insertions, 11 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index 70fc386f..62a46b1d 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -76,17 +76,6 @@ QUOTA = {
QUOTA_columns = tuple(sorted(QUOTA))
QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
-service_host = 'host_test'
-service_binary = 'compute_test'
-service_status = 'enabled'
-service_disabled_reason = 'earthquake'
-SERVICE = {
- 'host': service_host,
- 'binary': service_binary,
- 'status': service_status,
- 'disabled_reason': service_disabled_reason,
-}
-
class FakeAggregate(object):
"""Fake one aggregate."""
@@ -523,6 +512,54 @@ class FakeServer(object):
return mock.MagicMock(side_effect=servers)
+class FakeService(object):
+ """Fake one or more services."""
+
+ @staticmethod
+ def create_one_service(attrs=None):
+ """Create a fake service.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object, with id, name, ram, vcpus, properties
+ """
+ attrs = attrs or {}
+
+ # Set default attributes.
+ service_info = {
+ 'host': 'host-' + uuid.uuid4().hex,
+ 'binary': 'binary-' + uuid.uuid4().hex,
+ 'status': 'enabled',
+ 'disabled_reason': 'earthquake',
+ }
+
+ # Overwrite default attributes.
+ service_info.update(attrs)
+
+ service = fakes.FakeResource(info=copy.deepcopy(service_info),
+ loaded=True)
+
+ return service
+
+ @staticmethod
+ def create_services(attrs=None, count=2):
+ """Create multiple fake services.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of services to fake
+ :return:
+ A list of FakeResource objects faking the services
+ """
+ services = []
+ for i in range(0, count):
+ services.append(FakeService.create_one_service(attrs))
+
+ return services
+
+
class FakeFlavor(object):
"""Fake one or more flavors."""