Merge "Remove unused methods and functions"
This commit is contained in:
commit
5e22cf9a09
|
@ -62,45 +62,6 @@ class MagnumPersistentObject(object):
|
|||
}
|
||||
|
||||
|
||||
class ObjectListBase(ovoo_base.ObjectListBase):
|
||||
# TODO(xek): These are for transition to using the oslo base object
|
||||
# and can be removed when we move to it.
|
||||
fields = {
|
||||
'objects': list,
|
||||
}
|
||||
|
||||
def _attr_objects_to_primitive(self):
|
||||
"""Serialization of object list."""
|
||||
return [x.obj_to_primitive() for x in self.objects]
|
||||
|
||||
def _attr_objects_from_primitive(self, value):
|
||||
"""Deserialization of object list."""
|
||||
objects = []
|
||||
for entity in value:
|
||||
obj = MagnumObject.obj_from_primitive(entity,
|
||||
context=self._context)
|
||||
objects.append(obj)
|
||||
return objects
|
||||
|
||||
|
||||
class MagnumObjectSerializer(ovoo_base.VersionedObjectSerializer):
|
||||
# Base class to use for object hydration
|
||||
OBJ_BASE_CLASS = MagnumObject
|
||||
|
||||
|
||||
def obj_to_primitive(obj):
|
||||
"""Recursively turn an object into a python primitive.
|
||||
|
||||
An MagnumObject becomes a dict, and anything that implements ObjectListBase
|
||||
becomes a list.
|
||||
"""
|
||||
if isinstance(obj, ObjectListBase):
|
||||
return [obj_to_primitive(x) for x in obj]
|
||||
elif isinstance(obj, MagnumObject):
|
||||
result = {}
|
||||
for key in obj.obj_fields:
|
||||
if obj.obj_attr_is_set(key) or key in obj.obj_extra_fields:
|
||||
result[key] = obj_to_primitive(getattr(obj, key))
|
||||
return result
|
||||
else:
|
||||
return obj
|
||||
|
|
|
@ -153,31 +153,6 @@ class TestUtils(test_base.TestCase):
|
|||
self.assertIsNone(utils.dt_deserializer(None, None))
|
||||
self.assertRaises(ValueError, utils.dt_deserializer, None, 'foo')
|
||||
|
||||
def test_obj_to_primitive_list(self):
|
||||
class MyList(base.ObjectListBase, base.MagnumObject):
|
||||
fields = {'objects': fields.ListOfStringsField()}
|
||||
mylist = MyList(self.context)
|
||||
mylist.objects = ['1', '2', '3']
|
||||
self.assertEqual(['1', '2', '3'], base.obj_to_primitive(mylist))
|
||||
|
||||
def test_obj_to_primitive_dict(self):
|
||||
myobj = MyObj(self.context)
|
||||
myobj.foo = 1
|
||||
myobj.bar = 'foo'
|
||||
self.assertEqual({'foo': 1, 'bar': 'foo'},
|
||||
base.obj_to_primitive(myobj))
|
||||
|
||||
def test_obj_to_primitive_recursive(self):
|
||||
class MyList(base.ObjectListBase, base.MagnumObject):
|
||||
fields = {'objects': fields.ListOfObjectsField('MyObj')}
|
||||
|
||||
mylist = MyList(self.context)
|
||||
mylist.objects = [MyObj(self.context), MyObj(self.context)]
|
||||
for i, value in enumerate(mylist):
|
||||
value.foo = i
|
||||
self.assertEqual([{'foo': 0}, {'foo': 1}],
|
||||
base.obj_to_primitive(mylist))
|
||||
|
||||
|
||||
class _TestObject(object):
|
||||
def test_hydration_type_error(self):
|
||||
|
|
Loading…
Reference in New Issue