def test_obj_to_primitive_recursive(self): class MyList(base.ObjectListBase, base.CinderObject): fields = {'objects': fields.ListOfObjectsField('MyObj')} mylist = MyList(objects=[MyObj(), MyObj()]) for i, value in enumerate(mylist): value.foo = i self.assertEqual([{'foo': 0}, {'foo': 1}], base.obj_to_primitive(mylist))
def test_obj_to_primitive_recursive(self): class MyList(base.ObjectListBase, base.CinderObject): fields = {'objects': fields.ListOfObjectsField('MyObj')} mylist = MyList(objects=[MyObj(), MyObj()]) for i, value in enumerate(mylist): value.foo = i self.assertEqual([{ 'foo': 0 }, { 'foo': 1 }], base.obj_to_primitive(mylist))
def test_obj_to_primitive_list(self): class MyObjElement(base.CinderObject): fields = {'foo': fields.IntegerField()} def __init__(self, foo): super(MyObjElement, self).__init__() self.foo = foo class MyList(base.ObjectListBase, base.CinderObject): fields = {'objects': fields.ListOfObjectsField('MyObjElement')} mylist = MyList() mylist.objects = [MyObjElement(1), MyObjElement(2), MyObjElement(3)] self.assertEqual([1, 2, 3], [x['foo'] for x in base.obj_to_primitive(mylist)])
def test_obj_to_primitive_dict(self): myobj = MyObj(foo=1, bar='foo') self.assertEqual({ 'foo': 1, 'bar': 'foo' }, base.obj_to_primitive(myobj))
def test_obj_to_primitive_dict(self): myobj = MyObj(foo=1, bar='foo') self.assertEqual({'foo': 1, 'bar': 'foo'}, base.obj_to_primitive(myobj))