diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-11 19:48:27 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-11 19:48:27 -0500 |
| commit | 84af7e6c22100ef26c5a27185b1d270f5afb3370 (patch) | |
| tree | 18aa3efba3349c572c381aaf7ed1a74753e11e2d /test/sql/test_metadata.py | |
| parent | 9087157749a0527d6af37e58166793fc7e2f0bf7 (diff) | |
| download | sqlalchemy-84af7e6c22100ef26c5a27185b1d270f5afb3370.tar.gz | |
- The :class:`.ForeignKey` class more aggressively checks the given
column argument. If not a string, it checks that the object is
at least a :class:`.ColumnClause`, or an object that resolves to one,
and that the ``.table`` attribute, if present, refers to a
:class:`.TableClause` or subclass, and not something like an
:class:`.Alias`. Otherwise, a :class:`.ArgumentError` is raised.
[ticket:2883]
Diffstat (limited to 'test/sql/test_metadata.py')
| -rw-r--r-- | test/sql/test_metadata.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index d0a79a7bb..c5caa9780 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -6,7 +6,7 @@ import pickle from sqlalchemy import Integer, String, UniqueConstraint, \ CheckConstraint, ForeignKey, MetaData, Sequence, \ ForeignKeyConstraint, ColumnDefault, Index, event,\ - events, Unicode, types as sqltypes + events, Unicode, types as sqltypes, bindparam from sqlalchemy.testing.schema import Table, Column from sqlalchemy import schema, exc import sqlalchemy as tsa @@ -236,6 +236,45 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): go ) + def test_fk_given_non_col(self): + not_a_col = bindparam('x') + assert_raises_message( + exc.ArgumentError, + "String, Column, or Column-bound argument expected, got Bind", + ForeignKey, not_a_col + ) + + def test_fk_given_non_col_clauseelem(self): + class Foo(object): + def __clause_element__(self): + return bindparam('x') + assert_raises_message( + exc.ArgumentError, + "String, Column, or Column-bound argument expected, got Bind", + ForeignKey, Foo() + ) + + def test_fk_given_col_non_table(self): + t = Table('t', MetaData(), Column('x', Integer)) + xa = t.alias().c.x + assert_raises_message( + exc.ArgumentError, + "ForeignKey received Column not bound to a Table, got: .*Alias", + ForeignKey, xa + ) + + def test_fk_given_col_non_table_clauseelem(self): + t = Table('t', MetaData(), Column('x', Integer)) + class Foo(object): + def __clause_element__(self): + return t.alias().c.x + + assert_raises_message( + exc.ArgumentError, + "ForeignKey received Column not bound to a Table, got: .*Alias", + ForeignKey, Foo() + ) + def test_fk_no_such_target_col_error_upfront(self): meta = MetaData() a = Table('a', meta, Column('a', Integer)) |
