summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-10-23 10:34:33 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-10-23 10:35:31 -0400
commitc02f6b744d304578fe67da2e13d2c02ab71140d2 (patch)
treee052160b2dd7f0ef836649648479eb22b8b47511 /lib/sqlalchemy
parentbbf68345f4993245689b96cc6c6a50013afa3caa (diff)
downloadsqlalchemy-c02f6b744d304578fe67da2e13d2c02ab71140d2.tar.gz
test support for has_table()->view; backport to 1.4
For 1.4 only; in 2.0 this just refines the test suite a bit. Fixed regression which occurred throughout the 1.4 series where the :meth:`.Inspector.has_table` method, which historically reported on views as well, stopped working for SQL Server. The issue is not present in the 2.0 series which uses a different reflection architecture. Test support is added to ensure ``has_table()`` remains working per spec re: views. Fixes: #8700 Change-Id: I119a91ec07911edb08cf0799234827fec9ea1195
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py
index 7e54ee57a..dd7d38c5a 100644
--- a/lib/sqlalchemy/testing/suite/test_reflection.py
+++ b/lib/sqlalchemy/testing/suite/test_reflection.py
@@ -65,6 +65,28 @@ class HasTableTest(fixtures.TablesTest):
schema=config.test_schema,
)
+ if testing.requires.view_reflection:
+ cls.define_views(metadata)
+
+ @classmethod
+ def define_views(cls, metadata):
+ query = "CREATE VIEW vv AS SELECT * FROM test_table"
+
+ event.listen(metadata, "after_create", DDL(query))
+ event.listen(metadata, "before_drop", DDL("DROP VIEW vv"))
+
+ if testing.requires.schemas.enabled:
+ query = "CREATE VIEW %s.vv AS SELECT * FROM %s.test_table_s" % (
+ config.test_schema,
+ config.test_schema,
+ )
+ event.listen(metadata, "after_create", DDL(query))
+ event.listen(
+ metadata,
+ "before_drop",
+ DDL("DROP VIEW %s.vv" % (config.test_schema)),
+ )
+
def test_has_table(self):
with config.db.begin() as conn:
is_true(config.db.dialect.has_table(conn, "test_table"))
@@ -105,29 +127,14 @@ class HasTableTest(fixtures.TablesTest):
@testing.requires.views
def test_has_table_view(self, connection):
- query = "CREATE VIEW vv AS SELECT * FROM test_table"
- connection.execute(sa.sql.text(query))
insp = inspect(connection)
- try:
- is_true(insp.has_table("vv"))
- finally:
- connection.execute(sa.sql.text("DROP VIEW vv"))
+ is_true(insp.has_table("vv"))
@testing.requires.views
@testing.requires.schemas
def test_has_table_view_schema(self, connection):
- query = "CREATE VIEW %s.vv AS SELECT * FROM %s.test_table_s" % (
- config.test_schema,
- config.test_schema,
- )
- connection.execute(sa.sql.text(query))
insp = inspect(connection)
- try:
- is_true(insp.has_table("vv", config.test_schema))
- finally:
- connection.execute(
- sa.sql.text("DROP VIEW %s.vv" % config.test_schema)
- )
+ is_true(insp.has_table("vv", config.test_schema))
class HasIndexTest(fixtures.TablesTest):