def test_so_to_dict(): """Conversion to dictionary works properly""" hub = database.AutoConnectHub("sqlite:///:memory:") try: from sqlobject import IntCol from sqlobject.inheritance import InheritableSQLObject class Parent(InheritableSQLObject): _connection = hub a = IntCol() class Child(Parent): _connection = hub b = IntCol() Parent.createTable() Child.createTable() p = Parent(a=1) c = Child(a=1, b=2) p_dict = database.so_to_dict(p) assert p_dict['a'] == 1 c_dict = database.so_to_dict(c) assert c_dict['a'] == 1 assert c_dict['b'] == 2 assert None == c_dict.get('childName', None) assert None == p_dict.get('childName', None) finally: database.hub_registry.clear()
def test_so_to_dict(): from sqlobject import IntCol from sqlobject.inheritance import InheritableSQLObject class Parent(InheritableSQLObject): _connection = hub a = IntCol() class Child(Parent): _connection = hub b = IntCol() Parent.createTable() Child.createTable() p = Parent(a=1) c = Child(a=1, b=2) p_dict = database.so_to_dict(p) assert p_dict['a'] == 1 c_dict = database.so_to_dict(c) assert c_dict['a'] == 1 assert c_dict['b'] == 2 assert None == c_dict.get('childName', None) assert None == p_dict.get('childName', None)
def so_to_dict(sqlobj): return database.so_to_dict(sqlobj)