summaryrefslogtreecommitdiff
path: root/test/dialect/test_sqlite.py
diff options
context:
space:
mode:
authorMichal Petrucha <michal.petrucha@koniiiik.org>2016-04-11 23:16:24 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-02 17:49:09 -0400
commit0e88bcc30ed49193b91f248123f526fa30007f22 (patch)
tree2ea922bc52235cf876181579771c9b9d8cc2b53c /test/dialect/test_sqlite.py
parent59d90c95a133ee6b4a4db8ed61c699956eb33e9f (diff)
downloadsqlalchemy-0e88bcc30ed49193b91f248123f526fa30007f22.tar.gz
Reflect ON DELETE and ON UPDATE for SQLite foreign keys
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: Icd77ddbf851b1950f767022d67c8142b1b3c50f3 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/244
Diffstat (limited to 'test/dialect/test_sqlite.py')
-rw-r--r--test/dialect/test_sqlite.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py
index dde9da086..16a628777 100644
--- a/test/dialect/test_sqlite.py
+++ b/test/dialect/test_sqlite.py
@@ -1146,6 +1146,16 @@ class ConstraintReflectionTest(fixtures.TestBase):
# will contain an "autoindex"
conn.execute("create table o (foo varchar(20) primary key)")
+ conn.execute(
+ "CREATE TABLE onud_test (id INTEGER PRIMARY KEY, "
+ "c1 INTEGER, c2 INTEGER, c3 INTEGER, "
+ "CONSTRAINT fk1 FOREIGN KEY (c1) REFERENCES a1(id) "
+ "ON DELETE SET NULL, "
+ "CONSTRAINT fk2 FOREIGN KEY (c2) REFERENCES a1(id) "
+ "ON UPDATE CASCADE, "
+ "CONSTRAINT fk3 FOREIGN KEY (c3) REFERENCES a2(id) "
+ "ON DELETE CASCADE ON UPDATE SET NULL)"
+ )
conn.execute(
"CREATE TABLE cp ("
@@ -1283,6 +1293,33 @@ class ConstraintReflectionTest(fixtures.TestBase):
'constrained_columns': ['q', 'p']}]
)
+ def test_foreign_key_ondelete_onupdate(self):
+ inspector = Inspector(testing.db)
+ fks = inspector.get_foreign_keys('onud_test')
+ eq_(
+ fks,
+ [
+ {
+ 'referred_table': 'a1', 'referred_columns': ['id'],
+ 'referred_schema': None, 'name': 'fk1',
+ 'constrained_columns': ['c1'],
+ 'options': {'ondelete': 'SET NULL'}
+ },
+ {
+ 'referred_table': 'a1', 'referred_columns': ['id'],
+ 'referred_schema': None, 'name': 'fk2',
+ 'constrained_columns': ['c2'],
+ 'options': {'onupdate': 'CASCADE'}
+ },
+ {
+ 'referred_table': 'a2', 'referred_columns': ['id'],
+ 'referred_schema': None, 'name': 'fk3',
+ 'constrained_columns': ['c3'],
+ 'options': {'ondelete': 'CASCADE', 'onupdate': 'SET NULL'}
+ },
+ ]
+ )
+
def test_dont_reflect_autoindex(self):
inspector = Inspector(testing.db)
eq_(inspector.get_indexes('o'), [])