summaryrefslogtreecommitdiff
path: root/tests/test_op.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-03-14 16:41:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-03-14 16:41:21 -0400
commitce7ce28f3c11774c61668663fe60ff41080de90a (patch)
tree7e010a9e8262d400d4456ca4978ffa089fc206a3 /tests/test_op.py
parent623c7e76ef04c5656d7a116287a39e318f6744b1 (diff)
downloadalembic-ce7ce28f3c11774c61668663fe60ff41080de90a.tar.gz
- Added support for the ``initially``, ``match`` keyword arguments
as well as dialect-specific keyword arguments to :meth:`.Operations.create_foreign_key`. fixes #190
Diffstat (limited to 'tests/test_op.py')
-rw-r--r--tests/test_op.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/test_op.py b/tests/test_op.py
index a243aeb..1b82af3 100644
--- a/tests/test_op.py
+++ b/tests/test_op.py
@@ -6,7 +6,8 @@ from sqlalchemy.sql import column, func, text
from sqlalchemy import event
from alembic import op
-from . import op_fixture, assert_raises_message, requires_094
+from . import op_fixture, assert_raises_message, requires_094, eq_
+import mock
@event.listens_for(Table, "after_parent_attach")
def _add_cols(table, metadata):
@@ -397,6 +398,38 @@ def test_add_foreign_key_deferrable():
"REFERENCES t2 (bat, hoho) DEFERRABLE"
)
+def test_add_foreign_key_initially():
+ context = op_fixture()
+ op.create_foreign_key('fk_test', 't1', 't2',
+ ['foo', 'bar'], ['bat', 'hoho'],
+ initially='INITIAL')
+ context.assert_(
+ "ALTER TABLE t1 ADD CONSTRAINT fk_test FOREIGN KEY(foo, bar) "
+ "REFERENCES t2 (bat, hoho) INITIALLY INITIAL"
+ )
+
+def test_add_foreign_key_match():
+ context = op_fixture()
+ op.create_foreign_key('fk_test', 't1', 't2',
+ ['foo', 'bar'], ['bat', 'hoho'],
+ match='SIMPLE')
+ context.assert_(
+ "ALTER TABLE t1 ADD CONSTRAINT fk_test FOREIGN KEY(foo, bar) "
+ "REFERENCES t2 (bat, hoho) MATCH SIMPLE"
+ )
+
+def test_add_foreign_key_dialect_kw():
+ context = op_fixture()
+ with mock.patch("alembic.operations.sa_schema.ForeignKeyConstraint") as fkc:
+ op.create_foreign_key('fk_test', 't1', 't2',
+ ['foo', 'bar'], ['bat', 'hoho'],
+ foobar_arg='xyz')
+ eq_(fkc.mock_calls[0],
+ mock.call(['foo', 'bar'], ['t2.bat', 't2.hoho'],
+ onupdate=None, ondelete=None, name='fk_test',
+ foobar_arg='xyz',
+ deferrable=None, initially=None, match=None))
+
def test_add_foreign_key_self_referential():
context = op_fixture()
op.create_foreign_key("fk_test", "t1", "t1", ["foo"], ["bar"])