summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2023-05-16 16:19:53 +0100
committerStephen Finucane <sfinucan@redhat.com>2023-05-16 16:21:02 +0100
commit347b444feb19ddb13a5b1a66d049eb0d818cbe77 (patch)
tree96f0f0bb33d1a8f77b9d371357ccd9b052e4a227
parent3c9afe69bbb249b30e586fd0f8b3dd095d2cab48 (diff)
downloadpython-openstackclient-347b444feb19ddb13a5b1a66d049eb0d818cbe77.tar.gz
tests: Reorder compute fakes
This will make future changes slightly less complex. Change-Id: Ia69fd9d05796cce5ed48a8d12902cb54caec9779 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
-rw-r--r--openstackclient/tests/unit/compute/v2/fakes.py142
1 files changed, 71 insertions, 71 deletions
diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py
index c1ba4b97..17418c66 100644
--- a/openstackclient/tests/unit/compute/v2/fakes.py
+++ b/openstackclient/tests/unit/compute/v2/fakes.py
@@ -75,77 +75,6 @@ QUOTA_columns = tuple(sorted(QUOTA))
QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
-class FakeAggregate(object):
- """Fake one aggregate."""
-
- @staticmethod
- def create_one_aggregate(attrs=None):
- """Create a fake aggregate.
-
- :param dict attrs:
- A dictionary with all attributes
- :return:
- A FakeResource object, with id and other attributes
- """
- attrs = attrs or {}
-
- # Set default attribute
- aggregate_info = {
- "name": "aggregate-name-" + uuid.uuid4().hex,
- "availability_zone": "ag_zone",
- "hosts": [],
- "id": "aggregate-id-" + uuid.uuid4().hex,
- "metadata": {
- "availability_zone": "ag_zone",
- "key1": "value1",
- },
- }
-
- # Overwrite default attributes.
- aggregate_info.update(attrs)
-
- aggregate = fakes.FakeResource(
- info=copy.deepcopy(aggregate_info), loaded=True
- )
- return aggregate
-
- @staticmethod
- def create_aggregates(attrs=None, count=2):
- """Create multiple fake aggregates.
-
- :param dict attrs:
- A dictionary with all attributes
- :param int count:
- The number of aggregates to fake
- :return:
- A list of FakeResource objects faking the aggregates
- """
- aggregates = []
- for i in range(0, count):
- aggregates.append(FakeAggregate.create_one_aggregate(attrs))
-
- return aggregates
-
- @staticmethod
- def get_aggregates(aggregates=None, count=2):
- """Get an iterable MagicMock object with a list of faked aggregates.
-
- If aggregates list is provided, then initialize the Mock object
- with the list. Otherwise create one.
-
- :param List aggregates:
- A list of FakeResource objects faking aggregates
- :param int count:
- The number of aggregates to fake
- :return:
- An iterable Mock object with side_effect set to a list of faked
- aggregates
- """
- if aggregates is None:
- aggregates = FakeAggregate.create_aggregates(count)
- return mock.Mock(side_effect=aggregates)
-
-
class FakeComputev2Client(object):
def __init__(self, **kwargs):
self.agents = mock.Mock()
@@ -255,6 +184,77 @@ class TestComputev2(utils.TestCommand):
)
+class FakeAggregate(object):
+ """Fake one aggregate."""
+
+ @staticmethod
+ def create_one_aggregate(attrs=None):
+ """Create a fake aggregate.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object, with id and other attributes
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ aggregate_info = {
+ "name": "aggregate-name-" + uuid.uuid4().hex,
+ "availability_zone": "ag_zone",
+ "hosts": [],
+ "id": "aggregate-id-" + uuid.uuid4().hex,
+ "metadata": {
+ "availability_zone": "ag_zone",
+ "key1": "value1",
+ },
+ }
+
+ # Overwrite default attributes.
+ aggregate_info.update(attrs)
+
+ aggregate = fakes.FakeResource(
+ info=copy.deepcopy(aggregate_info), loaded=True
+ )
+ return aggregate
+
+ @staticmethod
+ def create_aggregates(attrs=None, count=2):
+ """Create multiple fake aggregates.
+
+ :param dict attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of aggregates to fake
+ :return:
+ A list of FakeResource objects faking the aggregates
+ """
+ aggregates = []
+ for i in range(0, count):
+ aggregates.append(FakeAggregate.create_one_aggregate(attrs))
+
+ return aggregates
+
+ @staticmethod
+ def get_aggregates(aggregates=None, count=2):
+ """Get an iterable MagicMock object with a list of faked aggregates.
+
+ If aggregates list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
+
+ :param List aggregates:
+ A list of FakeResource objects faking aggregates
+ :param int count:
+ The number of aggregates to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ aggregates
+ """
+ if aggregates is None:
+ aggregates = FakeAggregate.create_aggregates(count)
+ return mock.Mock(side_effect=aggregates)
+
+
class FakeAgent(object):
"""Fake one or more agent."""