]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
ForeignKeyConstraint reflection test respects MySQL limitations
authorijl <uijllji@gmail.com>
Tue, 15 Oct 2013 20:01:25 +0000 (16:01 -0400)
committerijl <uijllji@gmail.com>
Tue, 15 Oct 2013 20:01:25 +0000 (16:01 -0400)
test/engine/test_reflection.py

index 3b23bf31aaefeb5e27b21d336cd61f6df439cb13..c360527818983a376aca5f715052a016fee1553d 100644 (file)
@@ -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