From fbd81de0ebdbc54b0df6ba08cc8309e1328888fa Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 11 Dec 2012 16:31:41 -0500 Subject: Fixed a regression caused by :ticket:`2410` whereby a :class:`.CheckConstraint` would apply itself back to the original table during a :meth:`.Table.tometadata` operation, as it would parse the SQL expression for a parent table. The operation now copies the given expression to correspond to the new table. [ticket:2633] --- test/sql/test_constraints.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/sql') diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 261932a7f..b0ecae791 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -599,6 +599,45 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): c = Index('foo', t.c.a) assert c in t.indexes + def test_tometadata_ok(self): + m = MetaData() + + t = Table('tbl', m, + Column('a', Integer), + Column('b', Integer) + ) + + t2 = Table('t2', m, + Column('a', Integer), + Column('b', Integer) + ) + + uq = UniqueConstraint(t.c.a) + ck = CheckConstraint(t.c.a > 5) + fk = ForeignKeyConstraint([t.c.a], [t2.c.a]) + pk = PrimaryKeyConstraint(t.c.a) + + m2 = MetaData() + + t3 = t.tometadata(m2) + + eq_(len(t3.constraints), 4) + + for c in t3.constraints: + assert c.table is t3 + + 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): m = MetaData() -- cgit v1.2.1