summaryrefslogtreecommitdiff
path: root/test/dialect/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-12-23 04:47:52 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-12-23 04:47:52 +0000
commit864644bee4e3acc5c63eac6e639ae39d1c3c8393 (patch)
treec29617f0eafe9050423a1b8b253b2e30c8ee903f /test/dialect/postgres.py
parent5b09d8179e6bd329829f7c196cb7c05f8fca20bd (diff)
downloadsqlalchemy-864644bee4e3acc5c63eac6e639ae39d1c3c8393.tar.gz
- Added Index reflection support to Postgres, using a
great patch we long neglected, submitted by Ken Kuhlman. [ticket:714]
Diffstat (limited to 'test/dialect/postgres.py')
-rw-r--r--test/dialect/postgres.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/dialect/postgres.py b/test/dialect/postgres.py
index 8298b81f6..75c0918b8 100644
--- a/test/dialect/postgres.py
+++ b/test/dialect/postgres.py
@@ -618,6 +618,54 @@ class MiscTest(TestBase, AssertsExecutionResults):
finally:
testing.db.execute("drop table speedy_users", None)
+ @testing.emits_warning()
+ def test_index_reflection(self):
+ """ Reflecting partial & expression-based indexes should warn """
+ import warnings
+ def capture_warnings(*args, **kw):
+ capture_warnings._orig_showwarning(*args, **kw)
+ capture_warnings.warnings.append(args)
+ capture_warnings._orig_showwarning = warnings.warn
+ capture_warnings.warnings = []
+
+ m1 = MetaData(testing.db)
+ t1 = Table('party', m1,
+ Column('id', String(10), nullable=False),
+ Column('name', String(20), index=True)
+ )
+ m1.create_all()
+ testing.db.execute("""
+ create index idx1 on party ((id || name))
+ """, None)
+ testing.db.execute("""
+ create unique index idx2 on party (id) where name = 'test'
+ """, None)
+ try:
+ m2 = MetaData(testing.db)
+
+ warnings.warn = capture_warnings
+ t2 = Table('party', m2, autoload=True)
+
+ wrn = capture_warnings.warnings
+ assert str(wrn[0][0]) == (
+ "Skipped unsupported reflection of expression-based index idx1")
+ assert str(wrn[1][0]) == (
+ "Predicate of partial index idx2 ignored during reflection")
+ assert len(t2.indexes) == 2
+ # Make sure indexes are in the order we expect them in
+ tmp = [(idx.name, idx) for idx in t2.indexes]
+ tmp.sort()
+ r1, r2 = [idx[1] for idx in tmp]
+
+ assert r1.name == 'idx2'
+ assert r1.unique == True
+ assert r2.unique == False
+ assert [t2.c.id] == r1.columns
+ assert [t2.c.name] == r2.columns
+ finally:
+ warnings.warn = capture_warnings._orig_showwarning
+ m1.drop_all()
+
def test_create_partial_index(self):
tbl = Table('testtbl', MetaData(), Column('data',Integer))
idx = Index('test_idx1', tbl.c.data, postgres_where=and_(tbl.c.data > 5, tbl.c.data < 10))