summaryrefslogtreecommitdiff
path: root/tests/test_op.py
diff options
context:
space:
mode:
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"])