diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 16:08:35 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-24 16:08:35 -0400 |
commit | f69ccd193b5f1bfe4f2f50e93fe912ceac1af66e (patch) | |
tree | fa618540df1d0611855e971720e98604511b9ffe /test/sql/test_constraints.py | |
parent | ae90ba28e85835c278c64d5894ee1a983d11e400 (diff) | |
download | sqlalchemy-f69ccd193b5f1bfe4f2f50e93fe912ceac1af66e.tar.gz |
- [bug] All of UniqueConstraint, ForeignKeyConstraint,
CheckConstraint, and PrimaryKeyConstraint will
attach themselves to their parent table automatically
when they refer to a Table-bound Column object directly
(i.e. not just string column name), and refer to
one and only one Table. Prior to 0.8 this behavior
occurred for UniqueConstraint and PrimaryKeyConstraint,
but not ForeignKeyConstraint or CheckConstraint.
[ticket:2410]
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r-- | test/sql/test_constraints.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 5ea5a7eda..546a14ca2 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -437,7 +437,8 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): ) constraint = CheckConstraint('a < b',name="my_test_constraint", - deferrable=True,initially='DEFERRED', table=t) + deferrable=True,initially='DEFERRED', + table=t) # before we create an AddConstraint, @@ -513,4 +514,44 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): "ALTER TABLE tbl ADD PRIMARY KEY (a)" ) + def test_auto_append_constraint(self): + m = MetaData() + + t = Table('tbl', m, + Column('a', Integer), + Column('b', Integer) + ) + + t2 = Table('t2', m, + Column('a', Integer), + Column('b', Integer) + ) + + for c in ( + UniqueConstraint(t.c.a), + CheckConstraint(t.c.a > 5), + ForeignKeyConstraint([t.c.a], [t2.c.a]), + PrimaryKeyConstraint(t.c.a) + ): + assert c in t.constraints + t.append_constraint(c) + assert c in t.constraints + c = Index('foo', t.c.a) + assert c in t.indexes + + 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
\ No newline at end of file |