Source

sqlalchemy / lib / sqlalchemy / testing / suite / test_ddl.py

from __future__ import with_statement

from .. import fixtures, config, util
from ..config import requirements
from ..assertions import eq_

from sqlalchemy import Table, Column, Integer, String


class TableDDLTest(fixtures.TestBase):

    def _simple_fixture(self):
        return Table('test_table', self.metadata,
                Column('id', Integer, primary_key=True, autoincrement=False),
                Column('data', String(50))
            )

    def _simple_roundtrip(self):
        with config.db.begin() as conn:
            conn.execute("insert into test_table(id, data) values "
                            "(1, 'some data')")
            result = conn.execute("select id, data from test_table")
            eq_(
                result.first(),
                (1, 'some data')
            )

    @requirements.create_table
    @util.provide_metadata
    def test_create_table(self):
        table = self._simple_fixture()
        table.create(
            config.db, checkfirst=False
        )
        self._simple_roundtrip()

    @requirements.drop_table
    @util.provide_metadata
    def test_drop_table(self):
        table = self._simple_fixture()
        table.create(
            config.db, checkfirst=False
        )
        table.drop(
            config.db, checkfirst=False
        )


__all__ = ('TableDDLTest', )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.