Skip to content

Commit 81930ab

Browse files
author
Tang Chen
committed
Remove FakeFlavorResource class
In unit tests, all real methods are faked. They should not do any real operations in the tests. So, FakeFlavorResource is not necessary. Just fake get_keys(), set_keys and unset_keys() in FakeResource would be enough. Change-Id: Icc3473ba9c77f4817d0edddb7ff3e1bd2946fac7
1 parent 9ab7740 commit 81930ab

1 file changed

Lines changed: 16 additions & 29 deletions

File tree

  • openstackclient/tests/compute/v2

openstackclient/tests/compute/v2/fakes.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -501,42 +501,21 @@ def get_servers(servers=None, count=2):
501501
return mock.MagicMock(side_effect=servers)
502502

503503

504-
class FakeFlavorResource(fakes.FakeResource):
505-
"""Fake flavor object's methods to help test.
506-
507-
The flavor object has three methods to get, set, unset its properties.
508-
Need to fake them, otherwise the functions to be tested won't run properly.
509-
"""
510-
511-
def __init__(self, manager=None, info={}, loaded=False, methods={}):
512-
super(FakeFlavorResource, self).__init__(manager, info,
513-
loaded, methods)
514-
# Fake properties.
515-
self._keys = {'property': 'value'}
516-
517-
def set_keys(self, args):
518-
self._keys.update(args)
519-
520-
def unset_keys(self, keys):
521-
for key in keys:
522-
self._keys.pop(key, None)
523-
524-
def get_keys(self):
525-
return self._keys
526-
527-
528504
class FakeFlavor(object):
529505
"""Fake one or more flavors."""
530506

531507
@staticmethod
532-
def create_one_flavor(attrs={}):
508+
def create_one_flavor(attrs=None):
533509
"""Create a fake flavor.
534510
535511
:param Dictionary attrs:
536512
A dictionary with all attributes
537513
:return:
538-
A FakeFlavorResource object, with id, name, ram, vcpus, properties
514+
A FakeResource object, with id, name, ram, vcpus, properties
539515
"""
516+
if attrs is None:
517+
attrs = {}
518+
540519
# Set default attributes.
541520
flavor_info = {
542521
'id': 'flavor-id-' + uuid.uuid4().hex,
@@ -554,7 +533,15 @@ def create_one_flavor(attrs={}):
554533
# Overwrite default attributes.
555534
flavor_info.update(attrs)
556535

557-
flavor = FakeFlavorResource(info=copy.deepcopy(flavor_info),
536+
# Set default methods.
537+
flavor_methods = {
538+
'set_keys': None,
539+
'unset_keys': None,
540+
'get_keys': {'property': 'value'},
541+
}
542+
543+
flavor = fakes.FakeResource(info=copy.deepcopy(flavor_info),
544+
methods=flavor_methods,
558545
loaded=True)
559546

560547
# Set attributes with special mappings in nova client.
@@ -573,7 +560,7 @@ def create_flavors(attrs={}, count=2):
573560
:param int count:
574561
The number of flavors to fake
575562
:return:
576-
A list of FakeFlavorResource objects faking the flavors
563+
A list of FakeResource objects faking the flavors
577564
"""
578565
flavors = []
579566
for i in range(0, count):
@@ -589,7 +576,7 @@ def get_flavors(flavors=None, count=2):
589576
list. Otherwise create one.
590577
591578
:param List flavors:
592-
A list of FakeFlavorResource objects faking flavors
579+
A list of FakeResource objects faking flavors
593580
:param int count:
594581
The number of flavors to fake
595582
:return:

0 commit comments

Comments
 (0)