mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore(dao): Organize DAOs according to SIP-92 (#24331)
Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
This commit is contained in:
@@ -23,7 +23,7 @@ import pytest
|
||||
|
||||
import tests.integration_tests.test_app # pylint: disable=unused-import
|
||||
from superset import db, security_manager
|
||||
from superset.dashboards.dao import DashboardDAO
|
||||
from superset.daos.dashboard import DashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
@@ -129,7 +129,7 @@ class TestDashboardDAO(SupersetTestCase):
|
||||
db.session.commit()
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@patch("superset.dashboards.dao.g")
|
||||
@patch("superset.daos.dashboard.g")
|
||||
def test_copy_dashboard(self, mock_g):
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
original_dash = (
|
||||
@@ -155,7 +155,7 @@ class TestDashboardDAO(SupersetTestCase):
|
||||
db.session.commit()
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@patch("superset.dashboards.dao.g")
|
||||
@patch("superset.daos.dashboard.g")
|
||||
def test_copy_dashboard_copies_native_filters(self, mock_g):
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
original_dash = (
|
||||
@@ -183,7 +183,7 @@ class TestDashboardDAO(SupersetTestCase):
|
||||
db.session.commit()
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
@patch("superset.dashboards.dao.g")
|
||||
@patch("superset.daos.dashboard.g")
|
||||
def test_copy_dashboard_duplicate_slices(self, mock_g):
|
||||
mock_g.user = security_manager.find_user("admin")
|
||||
original_dash = (
|
||||
|
||||
@@ -22,7 +22,7 @@ import pytest
|
||||
from flask import escape
|
||||
|
||||
from superset import app
|
||||
from superset.dashboards.dao import DashboardDAO
|
||||
from superset.daos.dashboard import DashboardDAO
|
||||
from superset.models import core as models
|
||||
from tests.integration_tests.dashboards.base_case import DashboardTestCase
|
||||
from tests.integration_tests.dashboards.consts import *
|
||||
|
||||
@@ -859,7 +859,7 @@ class TestImportDatabasesCommand(SupersetTestCase):
|
||||
|
||||
|
||||
class TestTestConnectionDatabaseCommand(SupersetTestCase):
|
||||
@patch("superset.databases.dao.Database._get_sqla_engine")
|
||||
@patch("superset.daos.database.Database._get_sqla_engine")
|
||||
@patch("superset.databases.commands.test_connection.event_logger.log_with_context")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_connection_db_exception(
|
||||
@@ -880,7 +880,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase):
|
||||
)
|
||||
mock_event_logger.assert_called()
|
||||
|
||||
@patch("superset.databases.dao.Database._get_sqla_engine")
|
||||
@patch("superset.daos.database.Database._get_sqla_engine")
|
||||
@patch("superset.databases.commands.test_connection.event_logger.log_with_context")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_connection_do_ping_exception(
|
||||
@@ -925,7 +925,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase):
|
||||
== SupersetErrorType.CONNECTION_DATABASE_TIMEOUT
|
||||
)
|
||||
|
||||
@patch("superset.databases.dao.Database._get_sqla_engine")
|
||||
@patch("superset.daos.database.Database._get_sqla_engine")
|
||||
@patch("superset.databases.commands.test_connection.event_logger.log_with_context")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_connection_superset_security_connection(
|
||||
@@ -948,7 +948,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase):
|
||||
|
||||
mock_event_logger.assert_called()
|
||||
|
||||
@patch("superset.databases.dao.Database._get_sqla_engine")
|
||||
@patch("superset.daos.database.Database._get_sqla_engine")
|
||||
@patch("superset.databases.commands.test_connection.event_logger.log_with_context")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_connection_db_api_exc(
|
||||
@@ -1093,7 +1093,7 @@ def test_validate_partial_invalid_hostname(is_hostname_valid, app_context):
|
||||
|
||||
|
||||
class TestTablesDatabaseCommand(SupersetTestCase):
|
||||
@patch("superset.databases.dao.DatabaseDAO.find_by_id")
|
||||
@patch("superset.daos.database.DatabaseDAO.find_by_id")
|
||||
def test_database_tables_list_with_unknown_database(self, mock_find_by_id):
|
||||
mock_find_by_id.return_value = None
|
||||
command = TablesDatabaseCommand(1, "test", False)
|
||||
@@ -1102,7 +1102,7 @@ class TestTablesDatabaseCommand(SupersetTestCase):
|
||||
command.run()
|
||||
assert str(excinfo.value) == ("Database not found.")
|
||||
|
||||
@patch("superset.databases.dao.DatabaseDAO.find_by_id")
|
||||
@patch("superset.daos.database.DatabaseDAO.find_by_id")
|
||||
@patch("superset.security.manager.SupersetSecurityManager.can_access_database")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_database_tables_superset_exception(
|
||||
@@ -1121,7 +1121,7 @@ class TestTablesDatabaseCommand(SupersetTestCase):
|
||||
command.run()
|
||||
assert str(excinfo.value) == "Test Error"
|
||||
|
||||
@patch("superset.databases.dao.DatabaseDAO.find_by_id")
|
||||
@patch("superset.daos.database.DatabaseDAO.find_by_id")
|
||||
@patch("superset.security.manager.SupersetSecurityManager.can_access_database")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_database_tables_exception(
|
||||
@@ -1140,7 +1140,7 @@ class TestTablesDatabaseCommand(SupersetTestCase):
|
||||
== "Unexpected error occurred, please check your logs for details"
|
||||
)
|
||||
|
||||
@patch("superset.databases.dao.DatabaseDAO.find_by_id")
|
||||
@patch("superset.daos.database.DatabaseDAO.find_by_id")
|
||||
@patch("superset.security.manager.SupersetSecurityManager.can_access_database")
|
||||
@patch("superset.utils.core.g")
|
||||
def test_database_tables_list_tables(
|
||||
|
||||
@@ -30,7 +30,7 @@ from sqlalchemy.sql import func
|
||||
|
||||
from superset import app
|
||||
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
|
||||
from superset.dao.exceptions import (
|
||||
from superset.daos.exceptions import (
|
||||
DAOCreateFailedError,
|
||||
DAODeleteFailedError,
|
||||
DAOUpdateFailedError,
|
||||
@@ -827,7 +827,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
rv = self.client.delete(uri)
|
||||
assert rv.status_code == 200
|
||||
|
||||
@patch("superset.datasets.dao.DatasetDAO.create")
|
||||
@patch("superset.daos.dataset.DatasetDAO.create")
|
||||
def test_create_dataset_sqlalchemy_error(self, mock_dao_create):
|
||||
"""
|
||||
Dataset API: Test create dataset sqlalchemy error
|
||||
@@ -1440,7 +1440,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
db.session.delete(dataset)
|
||||
db.session.commit()
|
||||
|
||||
@patch("superset.datasets.dao.DatasetDAO.update")
|
||||
@patch("superset.daos.dataset.DatasetDAO.update")
|
||||
def test_update_dataset_sqlalchemy_error(self, mock_dao_update):
|
||||
"""
|
||||
Dataset API: Test update dataset sqlalchemy error
|
||||
@@ -1512,7 +1512,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
db.session.delete(dataset)
|
||||
db.session.commit()
|
||||
|
||||
@patch("superset.datasets.dao.DatasetDAO.delete")
|
||||
@patch("superset.daos.dataset.DatasetDAO.delete")
|
||||
def test_delete_dataset_sqlalchemy_error(self, mock_dao_delete):
|
||||
"""
|
||||
Dataset API: Test delete dataset sqlalchemy error
|
||||
@@ -1589,7 +1589,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
assert rv.status_code == 403
|
||||
|
||||
@pytest.mark.usefixtures("create_datasets")
|
||||
@patch("superset.datasets.dao.DatasetDAO.delete")
|
||||
@patch("superset.daos.dataset.DatasetDAO.delete")
|
||||
def test_delete_dataset_column_fail(self, mock_dao_delete):
|
||||
"""
|
||||
Dataset API: Test delete dataset column
|
||||
@@ -1669,7 +1669,7 @@ class TestDatasetApi(SupersetTestCase):
|
||||
assert rv.status_code == 403
|
||||
|
||||
@pytest.mark.usefixtures("create_datasets")
|
||||
@patch("superset.datasets.dao.DatasetDAO.delete")
|
||||
@patch("superset.daos.dataset.DatasetDAO.delete")
|
||||
def test_delete_dataset_metric_fail(self, mock_dao_delete):
|
||||
"""
|
||||
Dataset API: Test delete dataset metric
|
||||
|
||||
@@ -21,7 +21,7 @@ import pytest
|
||||
|
||||
from superset import db, security_manager
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
from superset.dao.exceptions import DatasourceTypeNotSupportedError
|
||||
from superset.daos.exceptions import DatasourceTypeNotSupportedError
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ from superset import app, db
|
||||
from superset.common.utils.query_cache_manager import QueryCacheManager
|
||||
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
|
||||
from superset.constants import CacheRegion
|
||||
from superset.dao.exceptions import DatasourceNotFound, DatasourceTypeNotSupportedError
|
||||
from superset.daos.exceptions import DatasourceNotFound, DatasourceTypeNotSupportedError
|
||||
from superset.datasets.commands.exceptions import DatasetNotFoundError
|
||||
from superset.exceptions import SupersetGenericDBErrorException
|
||||
from superset.models.core import Database
|
||||
@@ -433,7 +433,7 @@ class TestDatasource(SupersetTestCase):
|
||||
app.config["DATASET_HEALTH_CHECK"] = None
|
||||
|
||||
def test_get_datasource_failed(self):
|
||||
from superset.datasource.dao import DatasourceDAO
|
||||
from superset.daos.datasource import DatasourceDAO
|
||||
|
||||
pytest.raises(
|
||||
DatasourceNotFound,
|
||||
@@ -445,7 +445,7 @@ class TestDatasource(SupersetTestCase):
|
||||
self.assertEqual(resp.get("error"), "Datasource does not exist")
|
||||
|
||||
def test_get_datasource_invalid_datasource_failed(self):
|
||||
from superset.datasource.dao import DatasourceDAO
|
||||
from superset.daos.datasource import DatasourceDAO
|
||||
|
||||
pytest.raises(
|
||||
DatasourceTypeNotSupportedError,
|
||||
|
||||
@@ -21,7 +21,7 @@ from unittest import mock
|
||||
import pytest
|
||||
|
||||
from superset import db
|
||||
from superset.embedded.dao import EmbeddedDAO
|
||||
from superset.daos.dashboard import EmbeddedDashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.fixtures.birth_names_dashboard import (
|
||||
@@ -41,7 +41,7 @@ class TestEmbeddedDashboardApi(SupersetTestCase):
|
||||
def test_get_embedded_dashboard(self):
|
||||
self.login("admin")
|
||||
self.dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
self.embedded = EmbeddedDAO.upsert(self.dash, [])
|
||||
self.embedded = EmbeddedDashboardDAO.upsert(self.dash, [])
|
||||
uri = f"api/v1/{self.resource_name}/{self.embedded.uuid}"
|
||||
response = self.client.get(uri)
|
||||
self.assert200(response)
|
||||
|
||||
@@ -19,7 +19,7 @@ import pytest
|
||||
|
||||
import tests.integration_tests.test_app # pylint: disable=unused-import
|
||||
from superset import db
|
||||
from superset.embedded.dao import EmbeddedDAO
|
||||
from superset.daos.dashboard import EmbeddedDashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
@@ -28,24 +28,24 @@ from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
)
|
||||
|
||||
|
||||
class TestEmbeddedDAO(SupersetTestCase):
|
||||
class TestEmbeddedDashboardDAO(SupersetTestCase):
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_upsert(self):
|
||||
dash = db.session.query(Dashboard).filter_by(slug="world_health").first()
|
||||
assert not dash.embedded
|
||||
EmbeddedDAO.upsert(dash, ["test.example.com"])
|
||||
EmbeddedDashboardDAO.upsert(dash, ["test.example.com"])
|
||||
assert dash.embedded
|
||||
self.assertEqual(dash.embedded[0].allowed_domains, ["test.example.com"])
|
||||
original_uuid = dash.embedded[0].uuid
|
||||
self.assertIsNotNone(original_uuid)
|
||||
EmbeddedDAO.upsert(dash, [])
|
||||
EmbeddedDashboardDAO.upsert(dash, [])
|
||||
self.assertEqual(dash.embedded[0].allowed_domains, [])
|
||||
self.assertEqual(dash.embedded[0].uuid, original_uuid)
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_get_by_uuid(self):
|
||||
dash = db.session.query(Dashboard).filter_by(slug="world_health").first()
|
||||
uuid = str(EmbeddedDAO.upsert(dash, ["test.example.com"]).uuid)
|
||||
uuid = str(EmbeddedDashboardDAO.upsert(dash, ["test.example.com"]).uuid)
|
||||
db.session.expire_all()
|
||||
embedded = EmbeddedDAO.find_by_id(uuid)
|
||||
embedded = EmbeddedDashboardDAO.find_by_id(uuid)
|
||||
self.assertIsNotNone(embedded)
|
||||
|
||||
@@ -22,7 +22,7 @@ from unittest import mock
|
||||
import pytest
|
||||
|
||||
from superset import db
|
||||
from superset.embedded.dao import EmbeddedDAO
|
||||
from superset.daos.dashboard import EmbeddedDashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from tests.integration_tests.fixtures.birth_names_dashboard import (
|
||||
load_birth_names_dashboard_with_slices,
|
||||
@@ -43,7 +43,7 @@ if TYPE_CHECKING:
|
||||
)
|
||||
def test_get_embedded_dashboard(client: FlaskClient[Any]):
|
||||
dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
embedded = EmbeddedDAO.upsert(dash, [])
|
||||
embedded = EmbeddedDashboardDAO.upsert(dash, [])
|
||||
uri = f"embedded/{embedded.uuid}"
|
||||
response = client.get(uri)
|
||||
assert response.status_code == 200
|
||||
@@ -56,7 +56,7 @@ def test_get_embedded_dashboard(client: FlaskClient[Any]):
|
||||
)
|
||||
def test_get_embedded_dashboard_referrer_not_allowed(client: FlaskClient[Any]):
|
||||
dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
embedded = EmbeddedDAO.upsert(dash, ["test.example.com"])
|
||||
embedded = EmbeddedDashboardDAO.upsert(dash, ["test.example.com"])
|
||||
uri = f"embedded/{embedded.uuid}"
|
||||
response = client.get(uri)
|
||||
assert response.status_code == 403
|
||||
|
||||
@@ -216,7 +216,7 @@ def test_get_dataset_access_denied(
|
||||
assert data["message"] == message
|
||||
|
||||
|
||||
@patch("superset.datasource.dao.DatasourceDAO.get_datasource")
|
||||
@patch("superset.daos.datasource.DatasourceDAO.get_datasource")
|
||||
def test_wrong_endpoint(mock_get_datasource, test_client, login_as_admin, dataset):
|
||||
dataset.default_endpoint = "another_endpoint"
|
||||
mock_get_datasource.return_value = dataset
|
||||
|
||||
@@ -30,7 +30,7 @@ from superset.common.query_context import QueryContext
|
||||
from superset.common.query_context_factory import QueryContextFactory
|
||||
from superset.common.query_object import QueryObject
|
||||
from superset.connectors.sqla.models import SqlMetric
|
||||
from superset.datasource.dao import DatasourceDAO
|
||||
from superset.daos.datasource import DatasourceDAO
|
||||
from superset.extensions import cache_manager
|
||||
from superset.superset_typing import AdhocColumn
|
||||
from superset.utils.core import (
|
||||
|
||||
@@ -1955,7 +1955,7 @@ def test_grace_period_error_flap(
|
||||
@pytest.mark.usefixtures(
|
||||
"load_birth_names_dashboard_with_slices", "create_report_email_dashboard"
|
||||
)
|
||||
@patch("superset.reports.dao.ReportScheduleDAO.bulk_delete_logs")
|
||||
@patch("superset.daos.report.ReportScheduleDAO.bulk_delete_logs")
|
||||
def test_prune_log_soft_time_out(bulk_delete_logs, create_report_email_dashboard):
|
||||
from celery.exceptions import SoftTimeLimitExceeded
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import pytest
|
||||
|
||||
from flask_wtf.csrf import generate_csrf
|
||||
from superset import db
|
||||
from superset.embedded.dao import EmbeddedDAO
|
||||
from superset.daos.dashboard import EmbeddedDashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.utils.urls import get_url_host
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
@@ -89,7 +89,7 @@ class TestSecurityGuestTokenApi(SupersetTestCase):
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_post_guest_token_authorized(self):
|
||||
self.dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
self.embedded = EmbeddedDAO.upsert(self.dash, [])
|
||||
self.embedded = EmbeddedDashboardDAO.upsert(self.dash, [])
|
||||
self.login(username="admin")
|
||||
user = {"username": "bob", "first_name": "Bob", "last_name": "Also Bob"}
|
||||
resource = {"type": "dashboard", "id": str(self.embedded.uuid)}
|
||||
|
||||
@@ -21,8 +21,8 @@ import pytest
|
||||
from flask import g
|
||||
|
||||
from superset import db, security_manager
|
||||
from superset.daos.dashboard import EmbeddedDashboardDAO
|
||||
from superset.dashboards.commands.exceptions import DashboardAccessDeniedError
|
||||
from superset.embedded.dao import EmbeddedDAO
|
||||
from superset.exceptions import SupersetSecurityException
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.security.guest_token import GuestTokenResourceType
|
||||
@@ -100,7 +100,7 @@ class TestGuestUserSecurity(SupersetTestCase):
|
||||
class TestGuestUserDashboardAccess(SupersetTestCase):
|
||||
def setUp(self) -> None:
|
||||
self.dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
self.embedded = EmbeddedDAO.upsert(self.dash, [])
|
||||
self.embedded = EmbeddedDashboardDAO.upsert(self.dash, [])
|
||||
self.authorized_guest = security_manager.get_guest_user_from_token(
|
||||
{
|
||||
"user": {},
|
||||
|
||||
@@ -29,7 +29,7 @@ import pytest
|
||||
|
||||
from flask import current_app
|
||||
from flask_appbuilder.security.sqla.models import Role
|
||||
from superset.datasource.dao import DatasourceDAO
|
||||
from superset.daos.datasource import DatasourceDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset import app, appbuilder, db, security_manager, viz
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
from operator import and_
|
||||
from unittest.mock import patch
|
||||
import pytest
|
||||
from superset.dao.exceptions import DAOCreateFailedError, DAOException
|
||||
from superset.daos.exceptions import DAOCreateFailedError, DAOException
|
||||
from superset.models.slice import Slice
|
||||
from superset.models.sql_lab import SavedQuery
|
||||
from superset.tags.dao import TagDAO
|
||||
from superset.daos.tag import TagDAO
|
||||
from superset.tags.exceptions import InvalidTagNameError
|
||||
from superset.tags.models import ObjectTypes, Tag, TaggedObject
|
||||
from tests.integration_tests.tags.api_tests import TAGS_FIXTURE_COUNT
|
||||
|
||||
import tests.integration_tests.test_app # pylint: disable=unused-import
|
||||
from superset import db, security_manager
|
||||
from superset.dashboards.dao import DashboardDAO
|
||||
from superset.daos.dashboard import DashboardDAO
|
||||
from superset.models.dashboard import Dashboard
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
from tests.integration_tests.fixtures.world_bank_dashboard import (
|
||||
|
||||
Reference in New Issue
Block a user