Esempio n. 1
0
    def testGetAttr(self):
        attrNames = 'apple', 'banana', 'pears', 'orange', 'peach', 'nectarine', 'grape', 'watermelon'
        attrValues = range(len(attrNames))
        obj = SObject()
        for attr, val in zip(attrNames, attrValues):
            setattr(obj, attr, val)

        assert obj.getAttrs() == attrNames
        for attr, value in zip(attrNames, attrValues):
            assert value == getattr(obj, attr)

        #test simple case equality
        assert obj == SObject(*zip(attrNames, attrValues))

        obj2 = SObject(**dict(zip(attrNames, attrValues)))
        assert sorted(attrNames) == sorted(obj2.getAttrs())
Esempio n. 2
0
def create_sobject(sobjectdescribe):
    sobject = SObject(sobjectdescribe['label'],
                      apiname=sobjectdescribe['name'])
    for fld in sobjectdescribe['fields']:
        so_fld = Field(label=str(fld['label']),
                       apiname=str(fld['name']),
                       datatype=str(fld['type']),
                       custom=str(fld['custom']))

        sobject.add_field(so_fld)

    return sobject
Esempio n. 3
0
    def constructData(self):
        root = SObject()
        root.aString = "other thing"
        root.anotherStr = "bananas"
        root.anInt = 12
        root.none = None
        root.aBool = False
        root.big_str = _BIG_STR

        root.s2 = SObject(
            ('some_float', 200.0), ('someBool', True),
            ('unicode_test',
             u'some unicode value "with crap in it"\nand a newline!'))
        root.s2.crazy_list = [
            1, 2.5, '3', True, False,
            [
                'nested', 'lists', 'are', 'fun',
                (7, 8, 9, {
                    'dict': 1,
                    'inside': 2,
                    'tuple': (3)
                })
            ]
        ]
        root.s2.emptyTuple = ()
        root.s2.similarKeyDict = {123: 'key as int', '123': 'key as str'}

        root.s3 = SObject(('duplicate_ref_to_s2', root.s2), (
            'a_stupidly_long_attribute_name_to_test_whether_it_works_ok_with_serialization',
            0x902))

        root.s4 = SObject(('recursive_ref_to_root', root),
                          ('anotherTokenAttribute', -100))

        #test SObjects in lists - mixed with other stuff
        root.s5 = SObject()
        root.s5.objList = [
            root.s2, root.s3, root.s5, 1, 3.5, True, False, None
        ]
        root.s5.largeList = range(1000)

        #test tuples
        root.s6 = SObject(('aTuple', (1, 2, 3)),
                          ('objTuple', (SObject(), SObject())))

        assert root.s4.recursive_ref_to_root is root

        return root