Skip to content

Commit 347b444

Browse files
committed
tests: Reorder compute fakes
This will make future changes slightly less complex. Change-Id: Ia69fd9d05796cce5ed48a8d12902cb54caec9779 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 3c9afe6 commit 347b444

1 file changed

Lines changed: 71 additions & 71 deletions

File tree

  • openstackclient/tests/unit/compute/v2

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -75,77 +75,6 @@
7575
QUOTA_data = tuple(QUOTA[x] for x in sorted(QUOTA))
7676

7777

78-
class FakeAggregate(object):
79-
"""Fake one aggregate."""
80-
81-
@staticmethod
82-
def create_one_aggregate(attrs=None):
83-
"""Create a fake aggregate.
84-
85-
:param dict attrs:
86-
A dictionary with all attributes
87-
:return:
88-
A FakeResource object, with id and other attributes
89-
"""
90-
attrs = attrs or {}
91-
92-
# Set default attribute
93-
aggregate_info = {
94-
"name": "aggregate-name-" + uuid.uuid4().hex,
95-
"availability_zone": "ag_zone",
96-
"hosts": [],
97-
"id": "aggregate-id-" + uuid.uuid4().hex,
98-
"metadata": {
99-
"availability_zone": "ag_zone",
100-
"key1": "value1",
101-
},
102-
}
103-
104-
# Overwrite default attributes.
105-
aggregate_info.update(attrs)
106-
107-
aggregate = fakes.FakeResource(
108-
info=copy.deepcopy(aggregate_info), loaded=True
109-
)
110-
return aggregate
111-
112-
@staticmethod
113-
def create_aggregates(attrs=None, count=2):
114-
"""Create multiple fake aggregates.
115-
116-
:param dict attrs:
117-
A dictionary with all attributes
118-
:param int count:
119-
The number of aggregates to fake
120-
:return:
121-
A list of FakeResource objects faking the aggregates
122-
"""
123-
aggregates = []
124-
for i in range(0, count):
125-
aggregates.append(FakeAggregate.create_one_aggregate(attrs))
126-
127-
return aggregates
128-
129-
@staticmethod
130-
def get_aggregates(aggregates=None, count=2):
131-
"""Get an iterable MagicMock object with a list of faked aggregates.
132-
133-
If aggregates list is provided, then initialize the Mock object
134-
with the list. Otherwise create one.
135-
136-
:param List aggregates:
137-
A list of FakeResource objects faking aggregates
138-
:param int count:
139-
The number of aggregates to fake
140-
:return:
141-
An iterable Mock object with side_effect set to a list of faked
142-
aggregates
143-
"""
144-
if aggregates is None:
145-
aggregates = FakeAggregate.create_aggregates(count)
146-
return mock.Mock(side_effect=aggregates)
147-
148-
14978
class FakeComputev2Client(object):
15079
def __init__(self, **kwargs):
15180
self.agents = mock.Mock()
@@ -255,6 +184,77 @@ def setUp(self):
255184
)
256185

257186

187+
class FakeAggregate(object):
188+
"""Fake one aggregate."""
189+
190+
@staticmethod
191+
def create_one_aggregate(attrs=None):
192+
"""Create a fake aggregate.
193+
194+
:param dict attrs:
195+
A dictionary with all attributes
196+
:return:
197+
A FakeResource object, with id and other attributes
198+
"""
199+
attrs = attrs or {}
200+
201+
# Set default attribute
202+
aggregate_info = {
203+
"name": "aggregate-name-" + uuid.uuid4().hex,
204+
"availability_zone": "ag_zone",
205+
"hosts": [],
206+
"id": "aggregate-id-" + uuid.uuid4().hex,
207+
"metadata": {
208+
"availability_zone": "ag_zone",
209+
"key1": "value1",
210+
},
211+
}
212+
213+
# Overwrite default attributes.
214+
aggregate_info.update(attrs)
215+
216+
aggregate = fakes.FakeResource(
217+
info=copy.deepcopy(aggregate_info), loaded=True
218+
)
219+
return aggregate
220+
221+
@staticmethod
222+
def create_aggregates(attrs=None, count=2):
223+
"""Create multiple fake aggregates.
224+
225+
:param dict attrs:
226+
A dictionary with all attributes
227+
:param int count:
228+
The number of aggregates to fake
229+
:return:
230+
A list of FakeResource objects faking the aggregates
231+
"""
232+
aggregates = []
233+
for i in range(0, count):
234+
aggregates.append(FakeAggregate.create_one_aggregate(attrs))
235+
236+
return aggregates
237+
238+
@staticmethod
239+
def get_aggregates(aggregates=None, count=2):
240+
"""Get an iterable MagicMock object with a list of faked aggregates.
241+
242+
If aggregates list is provided, then initialize the Mock object
243+
with the list. Otherwise create one.
244+
245+
:param List aggregates:
246+
A list of FakeResource objects faking aggregates
247+
:param int count:
248+
The number of aggregates to fake
249+
:return:
250+
An iterable Mock object with side_effect set to a list of faked
251+
aggregates
252+
"""
253+
if aggregates is None:
254+
aggregates = FakeAggregate.create_aggregates(count)
255+
return mock.Mock(side_effect=aggregates)
256+
257+
258258
class FakeAgent(object):
259259
"""Fake one or more agent."""
260260

0 commit comments

Comments
 (0)