mirror of
https://github.com/apache/superset.git
synced 2026-04-23 18:14:56 +00:00
perf: refactor SIP-68 db migrations with INSERT SELECT FROM (#19421)
This commit is contained in:
@@ -16,11 +16,11 @@
|
||||
# under the License.
|
||||
import copy
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
import yaml
|
||||
from flask import g
|
||||
|
||||
from superset import db, security_manager
|
||||
from superset import db
|
||||
from superset.commands.exceptions import CommandInvalidError
|
||||
from superset.commands.importers.v1.assets import ImportAssetsCommand
|
||||
from superset.commands.importers.v1.utils import is_valid_config
|
||||
@@ -58,10 +58,13 @@ class TestImportersV1Utils(SupersetTestCase):
|
||||
|
||||
|
||||
class TestImportAssetsCommand(SupersetTestCase):
|
||||
@patch("superset.dashboards.commands.importers.v1.utils.g")
|
||||
def test_import_assets(self, mock_g):
|
||||
def setUp(self):
|
||||
user = self.get_user("admin")
|
||||
self.user = user
|
||||
setattr(g, "user", user)
|
||||
|
||||
def test_import_assets(self):
|
||||
"""Test that we can import multiple assets"""
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
contents = {
|
||||
"metadata.yaml": yaml.safe_dump(metadata_config),
|
||||
"databases/imported_database.yaml": yaml.safe_dump(database_config),
|
||||
@@ -141,7 +144,7 @@ class TestImportAssetsCommand(SupersetTestCase):
|
||||
database = dataset.database
|
||||
assert str(database.uuid) == database_config["uuid"]
|
||||
|
||||
assert dashboard.owners == [mock_g.user]
|
||||
assert dashboard.owners == [self.user]
|
||||
|
||||
dashboard.owners = []
|
||||
chart.owners = []
|
||||
@@ -153,11 +156,8 @@ class TestImportAssetsCommand(SupersetTestCase):
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
@patch("superset.dashboards.commands.importers.v1.utils.g")
|
||||
def test_import_v1_dashboard_overwrite(self, mock_g):
|
||||
def test_import_v1_dashboard_overwrite(self):
|
||||
"""Test that assets can be overwritten"""
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
|
||||
contents = {
|
||||
"metadata.yaml": yaml.safe_dump(metadata_config),
|
||||
"databases/imported_database.yaml": yaml.safe_dump(database_config),
|
||||
|
||||
@@ -111,11 +111,10 @@ def _commit_slices(slices: List[Slice]):
|
||||
|
||||
|
||||
def _create_world_bank_dashboard(table: SqlaTable, slices: List[Slice]) -> Dashboard:
|
||||
from superset.examples.helpers import update_slice_ids
|
||||
from superset.examples.world_bank import dashboard_positions
|
||||
|
||||
pos = dashboard_positions
|
||||
from superset.examples.helpers import update_slice_ids
|
||||
|
||||
update_slice_ids(pos, slices)
|
||||
|
||||
table.fetch_metadata()
|
||||
|
||||
@@ -455,7 +455,8 @@ class TestDatabaseModel(SupersetTestCase):
|
||||
|
||||
# make sure the columns have been mapped properly
|
||||
assert len(table.columns) == 4
|
||||
table.fetch_metadata()
|
||||
table.fetch_metadata(commit=False)
|
||||
|
||||
# assert that the removed column has been dropped and
|
||||
# the physical and calculated columns are present
|
||||
assert {col.column_name for col in table.columns} == {
|
||||
@@ -473,6 +474,8 @@ class TestDatabaseModel(SupersetTestCase):
|
||||
assert VIRTUAL_TABLE_STRING_TYPES[backend].match(cols["mycase"].type)
|
||||
assert cols["expr"].expression == "case when 1 then 1 else 0 end"
|
||||
|
||||
db.session.delete(table)
|
||||
|
||||
@patch("superset.models.core.Database.db_engine_spec", BigQueryEngineSpec)
|
||||
def test_labels_expected_on_mutated_query(self):
|
||||
query_obj = {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# isort:skip_file
|
||||
import unittest
|
||||
import uuid
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
Reference in New Issue
Block a user