From 52cfa74e094c32910fa1076375f1ae0c9795d45d Mon Sep 17 00:00:00 2001 From: ijl Date: Sun, 13 Oct 2013 17:13:28 -0400 Subject: #2183: Metadata.reflect() foreign keys include options when the dialect exposes it --- test/engine/test_reflection.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/engine') diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 21c050915..3b23bf31a 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -602,6 +602,47 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): is a2.c.user_id assert u2.join(a2).onclause.compare(u2.c.id == a2.c.user_id) + @testing.only_on(['postgresql', 'mysql']) + @testing.provide_metadata + def test_fk_options(self): + """test that foreign key reflection includes options (on + backends with {dialect}.get_foreign_keys() support)""" + + # fk whose attributes we're testing on reflection + addresses_user_id_fkey = sa.ForeignKey( + 'users.id', + name = 'addresses_user_id_fkey', + match='FULL', + onupdate='RESTRICT', + ondelete='RESTRICT', + deferrable=True, + initially='DEFERRED' + ) + + # only test implemented attrs + if testing.against('postgresql'): + test_attrs = ('match', 'onupdate', 'ondelete', 'deferrable', 'initially') + elif testing.against('mysql'): + test_attrs = ('onupdate', 'ondelete') + + meta = self.metadata + Table('users', meta, + Column('id', sa.Integer, primary_key=True), + Column('name', sa.String(30)), + test_needs_fk=True) + Table('addresses', meta, + Column('id', sa.Integer, primary_key=True), + Column('user_id', sa.Integer, addresses_user_id_fkey), + test_needs_fk=True) + meta.create_all() + + meta2 = MetaData() + meta2.reflect(testing.db) + for fk in meta2.tables['addresses'].foreign_keys: + ref = locals()[fk.name] + for attr in test_attrs: + assert getattr(fk, attr) == getattr(ref, attr) + def test_pks_not_uniques(self): """test that primary key reflection not tripped up by unique indexes""" -- cgit v1.2.1 From f17e8a4452de1363263d4aad9b24612570d64ccc Mon Sep 17 00:00:00 2001 From: ijl Date: Tue, 15 Oct 2013 16:01:25 -0400 Subject: ForeignKeyConstraint reflection test respects MySQL limitations --- test/engine/test_reflection.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'test/engine') diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 3b23bf31a..c36052781 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -608,21 +608,29 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): """test that foreign key reflection includes options (on backends with {dialect}.get_foreign_keys() support)""" - # fk whose attributes we're testing on reflection - addresses_user_id_fkey = sa.ForeignKey( - 'users.id', - name = 'addresses_user_id_fkey', - match='FULL', - onupdate='RESTRICT', - ondelete='RESTRICT', - deferrable=True, - initially='DEFERRED' - ) - - # only test implemented attrs if testing.against('postgresql'): test_attrs = ('match', 'onupdate', 'ondelete', 'deferrable', 'initially') + addresses_user_id_fkey = sa.ForeignKey( + # Each option is specifically not a Postgres default, or + # it won't be returned by PG's inspection + 'users.id', + name = 'addresses_user_id_fkey', + match='FULL', + onupdate='RESTRICT', + ondelete='RESTRICT', + deferrable=True, + initially='DEFERRED' + ) elif testing.against('mysql'): + # MATCH, DEFERRABLE, and INITIALLY cannot be defined for MySQL + # ON UPDATE and ON DELETE have defaults of RESTRICT, which are + # elided by MySQL's inspection + addresses_user_id_fkey = sa.ForeignKey( + 'users.id', + name = 'addresses_user_id_fkey', + onupdate='CASCADE', + ondelete='CASCADE' + ) test_attrs = ('onupdate', 'ondelete') meta = self.metadata -- cgit v1.2.1