]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- Fixed bug where the "source_schema" argument was not correctly passed
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Nov 2014 16:46:37 +0000 (11:46 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 30 Nov 2014 16:46:37 +0000 (11:46 -0500)
when calling :meth:`.BatchOperations.create_foreign_key`.  Pull
request courtesy Malte Marquarding.
- add tests

docs/build/changelog.rst
tests/test_batch.py

index 3c9927cee792148bf02025b7065cbc44964b8db7..1179e55784e257743f1c2db49ad3ef984d1c5507 100644 (file)
@@ -6,6 +6,14 @@ Changelog
 .. changelog::
     :version: 0.7.1
 
+    .. change::
+      :tags: bug, batch
+      :pullreq: bitbucket:34
+
+      Fixed bug where the "source_schema" argument was not correctly passed
+      when calling :meth:`.BatchOperations.create_foreign_key`.  Pull
+      request courtesy Malte Marquarding.
+
     .. change::
       :tags: bug, batch
       :tickets: 249
index 662714e135fd931c203bbd47e10988280d8ab79c..7f88a801a0b37eddf76202613e1b069bfa90850e 100644 (file)
@@ -440,10 +440,11 @@ class BatchAPITest(TestBase):
     __requires__ = ('sqlalchemy_08', )
 
     @contextmanager
-    def _fixture(self):
+    def _fixture(self, schema=None):
         migration_context = mock.Mock(opts={})
         op = Operations(migration_context)
-        batch = op.batch_alter_table('tname', recreate='never').__enter__()
+        batch = op.batch_alter_table(
+            'tname', recreate='never', schema=schema).__enter__()
 
         with mock.patch("alembic.operations.sa_schema") as mock_schema:
             yield batch
@@ -482,8 +483,60 @@ class BatchAPITest(TestBase):
                 mock.call(
                     ['x'], ['user.y'],
                     onupdate=None, ondelete=None, name='myfk',
-                    initially=None, deferrable=None, match=None,
-                    schema=None)
+                    initially=None, deferrable=None, match=None)
+            ]
+        )
+        eq_(
+            self.mock_schema.Table.mock_calls,
+            [
+                mock.call(
+                    'user', self.mock_schema.MetaData(),
+                    self.mock_schema.Column(),
+                    schema=None
+                ),
+                mock.call(
+                    'tname', self.mock_schema.MetaData(),
+                    self.mock_schema.Column(),
+                    schema=None
+                ),
+                mock.call().append_constraint(
+                    self.mock_schema.ForeignKeyConstraint())
+            ]
+        )
+        eq_(
+            batch.impl.operations.impl.mock_calls,
+            [mock.call.add_constraint(
+                self.mock_schema.ForeignKeyConstraint())]
+        )
+
+    def test_create_fk_schema(self):
+        with self._fixture(schema='foo') as batch:
+            batch.create_foreign_key('myfk', 'user', ['x'], ['y'])
+
+        eq_(
+            self.mock_schema.ForeignKeyConstraint.mock_calls,
+            [
+                mock.call(
+                    ['x'], ['user.y'],
+                    onupdate=None, ondelete=None, name='myfk',
+                    initially=None, deferrable=None, match=None)
+            ]
+        )
+        eq_(
+            self.mock_schema.Table.mock_calls,
+            [
+                mock.call(
+                    'user', self.mock_schema.MetaData(),
+                    self.mock_schema.Column(),
+                    schema=None
+                ),
+                mock.call(
+                    'tname', self.mock_schema.MetaData(),
+                    self.mock_schema.Column(),
+                    schema='foo'
+                ),
+                mock.call().append_constraint(
+                    self.mock_schema.ForeignKeyConstraint())
             ]
         )
         eq_(