diff options
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index e088cad01..263684e12 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -25,7 +25,9 @@ from sqlalchemy.dialects.postgresql import ExcludeConstraint from sqlalchemy.dialects.postgresql import INTEGER from sqlalchemy.dialects.postgresql import INTERVAL from sqlalchemy.dialects.postgresql import TSRANGE +from sqlalchemy.schema import CreateIndex from sqlalchemy.sql.schema import CheckConstraint +from sqlalchemy.testing import AssertsCompiledSQL from sqlalchemy.testing import fixtures from sqlalchemy.testing import mock from sqlalchemy.testing.assertions import assert_raises @@ -437,7 +439,7 @@ class DomainReflectionTest(fixtures.TestBase, AssertsExecutionResults): base.PGDialect.ischema_names = ischema_names -class ReflectionTest(fixtures.TestBase): +class ReflectionTest(AssertsCompiledSQL, fixtures.TestBase): __only_on__ = "postgresql" __backend__ = True @@ -587,7 +589,7 @@ class ReflectionTest(fixtures.TestBase): addresses = Table( "email_addresses", meta2, autoload=True, schema="test_schema" ) - users = Table("users", meta2, mustexist=True, schema="test_schema") + users = Table("users", meta2, must_exist=True, schema="test_schema") j = join(users, addresses) self.assert_( (users.c.user_id == addresses.c.remote_user_id).compare(j.onclause) @@ -898,7 +900,7 @@ class ReflectionTest(fixtures.TestBase): @testing.provide_metadata def test_index_reflection(self): - """ Reflecting partial & expression-based indexes should warn + """ Reflecting expression-based indexes should warn """ metadata = self.metadata @@ -944,12 +946,53 @@ class ReflectionTest(fixtures.TestBase): [ "Skipped unsupported reflection of " "expression-based index idx1", - "Predicate of partial index idx2 ignored during " "reflection", "Skipped unsupported reflection of " "expression-based index idx3", ], ) + @testing.provide_metadata + def test_index_reflection_partial(self, connection): + """Reflect the filter defintion on partial indexes + """ + + metadata = self.metadata + + t1 = Table( + "table1", + metadata, + Column("id", Integer, primary_key=True), + Column("name", String(20)), + Column("x", Integer), + ) + Index("idx1", t1.c.id, postgresql_where=t1.c.name == "test") + Index("idx2", t1.c.id, postgresql_where=t1.c.x >= 5) + + metadata.create_all(connection) + + ind = testing.db.dialect.get_indexes(connection, t1, None) + + partial_definitions = [] + for ix in ind: + if "dialect_options" in ix: + partial_definitions.append( + ix["dialect_options"]["postgresql_where"] + ) + + eq_( + sorted(partial_definitions), + ["((name)::text = 'test'::text)", "(x >= 5)"], + ) + + t2 = Table("table1", MetaData(), autoload_with=connection) + idx = list(sorted(t2.indexes, key=lambda idx: idx.name))[0] + + self.assert_compile( + CreateIndex(idx), + "CREATE INDEX idx1 ON table1 (id) " + "WHERE ((name)::text = 'test'::text)", + ) + @testing.fails_if("postgresql < 8.3", "index ordering not supported") @testing.provide_metadata def test_index_reflection_with_sorting(self): |