diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-04 13:48:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-04 13:48:46 -0500 |
commit | e46301b5154000148155ef00d15b35857ebb31ad (patch) | |
tree | 2b34b20e2ac178827a9b907b95559efee5fddfb1 /test/sql/test_constraints.py | |
parent | 8f78d5ba00f7e8656bdd7fd07dbadb5a6b4d1b72 (diff) | |
download | sqlalchemy-e46301b5154000148155ef00d15b35857ebb31ad.tar.gz |
- The Index() construct can be created inline with a Table
definition, using strings as column names, as an alternative
to the creation of the index outside of the Table.
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r-- | test/sql/test_constraints.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index fb07bf437..4bacbd271 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -217,6 +217,43 @@ class ConstraintTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL): dialect=dialect ) + def test_index_declartion_inline(self): + t1 = Table('t1', metadata, + Column('x', Integer), + Column('y', Integer), + Index('foo', 'x', 'y') + ) + self.assert_compile( + schema.CreateIndex(list(t1.indexes)[0]), + "CREATE INDEX foo ON t1 (x, y)" + ) + + def test_index_asserts_cols_standalone(self): + t1 = Table('t1', metadata, + Column('x', Integer) + ) + t2 = Table('t2', metadata, + Column('y', Integer) + ) + assert_raises_message( + exc.ArgumentError, + "Column 't2.y' is not part of table 't1'.", + Index, + "bar", t1.c.x, t2.c.y + ) + + def test_index_asserts_cols_inline(self): + t1 = Table('t1', metadata, + Column('x', Integer) + ) + assert_raises_message( + exc.ArgumentError, + "Index 'bar' is against table 't1', and " + "cannot be associated with table 't2'.", + Table, 't2', metadata, + Column('y', Integer), + Index('bar', t1.c.x) + ) class ConstraintCompilationTest(TestBase, AssertsCompiledSQL): |