Esempio n. 1
0
    def test_reflection(self):
        class SomeClass(TableModel):
            __tablename__ = 'some_class'

            id = Integer32(primary_key=True)
            s = Unicode(32)

        TableModel.Attributes.sqla_metadata.create_all()

        # create a new table model with empty metadata
        TM2 = TTableModel()
        TM2.Attributes.sqla_metadata.bind = self.engine

        # fill it with information from the db
        TM2.Attributes.sqla_metadata.reflect()

        # convert sqla info to spyne info
        class Reflected(TM2):
            __table__ = TM2.Attributes.sqla_metadata.tables['some_class']

        pprint(dict(Reflected._type_info).items())
        assert issubclass(Reflected._type_info['id'], Integer)

        # this looks at spyne attrs
        assert [k for k, v in get_pk_columns(Reflected)] == ['id']

        # this looks at sqla attrs
        assert [k for k, v in Reflected.get_primary_keys()] == ['id']

        assert issubclass(Reflected._type_info['s'], Unicode)
        assert Reflected._type_info['s'].Attributes.max_len == 32
Esempio n. 2
0
    def test_reflection(self):
        class SomeClass(TableModel):
            __tablename__ = 'some_class'

            id = Integer32(primary_key=True)
            s = Unicode(32)

        # create a new table model with empty metadata
        TM2 = TTableModel()
        TM2.bind = self.engine

        # fill it with information from the db
        TM2.Attributes.sqla_metadata.reflect()

        # convert sqla info to spyne info
        class Reflected(TM2):
            __table__ = TM2.Attributes.sqla_metadata.tables['some_class']

        pprint(dict(Reflected._type_info).items())
        assert issubclass(Reflected._type_info['id'], Integer)
        assert issubclass(Reflected._type_info['s'], Unicode)
        assert Reflected._type_info['s'].Attributes.max_len == 32
Esempio n. 3
0
from sqlalchemy.orm import mapper
from sqlalchemy.orm import sessionmaker

from spyne import M

from spyne.model import XmlAttribute, File, XmlData, ComplexModel, Array, \
    Integer32, Unicode, Integer, Enum, TTableModel, DateTime, Boolean

from spyne.model.binary import HybridFileStore
from spyne.model.complex import xml
from spyne.model.complex import table

from spyne.store.relational import get_pk_columns

TableModel = TTableModel()


class TestSqlAlchemyTypeMappings(unittest.TestCase):
    def test_bool(self):
        class SomeClass1(TableModel):
            __tablename__ = 'test_bool_1'
            i = Integer32(pk=True)
            b = Boolean

        assert isinstance(SomeClass1.Attributes.sqla_table.c.b.type,
                          sqlalchemy.Boolean)

        class SomeClass2(TableModel):
            __tablename__ = 'test_bool_2'
            i = Integer32(pk=True)