def get_table_oid(self, table_name, schema=None):
"""Return the OID for the given table name."""
- return self.dialect.get_table_oid(
- self.bind, table_name, schema, info_cache=self.info_cache
- )
+ with self._operation_context() as conn:
+ return self.dialect.get_table_oid(
+ conn, table_name, schema, info_cache=self.info_cache
+ )
def get_enums(self, schema=None):
"""Return a list of ENUM objects.
"""
schema = schema or self.default_schema_name
- return self.dialect._load_enums(self.bind, schema)
+ with self._operation_context() as conn:
+ return self.dialect._load_enums(conn, schema)
def get_foreign_table_names(self, schema=None):
"""Return a list of FOREIGN TABLE names.
"""
schema = schema or self.default_schema_name
- return self.dialect._get_foreign_table_names(self.bind, schema)
+ with self._operation_context() as conn:
+ return self.dialect._get_foreign_table_names(conn, schema)
def get_view_names(self, schema=None, include=("plain", "materialized")):
"""Return all view names in `schema`.
"""
- return self.dialect.get_view_names(
- self.bind, schema, info_cache=self.info_cache, include=include
- )
+ with self._operation_context() as conn:
+ return self.dialect.get_view_names(
+ conn, schema, info_cache=self.info_cache, include=include
+ )
class CreateEnumType(schema._CreateDropBase):
"JOIN pg_namespace n ON n.oid = c.relnamespace "
"WHERE n.nspname = :schema AND c.relkind = 'f'"
).columns(relname=sqltypes.Unicode),
- schema=schema if schema is not None else self.default_schema_name,
+ dict(
+ schema=schema
+ if schema is not None
+ else self.default_schema_name
+ ),
)
return [name for name, in result]
from sqlalchemy.testing.assertions import is_true
-class ForeignTableReflectionTest(fixtures.TablesTest, AssertsExecutionResults):
+class ReflectionFixtures(object):
+ @testing.fixture(
+ params=[
+ ("engine", True),
+ ("connection", True),
+ ("engine", False),
+ ("connection", False),
+ ]
+ )
+ def inspect_fixture(self, request, metadata, testing_engine):
+ engine, future = request.param
+
+ eng = testing_engine(future=future)
+
+ conn = eng.connect()
+
+ if engine == "connection":
+ yield inspect(eng), conn
+ else:
+ yield inspect(conn), conn
+
+ conn.close()
+
+
+class ForeignTableReflectionTest(
+ ReflectionFixtures, fixtures.TablesTest, AssertsExecutionResults
+):
"""Test reflection on foreign tables"""
__requires__ = ("postgresql_test_dblink",)
"Columns of reflected foreign table didn't equal expected columns",
)
- def test_get_foreign_table_names(self, connection):
- inspector = inspect(connection)
+ def test_get_foreign_table_names(self, inspect_fixture):
+ inspector, conn = inspect_fixture
+
ft_names = inspector.get_foreign_table_names()
eq_(ft_names, ["test_foreigntable"])
class MaterializedViewReflectionTest(
- fixtures.TablesTest, AssertsExecutionResults
+ ReflectionFixtures, fixtures.TablesTest, AssertsExecutionResults
):
"""Test reflection on materialized views"""
table = Table("test_mview", metadata, autoload_with=connection)
eq_(connection.execute(table.select()).fetchall(), [(89, "d1")])
- def test_get_view_names(self, connection):
- insp = inspect(connection)
+ def test_get_view_names(self, inspect_fixture):
+ insp, conn = inspect_fixture
eq_(set(insp.get_view_names()), set(["test_regview", "test_mview"]))
def test_get_view_names_plain(self, connection):
base.PGDialect.ischema_names = ischema_names
-class ReflectionTest(AssertsCompiledSQL, fixtures.TestBase):
+class ReflectionTest(
+ ReflectionFixtures, AssertsCompiledSQL, fixtures.TestBase
+):
__only_on__ = "postgresql"
__backend__ = True
],
)
- def test_inspect_enums(self, metadata, connection):
+ def test_inspect_enums(self, metadata, inspect_fixture):
+
+ inspector, conn = inspect_fixture
+
enum_type = postgresql.ENUM(
"cat", "dog", "rat", name="pet", metadata=metadata
)
- enum_type.create(connection)
- inspector = inspect(connection)
+
+ with conn.begin():
+ enum_type.create(conn)
+
eq_(
inspector.get_enums(),
[
],
)
+ def test_get_table_oid(self, metadata, inspect_fixture):
+
+ inspector, conn = inspect_fixture
+
+ with conn.begin():
+ Table("some_table", metadata, Column("q", Integer)).create(conn)
+
+ assert inspector.get_table_oid("some_table") is not None
+
def test_inspect_enums_case_sensitive(self, metadata, connection):
sa.event.listen(
metadata,