sqlalchemy.testing.schema.Table

Here are the examples of the python api sqlalchemy.testing.schema.Table taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: SickGear
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 2

Project: SickGear
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 3

Project: SickGear
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 4

Project: SickRage
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 5

Project: SickRage
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 6

Project: SickRage
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 7

Project: moviegrabber
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 8

Project: moviegrabber
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 9

Project: moviegrabber
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 10

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(50))
              )

Example 11

Project: sqlalchemy
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                  *[
                      Column('t%d' % i, type_)
                      for i, type_ in enumerate(types)
                  ]
                  )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 12

Project: sqlalchemy
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                  Column('a', Integer, nullable=True),
                  Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 13

Project: sqlalchemy
Source File: test_memusage.py
View license
    def test_path_registry(self):
        metadata = MetaData()
        a = Table("a", metadata,
                  Column('id', Integer, primary_key=True),
                  Column('foo', Integer),
                  Column('bar', Integer)
                  )
        m1 = mapper(A, a)

        @profile_memory()
        def go():
            ma = sa.inspect(aliased(A))
            m1._path_registry[m1.attrs.foo][ma][m1.attrs.bar]
        go()
        clear_mappers()

Example 14

Project: sqlalchemy
Source File: test_memusage.py
View license
    @testing.provide_metadata
    def test_key_fallback_result(self):
        e = self.engine
        m = self.metadata
        t = Table('t', m, Column('x', Integer), Column('y', Integer))
        m.create_all(e)
        e.execute(t.insert(), {"x": 1, "y": 1})

        @profile_memory()
        def go():
            r = e.execute(t.alias().select())
            for row in r:
                row[t.c.x]
        go()

Example 15

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('parent', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(20)),
              Column('child_id', Integer, ForeignKey('child.id'))
              )

        Table('child', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(20))
              )

Example 16

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('a', metadata,
              Column('id', Integer, primary_key=True),
              Column('c_id', Integer, ForeignKey('c.id'))
              )
        Table('b', metadata,
              Column('id', Integer, primary_key=True),
              Column('a_id', Integer, ForeignKey('a.id'))
              )
        Table('c', metadata,
              Column('id', Integer, primary_key=True),
              )
        Table('d', metadata,
              Column('id', Integer, primary_key=True),
              Column('a_id', Integer, ForeignKey('a.id'))
              )

Example 17

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('a', metadata,
              Column('id', Integer, primary_key=True),
              Column('x', String(5)),
              Column('y', String(5)),
              Column('z', String(5)),
              Column('q', String(5)),
              Column('p', String(5)),
              Column('r', String(5)),
              )

Example 18

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table(
            'parent',
            metadata,
            Column('id', Integer,
                   primary_key=True, test_needs_autoincrement=True),
            Column('data', String(20)))
        Table(
            'child', metadata,
            Column('id', Integer, primary_key=True,
                   test_needs_autoincrement=True),
            Column(
                'data', String(20)), Column(
                'parent_id', Integer, ForeignKey('parent.id'), nullable=False))

Example 19

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table(
            'parent',
            metadata,
            Column('id', Integer,
                   primary_key=True, test_needs_autoincrement=True),
            Column('data1', String(20)),
            Column('data2', String(20)),
            Column('data3', String(20)),
            Column('data4', String(20)),
        )

Example 20

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_explicit(self):
        metadata = MetaData()
        table = Table('test_table', metadata,
            Column('foo', Integer))
        for bind in (
            testing.db,
            testing.db.connect()
        ):
            for args in [
                ([], {'bind': bind}),
                ([bind], {})
            ]:
                metadata.create_all(*args[0], **args[1])
                assert table.exists(*args[0], **args[1])
                metadata.drop_all(*args[0], **args[1])
                table.create(*args[0], **args[1])
                table.drop(*args[0], **args[1])
                assert not table.exists(*args[0], **args[1])

Example 21

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_err_metadata(self):
        metadata = MetaData()
        Table('test_table', metadata, Column('foo', Integer))
        for meth in [metadata.create_all, metadata.drop_all]:
            assert_raises_message(
                exc.UnboundExecutionError,
                "MetaData object is not bound to an Engine or Connection.",
                meth
            )

Example 22

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_err_table(self):
        metadata = MetaData()
        table = Table('test_table', metadata,
            Column('foo', Integer))

        for meth in [
            table.exists,
            table.create,
            table.drop,
        ]:
            assert_raises_message(
                exc.UnboundExecutionError,
                ("Table object 'test_table' is not bound to an Engine or "
                 "Connection."),
                meth
            )

Example 23

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    def setup(self):
        self.engine = engines.mock_engine()
        self.metadata = MetaData(self.engine)
        self.users = Table('users', self.metadata,
                           Column('user_id', Integer, primary_key=True),
                           Column('user_name', String(40)),
                           )

Example 24

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    def test_filter(self):
        cx = self.mock_engine()

        tbl = Table('t', MetaData(), Column('id', Integer))
        target = cx.name

        assert DDL('')._should_execute(tbl, cx)
        assert DDL('').execute_if(dialect=target)._should_execute(tbl, cx)
        assert not DDL('').execute_if(dialect='bogus').\
                        _should_execute(tbl, cx)
        assert DDL('').execute_if(callable_=lambda d, y, z, **kw: True).\
                        _should_execute(tbl, cx)
        assert(DDL('').execute_if(
                        callable_=lambda d, y, z, **kw: z.engine.name
                        != 'bogus').
               _should_execute(tbl, cx))

Example 25

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    @testing.uses_deprecated(r'See DDLEvents')
    def test_filter_deprecated(self):
        cx = self.mock_engine()

        tbl = Table('t', MetaData(), Column('id', Integer))
        target = cx.name

        assert DDL('')._should_execute_deprecated('x', tbl, cx)
        assert DDL('', on=target)._should_execute_deprecated('x', tbl, cx)
        assert not DDL('', on='bogus').\
                        _should_execute_deprecated('x', tbl, cx)
        assert DDL('', on=lambda d, x, y, z: True).\
                        _should_execute_deprecated('x', tbl, cx)
        assert(DDL('', on=lambda d, x, y, z: z.engine.name != 'bogus').
               _should_execute_deprecated('x', tbl, cx))

Example 26

Project: sqlalchemy
Source File: test_reconnect.py
View license
    def setup(self):
        self.engine = engines.reconnecting_engine()
        self.meta = MetaData(self.engine)
        table = Table(
            'sometable', self.meta,
            Column('id', Integer, primary_key=True),
            Column('name', String(50)))
        self.meta.create_all()
        table.insert().execute(
            [{'id': i, 'name': 'row %d' % i} for i in range(1, 100)]
        )

Example 27

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("a", metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              )
        Table("b", metadata,
              Column('id', Integer,
                     ForeignKey('a.id'),
                     primary_key=True),
              Column('x', Integer, primary_key=True)
              )

Example 28

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('users', metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              Column('name', String(50)), test_needs_fk=True)
        Table(
            'addresses',
            metadata,
            Column('id', Integer, primary_key=True,
                   test_needs_autoincrement=True),
            Column('email', String(50)),
            Column('user_id', Integer, ForeignKey('users.id')),
            test_needs_fk=True,
        )

Example 29

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('users', metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              Column('name', String(50)), test_needs_fk=True)

        Table('user_items', metadata,
              Column('user_id', ForeignKey('users.id'), primary_key=True),
              Column('item_id', ForeignKey('items.id'), primary_key=True),
              test_needs_fk=True
              )

        Table('items', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('name', String(50)),
              test_needs_fk=True
              )

Example 30

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_table_resolution(self):
        class User(decl.DeferredReflection, fixtures.ComparableEntity, Base):
            __tablename__ = 'users'

            items = relationship("Item",
                                 secondary=Table("user_items", Base.metadata))

        class Item(decl.DeferredReflection, fixtures.ComparableEntity, Base):
            __tablename__ = 'items'

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 31

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("foo", metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('type', String(32)),
              Column('data', String(30)),
              Column('bar_data', String(30))
              )

Example 32

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("foo", metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('type', String(32)),
              Column('data', String(30)),
              test_needs_fk=True,
              )
        Table('bar', metadata,
              Column('id', Integer, ForeignKey('foo.id'), primary_key=True),
              Column('bar_data', String(30)),
              test_needs_fk=True,
              )

Example 33

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableDict = cls._type_fixture()

        mutable_pickle = MutableDict.as_mutable(PickleType)
        Table(
            'foo', metadata,
            Column(
                'id', Integer, primary_key=True,
                test_needs_autoincrement=True),
            Column('data', mutable_pickle, default={}),
        )

Example 34

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableDict = cls._type_fixture()

        mutable_pickle = MutableDict.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 35

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableList = cls._type_fixture()

        mutable_pickle = MutableList.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 36

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableSet = cls._type_fixture()

        mutable_pickle = MutableSet.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 37

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):

        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('data', PickleType),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

        Table('subfoo', metadata,
              Column('id', Integer, ForeignKey('foo.id'), primary_key=True),
              )

Example 38

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableDict = cls._type_fixture()
        MutableDict.associate_with(PickleType)

        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', PickleType),
              Column('data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 39

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('x', Integer),
              Column('y', Integer),
              Column('unrelated_data', String(50))
              )

Example 40

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table(
            'foo', metadata,
            Column('id', Integer, primary_key=True,
                   test_needs_autoincrement=True),
            Column('x', Integer, default=5),
            Column('y', Integer, default=9),
            Column('unrelated_data', String(50))
        )

Example 41

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('x', Integer),
              Column('y', Integer)
              )
        Table('subfoo', metadata,
              Column('id', Integer, ForeignKey('foo.id'), primary_key=True),
              )

Example 42

Project: sqlalchemy
Source File: test_serializer.py
View license
    @classmethod
    def define_tables(cls, metadata):
        global users, addresses
        users = Table('users', metadata, Column('id', Integer,
                      primary_key=True), Column('name', String(50)))
        addresses = Table('addresses', metadata, Column('id', Integer,
                          primary_key=True), Column('email',
                          String(50)), Column('user_id', Integer,
                          ForeignKey('users.id')))

Example 43

Project: sqlalchemy
Source File: test_serializer.py
View license
    def test_unicode(self):
        m = MetaData()
        t = Table(ue('\u6e2c\u8a66'), m,
                Column(ue('\u6e2c\u8a66_id'), Integer))

        expr = select([t]).where(t.c[ue('\u6e2c\u8a66_id')] == 5)

        expr2 = serializer.loads(serializer.dumps(expr, -1), m)

        self.assert_compile(
            expr2,
            ue('SELECT "\u6e2c\u8a66"."\u6e2c\u8a66_id" FROM "\u6e2c\u8a66" '
                'WHERE "\u6e2c\u8a66"."\u6e2c\u8a66_id" = :\u6e2c\u8a66_id_1'),
            dialect="default"
        )

Example 44

Project: sqlalchemy
Source File: test_abc_polymorphic.py
View license
    @classmethod
    def define_tables(cls, metadata):
        global a, b, c
        a = Table('a', metadata,
            Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
            Column('adata', String(30)),
            Column('type', String(30)),
            )
        b = Table('b', metadata,
            Column('id', Integer, ForeignKey('a.id'), primary_key=True),
            Column('bdata', String(30)))
        c = Table('c', metadata,
            Column('id', Integer, ForeignKey('b.id'), primary_key=True),
            Column('cdata', String(30)))

Example 45

Project: sqlalchemy
Source File: test_concrete.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('a_table', metadata, Column('id', Integer,
              primary_key=True, test_needs_autoincrement=True),
              Column('some_dest_id', Integer, ForeignKey('dest_table.id')),
              Column('aname', String(50)))
        Table('b_table', metadata, Column('id', Integer,
              primary_key=True, test_needs_autoincrement=True),
              Column('some_dest_id', Integer, ForeignKey('dest_table.id')),
              Column('bname', String(50)))

        Table('c_table', metadata, Column('id', Integer,
            primary_key=True, test_needs_autoincrement=True),
            Column('some_dest_id', Integer, ForeignKey('dest_table.id')),
            Column('cname', String(50)))

        Table('dest_table', metadata, Column('id', Integer,
              primary_key=True, test_needs_autoincrement=True),
              Column('name', String(50)))

Example 46

Project: sqlalchemy
Source File: test_concrete.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('base', metadata, Column('id', Integer, primary_key=True,
              test_needs_autoincrement=True))
        Table('sub', metadata, Column('id', Integer, primary_key=True,
              test_needs_autoincrement=True))
        Table('base_mtom', metadata, Column('base_id', Integer,
              ForeignKey('base.id'), primary_key=True),
              Column('related_id', Integer, ForeignKey('related.id'),
              primary_key=True))
        Table('sub_mtom', metadata, Column('base_id', Integer,
              ForeignKey('sub.id'), primary_key=True),
              Column('related_id', Integer, ForeignKey('related.id'),
              primary_key=True))
        Table('related', metadata, Column('id', Integer,
              primary_key=True, test_needs_autoincrement=True))

Example 47

Project: sqlalchemy
Source File: test_concrete.py
View license
    @classmethod
    def define_tables(cls, metadata):
        global offices_table, refugees_table
        refugees_table = Table('refugee', metadata, Column('refugee_fid'
                               , Integer, primary_key=True,
                               test_needs_autoincrement=True),
                               Column('refugee_name', String(30),
                               key='name'))
        offices_table = Table('office', metadata, Column('office_fid',
                              Integer, primary_key=True,
                              test_needs_autoincrement=True),
                              Column('office_name', String(30),
                              key='name'))

Example 48

Project: sqlalchemy
Source File: test_selects.py
View license
    @classmethod
    def define_tables(cls, metadata):
        foo = Table('foo', metadata,
                    Column('a', String(30), primary_key=1),
                    Column('b', String(30), nullable=0))

        cls.tables.bar = foo.select(foo.c.b == 'bar').alias('bar')
        cls.tables.baz = foo.select(foo.c.b == 'baz').alias('baz')

Example 49

Project: sqlalchemy
Source File: test_selects.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('base', metadata,
                Column('id', Integer, primary_key=True,
                        test_needs_autoincrement=True),
                Column('type', String(50))
            )
        Table('child', metadata,
                # 1. name of column must be different, so that we rely on
                # mapper._table_to_equated to link the two cols
                Column('child_id', Integer, ForeignKey('base.id'), primary_key=True),
                Column('name', String(50))
            )

Example 50

Project: sqlalchemy
Source File: test_single.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('employees', metadata,
            Column('employee_id', Integer, primary_key=True, test_needs_autoincrement=True),
            Column('name', String(50)),
            Column('manager_data', String(50)),
            Column('engineer_info', String(50)),
            Column('type', String(20)))

        Table('reports', metadata,
              Column('report_id', Integer, primary_key=True, test_needs_autoincrement=True),
              Column('employee_id', ForeignKey('employees.employee_id')),
              Column('name', String(50)),
        )