diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-05-17 11:45:05 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-05-17 11:45:05 -0400 |
| commit | 29251675503271fc700a6f7655157850e2de426d (patch) | |
| tree | 0a6f5a43525fc2e5390716812e511893cc8e9ce7 /test/engine/test_reflection.py | |
| parent | da8032dc45ad8243323e9359f9b31efe1b7cfe5b (diff) | |
| download | sqlalchemy-29251675503271fc700a6f7655157850e2de426d.tar.gz | |
- [feature] The "deferred declarative
reflection" system has been moved into the
declarative extension itself, using the
new DeferredReflection class. This
class is now tested with both single
and joined table inheritance use cases.
[ticket:2485]
- [bug] The autoload_replace flag on Table,
when False, will cause any reflected foreign key
constraints which refer to already-declared
columns to be skipped, assuming that the
in-Python declared column will take over
the task of specifying in-Python ForeignKey
or ForeignKeyConstraint declarations.
Diffstat (limited to 'test/engine/test_reflection.py')
| -rw-r--r-- | test/engine/test_reflection.py | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 6bfc3246a..be2acb1f3 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -201,7 +201,11 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): assert len(t2.indexes) == 2 @testing.provide_metadata - def test_autoload_replace_foreign_key(self): + def test_autoload_replace_foreign_key_nonpresent(self): + """test autoload_replace=False with col plus FK + establishes the FK not present in the DB. + + """ a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) b = Table('b', self.metadata, Column('id', Integer, primary_key=True), Column('a_id', Integer)) @@ -219,6 +223,51 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): eq_(len(b2.constraints), 2) @testing.provide_metadata + def test_autoload_replace_foreign_key_ispresent(self): + """test autoload_replace=False with col plus FK mirroring + DB-reflected FK skips the reflected FK and installs + the in-python one only. + + """ + a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) + b = Table('b', self.metadata, Column('id', Integer, primary_key=True), + Column('a_id', Integer, sa.ForeignKey('a.id'))) + self.metadata.create_all() + + m2 = MetaData() + b2 = Table('b', m2, Column('a_id', Integer, sa.ForeignKey('a.id'))) + a2 = Table('a', m2, autoload=True, autoload_with=testing.db) + b2 = Table('b', m2, extend_existing=True, autoload=True, + autoload_with=testing.db, + autoload_replace=False) + + assert b2.c.id is not None + assert b2.c.a_id.references(a2.c.id) + eq_(len(b2.constraints), 2) + + @testing.provide_metadata + def test_autoload_replace_foreign_key_removed(self): + """test autoload_replace=False with col minus FK that's in the + DB means the FK is skipped and doesn't get installed at all. + + """ + a = Table('a', self.metadata, Column('id', Integer, primary_key=True)) + b = Table('b', self.metadata, Column('id', Integer, primary_key=True), + Column('a_id', Integer, sa.ForeignKey('a.id'))) + self.metadata.create_all() + + m2 = MetaData() + b2 = Table('b', m2, Column('a_id', Integer)) + a2 = Table('a', m2, autoload=True, autoload_with=testing.db) + b2 = Table('b', m2, extend_existing=True, autoload=True, + autoload_with=testing.db, + autoload_replace=False) + + assert b2.c.id is not None + assert not b2.c.a_id.references(a2.c.id) + eq_(len(b2.constraints), 1) + + @testing.provide_metadata def test_autoload_replace_primary_key(self): a = Table('a', self.metadata, Column('id', Integer)) self.metadata.create_all() |
