From 81930abdcbee68a7687a53625ac3b5d34f16168f Mon Sep 17 00:00:00 2001
From: Tang Chen <chen.tang@easystack.cn>
Date: Tue, 8 Mar 2016 20:41:52 +0800
Subject: [PATCH] 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
---
 openstackclient/tests/compute/v2/fakes.py | 45 ++++++++---------------
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index f735fe42d8..11d9ff1b46 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -501,42 +501,21 @@ class FakeServer(object):
         return mock.MagicMock(side_effect=servers)
 
 
-class FakeFlavorResource(fakes.FakeResource):
-    """Fake flavor object's methods to help test.
-
-    The flavor object has three methods to get, set, unset its properties.
-    Need to fake them, otherwise the functions to be tested won't run properly.
-    """
-
-    def __init__(self, manager=None, info={}, loaded=False, methods={}):
-        super(FakeFlavorResource, self).__init__(manager, info,
-                                                 loaded, methods)
-        # Fake properties.
-        self._keys = {'property': 'value'}
-
-    def set_keys(self, args):
-        self._keys.update(args)
-
-    def unset_keys(self, keys):
-        for key in keys:
-            self._keys.pop(key, None)
-
-    def get_keys(self):
-        return self._keys
-
-
 class FakeFlavor(object):
     """Fake one or more flavors."""
 
     @staticmethod
-    def create_one_flavor(attrs={}):
+    def create_one_flavor(attrs=None):
         """Create a fake flavor.
 
         :param Dictionary attrs:
             A dictionary with all attributes
         :return:
-            A FakeFlavorResource object, with id, name, ram, vcpus, properties
+            A FakeResource object, with id, name, ram, vcpus, properties
         """
+        if attrs is None:
+            attrs = {}
+
         # Set default attributes.
         flavor_info = {
             'id': 'flavor-id-' + uuid.uuid4().hex,
@@ -554,7 +533,15 @@ class FakeFlavor(object):
         # Overwrite default attributes.
         flavor_info.update(attrs)
 
-        flavor = FakeFlavorResource(info=copy.deepcopy(flavor_info),
+        # Set default methods.
+        flavor_methods = {
+            'set_keys': None,
+            'unset_keys': None,
+            'get_keys': {'property': 'value'},
+        }
+
+        flavor = fakes.FakeResource(info=copy.deepcopy(flavor_info),
+                                    methods=flavor_methods,
                                     loaded=True)
 
         # Set attributes with special mappings in nova client.
@@ -573,7 +560,7 @@ class FakeFlavor(object):
         :param int count:
             The number of flavors to fake
         :return:
-            A list of FakeFlavorResource objects faking the flavors
+            A list of FakeResource objects faking the flavors
         """
         flavors = []
         for i in range(0, count):
@@ -589,7 +576,7 @@ class FakeFlavor(object):
         list. Otherwise create one.
 
         :param List flavors:
-            A list of FakeFlavorResource objects faking flavors
+            A list of FakeResource objects faking flavors
         :param int count:
             The number of flavors to fake
         :return: