sqlalchemy.CheckConstraint

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

94 Examples 7

3 Source : test_compiler.py
with Apache License 2.0
from gethue

    def test_drop_constraint_mysql(self):
        m = MetaData()
        table_name = "testtbl"
        constraint_name = "constraint"
        constraint = CheckConstraint("data IS NOT NULL", name=constraint_name)
        Table(table_name, m, Column("data", String(255)), constraint)
        dialect = mysql.dialect()
        self.assert_compile(
            schema.DropConstraint(constraint),
            "ALTER TABLE %s DROP CHECK `%s`" % (table_name, constraint_name),
            dialect=dialect,
        )

    def test_drop_constraint_mariadb(self):

3 Source : test_compiler.py
with Apache License 2.0
from gethue

    def test_drop_constraint_mariadb(self):
        m = MetaData()
        table_name = "testtbl"
        constraint_name = "constraint"
        constraint = CheckConstraint("data IS NOT NULL", name=constraint_name)
        Table(table_name, m, Column("data", String(255)), constraint)
        dialect = mysql.dialect()
        dialect.server_version_info = (10, 1, 1, "MariaDB")
        self.assert_compile(
            schema.DropConstraint(constraint),
            "ALTER TABLE %s DROP CONSTRAINT `%s`"
            % (table_name, constraint_name),
            dialect=dialect,
        )

    def test_create_index_with_length_quoted(self):

3 Source : test_sqlite.py
with Apache License 2.0
from gethue

    def test_on_conflict_clause_check_constraint(self):

        meta = MetaData()
        t = Table(
            "n",
            meta,
            Column("id", Integer),
            Column("x", Integer),
            CheckConstraint("id > x", sqlite_on_conflict="FAIL"),
        )

        self.assert_compile(
            CreateTable(t),
            "CREATE TABLE n (id INTEGER, x INTEGER, "
            "CHECK (id > x) ON CONFLICT FAIL)",
            dialect=sqlite.dialect(),
        )

    def test_on_conflict_clause_check_constraint_from_column(self):

3 Source : test_compiler.py
with Apache License 2.0
from gethue

    def test_table_no_cols_w_constraint(self):
        m = MetaData()
        t1 = Table("t1", m, CheckConstraint("a = 1"))
        self.assert_compile(
            schema.CreateTable(t1), "CREATE TABLE t1 (CHECK (a = 1))"
        )

    def test_table_one_col_w_constraint(self):

3 Source : test_compiler.py
with Apache License 2.0
from gethue

    def test_table_one_col_w_constraint(self):
        m = MetaData()
        t1 = Table("t1", m, Column("q", Integer), CheckConstraint("a = 1"))
        self.assert_compile(
            schema.CreateTable(t1),
            "CREATE TABLE t1 (q INTEGER, CHECK (a = 1))",
        )

    def test_schema_translate_map_table(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_column_level_ck_name(self):
        t = Table(
            "tbl",
            MetaData(),
            Column(
                "a",
                Integer,
                CheckConstraint("a > 5", name="ck_a_greater_five"),
            ),
        )
        self.assert_compile(
            schema.CreateTable(t),
            "CREATE TABLE tbl (a INTEGER CONSTRAINT "
            "ck_a_greater_five CHECK (a > 5))",
        )

    def test_deferrable_pk(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_deferrable_table_check(self):
        def factory(**kw):
            return CheckConstraint("a   <   b", **kw)

        self._test_deferrable(factory)

    def test_multiple(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_render_ck_constraint_external(self):
        t, t2 = self._constraint_create_fixture()

        constraint = CheckConstraint(
            "a   <   b",
            name="my_test_constraint",
            deferrable=True,
            initially="DEFERRED",
            table=t,
        )

        self.assert_compile(
            schema.AddConstraint(constraint),
            "ALTER TABLE tbl ADD CONSTRAINT my_test_constraint "
            "CHECK (a  <  b) DEFERRABLE INITIALLY DEFERRED",
        )

    def test_external_ck_constraint_cancels_internal(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_render_drop_constraint(self):
        t, t2 = self._constraint_create_fixture()

        constraint = CheckConstraint(
            "a   <   b",
            name="my_test_constraint",
            deferrable=True,
            initially="DEFERRED",
            table=t,
        )

        self.assert_compile(
            schema.DropConstraint(constraint),
            "ALTER TABLE tbl DROP CONSTRAINT my_test_constraint",
        )

    def test_render_drop_constraint_cascade(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_render_drop_constraint_cascade(self):
        t, t2 = self._constraint_create_fixture()

        constraint = CheckConstraint(
            "a   <   b",
            name="my_test_constraint",
            deferrable=True,
            initially="DEFERRED",
            table=t,
        )

        self.assert_compile(
            schema.DropConstraint(constraint, cascade=True),
            "ALTER TABLE tbl DROP CONSTRAINT my_test_constraint CASCADE",
        )

    def test_render_add_fk_constraint_stringcol(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_render_check_constraint_sql_literal(self):
        t, t2 = self._constraint_create_fixture()

        constraint = CheckConstraint(t.c.a > 5)

        self.assert_compile(
            schema.AddConstraint(constraint),
            "ALTER TABLE tbl ADD CHECK (a > 5)",
        )

    def test_render_check_constraint_inline_sql_literal(self):

3 Source : test_constraints.py
with Apache License 2.0
from gethue

    def test_render_check_constraint_inline_sql_literal(self):
        t, t2 = self._constraint_create_fixture()

        m = MetaData()
        t = Table(
            "t",
            m,
            Column("a", Integer, CheckConstraint(Column("a", Integer) > 5)),
        )

        self.assert_compile(
            schema.CreateColumn(t.c.a), "a INTEGER CHECK (a > 5)"
        )

    def test_render_index_sql_literal(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_check_constraint_copy(self):
        def r(x):
            return x

        c = CheckConstraint(
            "foo bar",
            name="name",
            initially=True,
            deferrable=True,
            _create_rule=r,
        )
        c2 = c.copy()
        eq_(c2.name, "name")
        eq_(str(c2.sqltext), "foo bar")
        eq_(c2.initially, True)
        eq_(c2.deferrable, True)
        assert c2._create_rule is r

    def test_col_replace_w_constraint(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_check_constraint_info(self):
        cc = CheckConstraint("foo=bar", name="x")
        eq_(cc.info, {})

        cc = CheckConstraint("foo=bar", name="x", info={"foo": "bar"})
        eq_(cc.info, {"foo": "bar"})

    def test_index_info(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_auto_append_lowercase_table(self):
        from sqlalchemy import table, column

        t = table("t", column("a"))
        t2 = table("t2", column("a"))
        for c in (
            UniqueConstraint(t.c.a),
            CheckConstraint(t.c.a > 5),
            ForeignKeyConstraint([t.c.a], [t2.c.a]),
            PrimaryKeyConstraint(t.c.a),
            Index("foo", t.c.a),
        ):
            assert True

    def test_tometadata_ok(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_check_constraint_copy(self):
        m = MetaData()
        t = Table("tbl", m, Column("a", Integer), Column("b", Integer))
        ck = CheckConstraint(t.c.a > 5)
        ck2 = ck.copy()
        assert ck in t.constraints
        assert ck2 not in t.constraints

    def test_ambig_check_constraint_auto_append(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_ambig_check_constraint_auto_append(self):
        m = MetaData()

        t = Table("tbl", m, Column("a", Integer), Column("b", Integer))

        t2 = Table("t2", m, Column("a", Integer), Column("b", Integer))
        c = CheckConstraint(t.c.a > t2.c.b)
        assert c not in t.constraints
        assert c not in t2.constraints

    def test_auto_append_ck_on_col_attach_one(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_auto_append_ck_on_col_attach_one(self):
        m = MetaData()

        a = Column("a", Integer)
        b = Column("b", Integer)
        ck = CheckConstraint(a > b)

        t = Table("tbl", m, a, b)
        assert ck in t.constraints

    def test_auto_append_ck_on_col_attach_two(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_auto_append_ck_on_col_attach_two(self):
        m = MetaData()

        a = Column("a", Integer)
        b = Column("b", Integer)
        c = Column("c", Integer)
        ck = CheckConstraint(a > b + c)

        t = Table("tbl", m, a)
        assert ck not in t.constraints

        t.append_column(b)
        assert ck not in t.constraints

        t.append_column(c)
        assert ck in t.constraints

    def test_auto_append_ck_on_col_attach_three(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_ck_name_required(self):
        u1 = self._fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint(u1.c.data == "x", name="mycheck")
        eq_(ck.name, "ck_user_mycheck")

        assert_raises_message(
            exc.InvalidRequestError,
            r"Naming convention including %\(constraint_name\)s token "
            "requires that constraint is explicitly named.",
            CheckConstraint,
            u1.c.data == "x",
        )

    def test_ck_name_deferred_required(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_ck_name_deferred_required(self):
        u1 = self._fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint(u1.c.data == "x", name=elements._defer_name(None))

        assert_raises_message(
            exc.InvalidRequestError,
            r"Naming convention including %\(constraint_name\)s token "
            "requires that constraint is explicitly named.",
            schema.AddConstraint(ck).compile,
        )

    def test_column_attached_ck_name(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_column_attached_ck_name(self):
        m = MetaData(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint("x > 5", name="x1")
        Table("t", m, Column("x", ck))
        eq_(ck.name, "ck_t_x1")

    def test_table_attached_ck_name(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_table_attached_ck_name(self):
        m = MetaData(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint("x > 5", name="x1")
        Table("t", m, Column("x", Integer), ck)
        eq_(ck.name, "ck_t_x1")

    def test_uq_name_already_conv(self):

3 Source : test_metadata.py
with Apache License 2.0
from gethue

    def test_ck_constraint_redundant_event(self):
        u1 = self._fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )

        ck1 = CheckConstraint(u1.c.version > 3, name="foo")
        u1.append_constraint(ck1)
        u1.append_constraint(ck1)
        u1.append_constraint(ck1)

        eq_(ck1.name, "ck_user_foo")

    def test_pickle_metadata(self):

3 Source : test_quote.py
with Apache License 2.0
from gethue

    def test_quote_flag_propagate_check_constraint(self):
        m = MetaData()
        t = Table("t", m, Column("x", Integer, quote=True))
        CheckConstraint(t.c.x > 5)
        self.assert_compile(
            schema.CreateTable(t),
            "CREATE TABLE t (" '"x" INTEGER, ' 'CHECK ("x" > 5)' ")",
        )

    def test_quote_flag_propagate_index(self):

3 Source : test_autogen_diffs.py
with MIT License
from sqlalchemy

    def setUp(self):
        self.metadata = m = MetaData()
        t = Table(
            "t",
            m,
            Column("id", Integer(), primary_key=True),
            Column("x", Integer()),
        )
        self.ix = Index("ix1", t.c.id)
        fk = ForeignKeyConstraint(["t_id"], ["t.id"])
        q = Table("q", m, Column("t_id", Integer()), fk)
        self.table = t
        self.fk = fk
        self.ck = CheckConstraint(t.c.x > 5)
        t.append_constraint(self.ck)
        self.uq = UniqueConstraint(q.c.t_id)
        self.pk = t.primary_key

    def test_drop_fk(self):

3 Source : test_autogen_render.py
with MIT License
from sqlalchemy

    def test_render_check_constraint_literal(self):
        eq_ignore_whitespace(
            autogenerate.render._render_check_constraint(
                CheckConstraint("im a constraint", name="cc1"),
                self.autogen_context,
                None,
            ),
            "sa.CheckConstraint('im a constraint', name='cc1')",
        )

    def test_render_check_constraint_sqlexpr(self):

3 Source : test_autogen_render.py
with MIT License
from sqlalchemy

    def test_render_check_constraint_sqlexpr(self):
        c = column("c")
        five = literal_column("5")
        ten = literal_column("10")
        eq_ignore_whitespace(
            autogenerate.render._render_check_constraint(
                CheckConstraint(and_(c > five, c   <   ten)),
                self.autogen_context,
                None,
            ),
            "sa.CheckConstraint('c > 5 AND c  <  10')",
        )

    def test_render_check_constraint_literal_binds(self):

3 Source : test_autogen_render.py
with MIT License
from sqlalchemy

    def test_render_check_constraint_literal_binds(self):
        c = column("c")
        eq_ignore_whitespace(
            autogenerate.render._render_check_constraint(
                CheckConstraint(and_(c > 5, c   <   10)),
                self.autogen_context,
                None,
            ),
            "sa.CheckConstraint('c > 5 AND c  <  10')",
        )

    def test_render_unique_constraint_opts(self):

3 Source : test_autogen_render.py
with MIT License
from sqlalchemy

    def test_inline_ck_constraint(self):
        t = Table(
            "t", self.metadata, Column("c", Integer), CheckConstraint("c > 5")
        )
        op_obj = ops.CreateTableOp.from_table(t)
        eq_ignore_whitespace(
            autogenerate.render_op_text(self.autogen_context, op_obj),
            "op.create_table('t',sa.Column('c', sa.Integer(), nullable=True),"
            "sa.CheckConstraint('c > 5', name=op.f('ck_ct_t')))",
        )

    def test_inline_fk(self):

3 Source : test_batch.py
with MIT License
from sqlalchemy

    def _named_ck_table_fixture(self, table_args=(), table_kwargs={}):
        m = MetaData()
        t = Table(
            "tname",
            m,
            Column("id", Integer, primary_key=True),
            Column("x", String()),
            Column("y", Integer),
            CheckConstraint("y > 5", name="ck1"),
        )
        return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False)

    def _named_ck_col_fixture(self, table_args=(), table_kwargs={}):

3 Source : test_batch.py
with MIT License
from sqlalchemy

    def _named_ck_col_fixture(self, table_args=(), table_kwargs={}):
        m = MetaData()
        t = Table(
            "tname",
            m,
            Column("id", Integer, primary_key=True),
            Column("x", String()),
            Column("y", Integer, CheckConstraint("y > 5", name="ck1")),
        )
        return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False)

    def _ix_fixture(self, table_args=(), table_kwargs={}):

3 Source : test_batch.py
with MIT License
from sqlalchemy

    def _literal_ck_fixture(
        self, copy_from=None, table_args=(), table_kwargs={}
    ):
        m = MetaData()
        if copy_from is not None:
            t = copy_from
        else:
            t = Table(
                "tname",
                m,
                Column("id", Integer, primary_key=True),
                Column("email", String()),
                CheckConstraint("email LIKE '%@%'"),
            )
        return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False)

    def _sql_ck_fixture(self, table_args=(), table_kwargs={}):

3 Source : test_batch.py
with MIT License
from sqlalchemy

    def _sql_ck_fixture(self, table_args=(), table_kwargs={}):
        m = MetaData()
        t = Table(
            "tname",
            m,
            Column("id", Integer, primary_key=True),
            Column("email", String()),
        )
        t.append_constraint(CheckConstraint(t.c.email.like("%@%")))
        return ApplyBatchImpl(self.impl, t, table_args, table_kwargs, False)

    def _fk_fixture(self, table_args=(), table_kwargs={}):

3 Source : test_batch.py
with MIT License
from sqlalchemy

    def _ck_constraint_fixture(self):
        with self.conn.begin():
            t = Table(
                "ck_table",
                self.metadata,
                Column("id", Integer, nullable=False),
                CheckConstraint("id is not NULL", name="ck"),
            )
            t.create(self.conn)
            return t

    def _datetime_server_default_fixture(self):

3 Source : test_op.py
with MIT License
from sqlalchemy

    def test_add_column_w_check(self):
        context = op_fixture()
        op.add_column(
            "t1",
            Column("c1", Integer, CheckConstraint("c1 > 5"), nullable=False),
        )
        context.assert_(
            "ALTER TABLE t1 ADD COLUMN c1 INTEGER NOT NULL CHECK (c1 > 5)"
        )

    def test_add_column_schema(self):

3 Source : test_op_naming_convention.py
with MIT License
from sqlalchemy

    def test_add_check_constraint_already_named_from_schema(self):
        m1 = MetaData(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint("im a constraint", name="cc1")
        Table("t", m1, Column("x"), ck)

        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )

        op.create_table("some_table", Column("x", Integer, ck))
        context.assert_(
            "CREATE TABLE some_table "
            "(x INTEGER CONSTRAINT ck_t_cc1 CHECK (im a constraint))"
        )

    def test_add_check_constraint_inline_on_table(self):

3 Source : test_op_naming_convention.py
with MIT License
from sqlalchemy

    def test_add_check_constraint_inline_on_table(self):
        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        op.create_table(
            "some_table",
            Column("x", Integer),
            CheckConstraint("im a constraint", name="cc1"),
        )
        context.assert_(
            "CREATE TABLE some_table "
            "(x INTEGER, CONSTRAINT ck_some_table_cc1 CHECK (im a constraint))"
        )

    def test_add_check_constraint_inline_on_table_w_f(self):

3 Source : test_op_naming_convention.py
with MIT License
from sqlalchemy

    def test_add_check_constraint_inline_on_table_w_f(self):
        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        op.create_table(
            "some_table",
            Column("x", Integer),
            CheckConstraint("im a constraint", name=op.f("ck_some_table_cc1")),
        )
        context.assert_(
            "CREATE TABLE some_table "
            "(x INTEGER, CONSTRAINT ck_some_table_cc1 CHECK (im a constraint))"
        )

    def test_add_check_constraint_inline_on_column(self):

3 Source : test_op_naming_convention.py
with MIT License
from sqlalchemy

    def test_add_check_constraint_inline_on_column(self):
        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        op.create_table(
            "some_table",
            Column(
                "x", Integer, CheckConstraint("im a constraint", name="cc1")
            ),
        )
        context.assert_(
            "CREATE TABLE some_table "
            "(x INTEGER CONSTRAINT ck_some_table_cc1 CHECK (im a constraint))"
        )

    def test_add_check_constraint_inline_on_column_w_f(self):

3 Source : test_op_naming_convention.py
with MIT License
from sqlalchemy

    def test_add_check_constraint_inline_on_column_w_f(self):
        context = op_fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        op.create_table(
            "some_table",
            Column(
                "x",
                Integer,
                CheckConstraint("im a constraint", name=op.f("ck_q_cc1")),
            ),
        )
        context.assert_(
            "CREATE TABLE some_table "
            "(x INTEGER CONSTRAINT ck_q_cc1 CHECK (im a constraint))"
        )

    def test_add_column_schema_type(self):

3 Source : test_compiler.py
with MIT License
from sqlalchemy

    def test_drop_constraint_mariadb(self):
        m = MetaData()
        table_name = "testtbl"
        constraint_name = "constraint"
        constraint = CheckConstraint("data IS NOT NULL", name=constraint_name)
        Table(table_name, m, Column("data", String(255)), constraint)
        self.assert_compile(
            schema.DropConstraint(constraint),
            "ALTER TABLE %s DROP CONSTRAINT `%s`"
            % (table_name, constraint_name),
            dialect="mariadb",
        )

    def test_create_index_with_length_quoted(self):

3 Source : test_compiler.py
with MIT License
from sqlalchemy

    def test_create_check_constraint_not_valid(self):
        m = MetaData()

        tbl = Table(
            "testtbl",
            m,
            Column("data", Integer),
            CheckConstraint("data = 0", postgresql_not_valid=True),
        )

        self.assert_compile(
            schema.CreateTable(tbl),
            "CREATE TABLE testtbl (data INTEGER, CHECK (data = 0) NOT VALID)",
        )

    def test_create_foreign_key_constraint_not_valid(self):

3 Source : test_metadata.py
with MIT License
from sqlalchemy

    def test_check_constraint_copy(self):
        def r(x):
            return x

        c = CheckConstraint(
            "foo bar",
            name="name",
            initially=True,
            deferrable=True,
            _create_rule=r,
        )
        c2 = c._copy()
        eq_(c2.name, "name")
        eq_(str(c2.sqltext), "foo bar")
        eq_(c2.initially, True)
        eq_(c2.deferrable, True)
        assert c2._create_rule is r

    def test_col_replace_w_constraint(self):

3 Source : test_metadata.py
with MIT License
from sqlalchemy

    def test_auto_append_lowercase_table(self):
        from sqlalchemy import table, column

        t = table("t", column("a"))
        t2 = table("t2", column("a"))
        for c in (
            UniqueConstraint(t.c.a),
            CheckConstraint(t.c.a > 5),
            ForeignKeyConstraint([t.c.a], [t2.c.a]),
            PrimaryKeyConstraint(t.c.a),
            Index("foo", t.c.a),
        ):
            assert True

    def test_to_metadata_ok(self):

3 Source : test_metadata.py
with MIT License
from sqlalchemy

    def test_check_constraint_copy(self):
        m = MetaData()
        t = Table("tbl", m, Column("a", Integer), Column("b", Integer))
        ck = CheckConstraint(t.c.a > 5)
        ck2 = ck._copy()
        assert ck in t.constraints
        assert ck2 not in t.constraints

    def test_ambig_check_constraint_auto_append(self):

3 Source : test_metadata.py
with MIT License
from sqlalchemy

    def test_pickle_ck_binary_annotated_col(self, no_pickle_annotated):
        t, q_col = no_pickle_annotated

        ck = CheckConstraint(q_col > 5)
        t.append_constraint(ck)

        m2 = pickle.loads(pickle.dumps(t.metadata))
        const = [
            c
            for c in m2.tables["t"].constraints
            if isinstance(c, CheckConstraint)
        ][0]
        is_true(const.sqltext.compare(ck.sqltext))


class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase):

3 Source : test_metadata.py
with MIT License
from sqlalchemy

    def test_ck_name_deferred_required(self):
        u1 = self._fixture(
            naming_convention={"ck": "ck_%(table_name)s_%(constraint_name)s"}
        )
        ck = CheckConstraint(u1.c.data == "x", name=naming._NONE_NAME)

        assert_raises_message(
            exc.InvalidRequestError,
            r"Naming convention including %\(constraint_name\)s token "
            "requires that constraint is explicitly named.",
            schema.AddConstraint(ck).compile,
        )

    def test_column_attached_ck_name(self):

0 Source : test_reflection.py
with MIT License
from analyzeDFIR

    def _test_get_check_constraints(self, schema=None):
        orig_meta = self.metadata
        Table(
            'sa_cc', orig_meta,
            Column('a', Integer()),
            sa.CheckConstraint('a > 1 AND a   <   5', name='cc1'),
            sa.CheckConstraint('a = 1 OR (a > 2 AND a  <  5)', name='cc2'),
            schema=schema
        )

        orig_meta.create_all()

        inspector = inspect(orig_meta.bind)
        reflected = sorted(
            inspector.get_check_constraints('sa_cc', schema=schema),
            key=operator.itemgetter('name')
        )

        # trying to minimize effect of quoting, parenthesis, etc.
        # may need to add more to this as new dialects get CHECK
        # constraint reflection support
        def normalize(sqltext):
            return " ".join(re.findall(r"and|\d|=|a|or| < |>", sqltext.lower(), re.I))

        reflected = [
            {"name": item["name"],
             "sqltext": normalize(item["sqltext"])}
            for item in reflected
        ]
        eq_(
            reflected,
            [
                {'name': 'cc1', 'sqltext': 'a > 1 and a  <  5'},
                {'name': 'cc2', 'sqltext': 'a = 1 or a > 2 and a  <  5'}
            ]
        )

    @testing.provide_metadata

0 Source : test_reflection.py
with MIT License
from dhina016

    def _test_get_check_constraints(self, schema=None):
        orig_meta = self.metadata
        Table(
            "sa_cc",
            orig_meta,
            Column("a", Integer()),
            sa.CheckConstraint("a > 1 AND a   <   5", name="cc1"),
            sa.CheckConstraint("a = 1 OR (a > 2 AND a  <  5)", name="cc2"),
            schema=schema,
        )

        orig_meta.create_all()

        inspector = inspect(orig_meta.bind)
        reflected = sorted(
            inspector.get_check_constraints("sa_cc", schema=schema),
            key=operator.itemgetter("name"),
        )

        # trying to minimize effect of quoting, parenthesis, etc.
        # may need to add more to this as new dialects get CHECK
        # constraint reflection support
        def normalize(sqltext):
            return " ".join(
                re.findall(r"and|\d|=|a|or| < |>", sqltext.lower(), re.I)
            )

        reflected = [
            {"name": item["name"], "sqltext": normalize(item["sqltext"])}
            for item in reflected
        ]
        eq_(
            reflected,
            [
                {"name": "cc1", "sqltext": "a > 1 and a  <  5"},
                {"name": "cc2", "sqltext": "a = 1 or a > 2 and a  <  5"},
            ],
        )

    @testing.provide_metadata

See More Examples