mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: remove shadow write of new sip 68 dataset models (#21986)
This commit is contained in:
committed by
GitHub
parent
824dc7188b
commit
86d52fcbc4
@@ -25,6 +25,7 @@ from zipfile import is_zipfile, ZipFile
|
||||
import prison
|
||||
import pytest
|
||||
import yaml
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
|
||||
@@ -95,6 +96,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
def get_fixture_datasets(self) -> List[SqlaTable]:
|
||||
return (
|
||||
db.session.query(SqlaTable)
|
||||
.options(joinedload(SqlaTable.database))
|
||||
.filter(SqlaTable.table_name.in_(self.fixture_tables_names))
|
||||
.all()
|
||||
)
|
||||
@@ -1973,21 +1975,17 @@ class TestDatasetApi(SupersetTestCase):
|
||||
database = (
|
||||
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
|
||||
)
|
||||
shadow_dataset = (
|
||||
db.session.query(Dataset).filter_by(uuid=dataset_config["uuid"]).one()
|
||||
)
|
||||
|
||||
assert database.database_name == "imported_database"
|
||||
|
||||
assert len(database.tables) == 1
|
||||
dataset = database.tables[0]
|
||||
assert dataset.table_name == "imported_dataset"
|
||||
assert str(dataset.uuid) == dataset_config["uuid"]
|
||||
assert str(shadow_dataset.uuid) == dataset_config["uuid"]
|
||||
|
||||
dataset.owners = []
|
||||
database.owners = []
|
||||
db.session.delete(dataset)
|
||||
db.session.delete(shadow_dataset)
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from superset.columns.models import Column
|
||||
from superset.connectors.sqla.models import SqlaTable, TableColumn
|
||||
from superset.extensions import db
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.fixtures.datasource import load_dataset_with_columns
|
||||
|
||||
|
||||
class SqlaTableModelTest(SupersetTestCase):
|
||||
@pytest.mark.usefixtures("load_dataset_with_columns")
|
||||
def test_dual_update_column(self) -> None:
|
||||
"""
|
||||
Test that when updating a sqla ``TableColumn``
|
||||
That the shadow ``Column`` is also updated
|
||||
"""
|
||||
dataset = db.session.query(SqlaTable).filter_by(table_name="students").first()
|
||||
column = dataset.columns[0]
|
||||
column_name = column.column_name
|
||||
column.column_name = "new_column_name"
|
||||
SqlaTable.update_column(None, None, target=column)
|
||||
|
||||
# refetch
|
||||
dataset = db.session.query(SqlaTable).filter_by(id=dataset.id).one()
|
||||
assert dataset.columns[0].column_name == "new_column_name"
|
||||
|
||||
# reset
|
||||
column.column_name = column_name
|
||||
SqlaTable.update_column(None, None, target=column)
|
||||
|
||||
@pytest.mark.usefixtures("load_dataset_with_columns")
|
||||
@mock.patch("superset.columns.models.Column")
|
||||
def test_dual_update_column_not_found(self, column_mock) -> None:
|
||||
"""
|
||||
Test that when updating a sqla ``TableColumn``
|
||||
That the shadow ``Column`` is also updated
|
||||
"""
|
||||
dataset = db.session.query(SqlaTable).filter_by(table_name="students").first()
|
||||
column = dataset.columns[0]
|
||||
column_uuid = column.uuid
|
||||
with mock.patch("sqlalchemy.orm.query.Query.one", side_effect=NoResultFound):
|
||||
SqlaTable.update_column(None, None, target=column)
|
||||
|
||||
session = inspect(column).session
|
||||
|
||||
session.flush()
|
||||
|
||||
# refetch
|
||||
dataset = db.session.query(SqlaTable).filter_by(id=dataset.id).one()
|
||||
# it should create a new uuid
|
||||
assert dataset.columns[0].uuid != column_uuid
|
||||
|
||||
# reset
|
||||
column.uuid = column_uuid
|
||||
SqlaTable.update_column(None, None, target=column)
|
||||
|
||||
@pytest.mark.usefixtures("load_dataset_with_columns")
|
||||
def test_to_sl_column_no_known_columns(self) -> None:
|
||||
"""
|
||||
Test that the function returns a new column
|
||||
"""
|
||||
dataset = db.session.query(SqlaTable).filter_by(table_name="students").first()
|
||||
column = dataset.columns[0]
|
||||
new_column = column.to_sl_column()
|
||||
|
||||
# it should use the same uuid
|
||||
assert column.uuid == new_column.uuid
|
||||
Reference in New Issue
Block a user