mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat: create function for get_sqla_engine with context (#21790)
This commit is contained in:
@@ -45,18 +45,17 @@ def create_test_table_context(database: Database):
|
||||
schema = get_example_default_schema()
|
||||
full_table_name = f"{schema}.test_table" if schema else "test_table"
|
||||
|
||||
database.get_sqla_engine().execute(
|
||||
f"CREATE TABLE IF NOT EXISTS {full_table_name} AS SELECT 1 as first, 2 as second"
|
||||
)
|
||||
database.get_sqla_engine().execute(
|
||||
f"INSERT INTO {full_table_name} (first, second) VALUES (1, 2)"
|
||||
)
|
||||
database.get_sqla_engine().execute(
|
||||
f"INSERT INTO {full_table_name} (first, second) VALUES (3, 4)"
|
||||
)
|
||||
with database.get_sqla_engine_with_context() as engine:
|
||||
engine.execute(
|
||||
f"CREATE TABLE IF NOT EXISTS {full_table_name} AS SELECT 1 as first, 2 as second"
|
||||
)
|
||||
engine.execute(f"INSERT INTO {full_table_name} (first, second) VALUES (1, 2)")
|
||||
engine.execute(f"INSERT INTO {full_table_name} (first, second) VALUES (3, 4)")
|
||||
|
||||
yield db.session
|
||||
database.get_sqla_engine().execute(f"DROP TABLE {full_table_name}")
|
||||
|
||||
with database.get_sqla_engine_with_context() as engine:
|
||||
engine.execute(f"DROP TABLE {full_table_name}")
|
||||
|
||||
|
||||
class TestDatasource(SupersetTestCase):
|
||||
|
||||
Reference in New Issue
Block a user