diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-28 17:25:44 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-28 17:25:44 -0400 |
| commit | fe66951f5de6a2b201dc3ecc2261f4f8b8888e9f (patch) | |
| tree | efe0e66dbd262ef473094514cc14fcc9854e464f /test/engine/test_reflection.py | |
| parent | 03c9b2df770385fc3b2b0acbdcb809c2239b67ef (diff) | |
| download | sqlalchemy-fe66951f5de6a2b201dc3ecc2261f4f8b8888e9f.tar.gz | |
Fixed bug where using the ``column_reflect`` event to change the ``.key``
of the incoming :class:`.Column` would prevent primary key constraints,
indexes, and foreign key constraints from being correctly reflected.
Also in 0.8.3. [ticket:2811]
Diffstat (limited to 'test/engine/test_reflection.py')
| -rw-r--r-- | test/engine/test_reflection.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 52cbc15e6..532de1c35 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -1431,6 +1431,12 @@ class ColumnEventsTest(fixtures.TestBase): cls.metadata, Column('x', sa.Integer, primary_key=True), ) + cls.related = Table( + 'related', + cls.metadata, + Column('q', sa.Integer, sa.ForeignKey('to_reflect.x')) + ) + sa.Index("some_index", cls.to_reflect.c.x) cls.metadata.create_all(testing.db) @classmethod @@ -1440,7 +1446,7 @@ class ColumnEventsTest(fixtures.TestBase): def teardown(self): events.SchemaEventTarget.dispatch._clear() - def _do_test(self, col, update, assert_): + def _do_test(self, col, update, assert_, tablename="to_reflect"): # load the actual Table class, not the test # wrapper from sqlalchemy.schema import Table @@ -1450,22 +1456,46 @@ class ColumnEventsTest(fixtures.TestBase): if column_info['name'] == col: column_info.update(update) - t = Table('to_reflect', m, autoload=True, listeners=[ + t = Table(tablename, m, autoload=True, listeners=[ ('column_reflect', column_reflect), ]) assert_(t) m = MetaData(testing.db) event.listen(Table, 'column_reflect', column_reflect) - t2 = Table('to_reflect', m, autoload=True) + t2 = Table(tablename, m, autoload=True) assert_(t2) def test_override_key(self): + def assertions(table): + eq_(table.c.YXZ.name, "x") + eq_(set(table.primary_key), set([table.c.YXZ])) + idx = list(table.indexes)[0] + eq_(idx.columns, [table.c.YXZ]) + self._do_test( "x", {"key": "YXZ"}, - lambda table: eq_(table.c.YXZ.name, "x") + assertions ) + def test_override_key_fk(self): + m = MetaData(testing.db) + def column_reflect(insp, table, column_info): + + if column_info['name'] == 'q': + column_info['key'] = 'qyz' + elif column_info['name'] == 'x': + column_info['key'] = 'xyz' + + to_reflect = Table("to_reflect", m, autoload=True, listeners=[ + ('column_reflect', column_reflect), + ]) + related = Table("related", m, autoload=True, listeners=[ + ('column_reflect', column_reflect), + ]) + + assert related.c.qyz.references(to_reflect.c.xyz) + def test_override_type(self): def assert_(table): assert isinstance(table.c.x.type, sa.String) |
