예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
    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)])
예제 #4
0
    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)])
예제 #5
0
 def test_obj_to_primitive_dict(self):
     myobj = MyObj(foo=1, bar='foo')
     self.assertEqual({
         'foo': 1,
         'bar': 'foo'
     }, base.obj_to_primitive(myobj))
예제 #6
0
 def test_obj_to_primitive_dict(self):
     myobj = MyObj(foo=1, bar='foo')
     self.assertEqual({'foo': 1, 'bar': 'foo'},
                      base.obj_to_primitive(myobj))