summaryrefslogtreecommitdiff
path: root/test/sql/test_constraints.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-12-11 16:31:41 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-12-11 16:31:41 -0500
commitfbd81de0ebdbc54b0df6ba08cc8309e1328888fa (patch)
tree2dd468791587e60966d5122f0c6cedabf22c1dea /test/sql/test_constraints.py
parentd9d6dcea77a848ed9acf5611abb4d00387737e17 (diff)
downloadsqlalchemy-fbd81de0ebdbc54b0df6ba08cc8309e1328888fa.tar.gz
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]
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r--test/sql/test_constraints.py39
1 files changed, 39 insertions, 0 deletions
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()