diff --git a/superset/annotation_layers/annotations/api.py b/superset/annotation_layers/annotations/api.py index 4c95b3c10..0be6efbfa 100644 --- a/superset/annotation_layers/annotations/api.py +++ b/superset/annotation_layers/annotations/api.py @@ -24,22 +24,6 @@ from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_babel import ngettext from marshmallow import ValidationError -from superset.annotation_layers.annotations.commands.create import ( - CreateAnnotationCommand, -) -from superset.annotation_layers.annotations.commands.delete import ( - DeleteAnnotationCommand, -) -from superset.annotation_layers.annotations.commands.exceptions import ( - AnnotationCreateFailedError, - AnnotationDeleteFailedError, - AnnotationInvalidError, - AnnotationNotFoundError, - AnnotationUpdateFailedError, -) -from superset.annotation_layers.annotations.commands.update import ( - UpdateAnnotationCommand, -) from superset.annotation_layers.annotations.filters import AnnotationAllTextFilter from superset.annotation_layers.annotations.schemas import ( AnnotationPostSchema, @@ -47,7 +31,17 @@ from superset.annotation_layers.annotations.schemas import ( get_delete_ids_schema, openapi_spec_methods_override, ) -from superset.annotation_layers.commands.exceptions import AnnotationLayerNotFoundError +from superset.commands.annotation_layer.annotation.create import CreateAnnotationCommand +from superset.commands.annotation_layer.annotation.delete import DeleteAnnotationCommand +from superset.commands.annotation_layer.annotation.exceptions import ( + AnnotationCreateFailedError, + AnnotationDeleteFailedError, + AnnotationInvalidError, + AnnotationNotFoundError, + AnnotationUpdateFailedError, +) +from superset.commands.annotation_layer.annotation.update import UpdateAnnotationCommand +from superset.commands.annotation_layer.exceptions import AnnotationLayerNotFoundError from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.models.annotations import Annotation from superset.views.base_api import ( diff --git a/superset/annotation_layers/api.py b/superset/annotation_layers/api.py index b7a3b301b..886c151a6 100644 --- a/superset/annotation_layers/api.py +++ b/superset/annotation_layers/api.py @@ -23,17 +23,6 @@ from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_babel import ngettext from marshmallow import ValidationError -from superset.annotation_layers.commands.create import CreateAnnotationLayerCommand -from superset.annotation_layers.commands.delete import DeleteAnnotationLayerCommand -from superset.annotation_layers.commands.exceptions import ( - AnnotationLayerCreateFailedError, - AnnotationLayerDeleteFailedError, - AnnotationLayerDeleteIntegrityError, - AnnotationLayerInvalidError, - AnnotationLayerNotFoundError, - AnnotationLayerUpdateFailedError, -) -from superset.annotation_layers.commands.update import UpdateAnnotationLayerCommand from superset.annotation_layers.filters import AnnotationLayerAllTextFilter from superset.annotation_layers.schemas import ( AnnotationLayerPostSchema, @@ -41,6 +30,17 @@ from superset.annotation_layers.schemas import ( get_delete_ids_schema, openapi_spec_methods_override, ) +from superset.commands.annotation_layer.create import CreateAnnotationLayerCommand +from superset.commands.annotation_layer.delete import DeleteAnnotationLayerCommand +from superset.commands.annotation_layer.exceptions import ( + AnnotationLayerCreateFailedError, + AnnotationLayerDeleteFailedError, + AnnotationLayerDeleteIntegrityError, + AnnotationLayerInvalidError, + AnnotationLayerNotFoundError, + AnnotationLayerUpdateFailedError, +) +from superset.commands.annotation_layer.update import UpdateAnnotationLayerCommand from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.extensions import event_logger from superset.models.annotations import AnnotationLayer diff --git a/superset/charts/api.py b/superset/charts/api.py index 768d33029..ea705f0aa 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -32,21 +32,6 @@ from werkzeug.wrappers import Response as WerkzeugResponse from werkzeug.wsgi import FileWrapper from superset import app, is_feature_enabled, thumbnail_cache -from superset.charts.commands.create import CreateChartCommand -from superset.charts.commands.delete import DeleteChartCommand -from superset.charts.commands.exceptions import ( - ChartCreateFailedError, - ChartDeleteFailedError, - ChartForbiddenError, - ChartInvalidError, - ChartNotFoundError, - ChartUpdateFailedError, - DashboardsForbiddenError, -) -from superset.charts.commands.export import ExportChartsCommand -from superset.charts.commands.importers.dispatcher import ImportChartsCommand -from superset.charts.commands.update import UpdateChartCommand -from superset.charts.commands.warm_up_cache import ChartWarmUpCacheCommand from superset.charts.filters import ( ChartAllTextFilter, ChartCertifiedFilter, @@ -69,6 +54,21 @@ from superset.charts.schemas import ( screenshot_query_schema, thumbnail_query_schema, ) +from superset.commands.chart.create import CreateChartCommand +from superset.commands.chart.delete import DeleteChartCommand +from superset.commands.chart.exceptions import ( + ChartCreateFailedError, + ChartDeleteFailedError, + ChartForbiddenError, + ChartInvalidError, + ChartNotFoundError, + ChartUpdateFailedError, + DashboardsForbiddenError, +) +from superset.commands.chart.export import ExportChartsCommand +from superset.commands.chart.importers.dispatcher import ImportChartsCommand +from superset.commands.chart.update import UpdateChartCommand +from superset.commands.chart.warm_up_cache import ChartWarmUpCacheCommand from superset.commands.exceptions import CommandException from superset.commands.importers.exceptions import ( IncorrectFormatError, diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py index 885b6691b..a62e6a240 100644 --- a/superset/charts/data/api.py +++ b/superset/charts/data/api.py @@ -30,17 +30,17 @@ from marshmallow import ValidationError from superset import is_feature_enabled, security_manager from superset.async_events.async_query_manager import AsyncQueryTokenException from superset.charts.api import ChartRestApi -from superset.charts.commands.exceptions import ( - ChartDataCacheLoadError, - ChartDataQueryFailedError, -) -from superset.charts.data.commands.create_async_job_command import ( - CreateAsyncChartDataJobCommand, -) -from superset.charts.data.commands.get_data_command import ChartDataCommand from superset.charts.data.query_context_cache_loader import QueryContextCacheLoader from superset.charts.post_processing import apply_post_process from superset.charts.schemas import ChartDataQueryContextSchema +from superset.commands.chart.data.create_async_job_command import ( + CreateAsyncChartDataJobCommand, +) +from superset.commands.chart.data.get_data_command import ChartDataCommand +from superset.commands.chart.exceptions import ( + ChartDataCacheLoadError, + ChartDataQueryFailedError, +) from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType from superset.connectors.sqla.models import BaseDatasource from superset.daos.exceptions import DatasourceNotFound diff --git a/superset/charts/data/query_context_cache_loader.py b/superset/charts/data/query_context_cache_loader.py index 97fa733a3..1bdabd33f 100644 --- a/superset/charts/data/query_context_cache_loader.py +++ b/superset/charts/data/query_context_cache_loader.py @@ -17,7 +17,7 @@ from typing import Any from superset import cache -from superset.charts.commands.exceptions import ChartDataCacheLoadError +from superset.commands.chart.exceptions import ChartDataCacheLoadError class QueryContextCacheLoader: # pylint: disable=too-few-public-methods diff --git a/superset/cli/importexport.py b/superset/cli/importexport.py index 5dde06d01..0d76e535e 100755 --- a/superset/cli/importexport.py +++ b/superset/cli/importexport.py @@ -72,7 +72,7 @@ if feature_flags.get("VERSIONED_EXPORT"): def export_dashboards(dashboard_file: Optional[str] = None) -> None: """Export dashboards to ZIP file""" # pylint: disable=import-outside-toplevel - from superset.dashboards.commands.export import ExportDashboardsCommand + from superset.commands.dashboard.export import ExportDashboardsCommand from superset.models.dashboard import Dashboard g.user = security_manager.find_user(username="admin") @@ -106,8 +106,8 @@ if feature_flags.get("VERSIONED_EXPORT"): def export_datasources(datasource_file: Optional[str] = None) -> None: """Export datasources to ZIP file""" # pylint: disable=import-outside-toplevel + from superset.commands.dataset.export import ExportDatasetsCommand from superset.connectors.sqla.models import SqlaTable - from superset.datasets.commands.export import ExportDatasetsCommand g.user = security_manager.find_user(username="admin") @@ -144,10 +144,10 @@ if feature_flags.get("VERSIONED_EXPORT"): def import_dashboards(path: str, username: Optional[str]) -> None: """Import dashboards from ZIP file""" # pylint: disable=import-outside-toplevel - from superset.commands.importers.v1.utils import get_contents_from_bundle - from superset.dashboards.commands.importers.dispatcher import ( + from superset.commands.dashboard.importers.dispatcher import ( ImportDashboardsCommand, ) + from superset.commands.importers.v1.utils import get_contents_from_bundle if username is not None: g.user = security_manager.find_user(username=username) @@ -176,10 +176,8 @@ if feature_flags.get("VERSIONED_EXPORT"): def import_datasources(path: str) -> None: """Import datasources from ZIP file""" # pylint: disable=import-outside-toplevel + from superset.commands.dataset.importers.dispatcher import ImportDatasetsCommand from superset.commands.importers.v1.utils import get_contents_from_bundle - from superset.datasets.commands.importers.dispatcher import ( - ImportDatasetsCommand, - ) if is_zipfile(path): with ZipFile(path) as bundle: @@ -304,7 +302,7 @@ else: def import_dashboards(path: str, recursive: bool, username: str) -> None: """Import dashboards from JSON file""" # pylint: disable=import-outside-toplevel - from superset.dashboards.commands.importers.v0 import ImportDashboardsCommand + from superset.commands.dashboard.importers.v0 import ImportDashboardsCommand path_object = Path(path) files: list[Path] = [] @@ -353,7 +351,7 @@ else: def import_datasources(path: str, sync: str, recursive: bool) -> None: """Import datasources from YAML""" # pylint: disable=import-outside-toplevel - from superset.datasets.commands.importers.v0 import ImportDatasetsCommand + from superset.commands.dataset.importers.v0 import ImportDatasetsCommand sync_array = sync.split(",") sync_columns = "columns" in sync_array diff --git a/superset/annotation_layers/annotations/commands/__init__.py b/superset/commands/annotation_layer/__init__.py similarity index 100% rename from superset/annotation_layers/annotations/commands/__init__.py rename to superset/commands/annotation_layer/__init__.py diff --git a/superset/annotation_layers/commands/__init__.py b/superset/commands/annotation_layer/annotation/__init__.py similarity index 100% rename from superset/annotation_layers/commands/__init__.py rename to superset/commands/annotation_layer/annotation/__init__.py diff --git a/superset/annotation_layers/annotations/commands/create.py b/superset/commands/annotation_layer/annotation/create.py similarity index 92% rename from superset/annotation_layers/annotations/commands/create.py rename to superset/commands/annotation_layer/annotation/create.py index 25317762d..feed6162c 100644 --- a/superset/annotation_layers/annotations/commands/create.py +++ b/superset/commands/annotation_layer/annotation/create.py @@ -21,15 +21,15 @@ from typing import Any, Optional from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError -from superset.annotation_layers.annotations.commands.exceptions import ( +from superset.commands.annotation_layer.annotation.exceptions import ( AnnotationCreateFailedError, AnnotationDatesValidationError, AnnotationInvalidError, AnnotationUniquenessValidationError, ) -from superset.annotation_layers.commands.exceptions import AnnotationLayerNotFoundError +from superset.commands.annotation_layer.exceptions import AnnotationLayerNotFoundError from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationDAO, AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationDAO, AnnotationLayerDAO from superset.daos.exceptions import DAOCreateFailedError logger = logging.getLogger(__name__) diff --git a/superset/annotation_layers/annotations/commands/delete.py b/superset/commands/annotation_layer/annotation/delete.py similarity index 93% rename from superset/annotation_layers/annotations/commands/delete.py rename to superset/commands/annotation_layer/annotation/delete.py index 2850f8cb9..3f48ae2ce 100644 --- a/superset/annotation_layers/annotations/commands/delete.py +++ b/superset/commands/annotation_layer/annotation/delete.py @@ -17,12 +17,12 @@ import logging from typing import Optional -from superset.annotation_layers.annotations.commands.exceptions import ( +from superset.commands.annotation_layer.annotation.exceptions import ( AnnotationDeleteFailedError, AnnotationNotFoundError, ) from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationDAO +from superset.daos.annotation_layer import AnnotationDAO from superset.daos.exceptions import DAODeleteFailedError from superset.models.annotations import Annotation diff --git a/superset/annotation_layers/annotations/commands/exceptions.py b/superset/commands/annotation_layer/annotation/exceptions.py similarity index 100% rename from superset/annotation_layers/annotations/commands/exceptions.py rename to superset/commands/annotation_layer/annotation/exceptions.py diff --git a/superset/annotation_layers/annotations/commands/update.py b/superset/commands/annotation_layer/annotation/update.py similarity index 93% rename from superset/annotation_layers/annotations/commands/update.py rename to superset/commands/annotation_layer/annotation/update.py index 76287d24a..9ba07fdcd 100644 --- a/superset/annotation_layers/annotations/commands/update.py +++ b/superset/commands/annotation_layer/annotation/update.py @@ -21,16 +21,16 @@ from typing import Any, Optional from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError -from superset.annotation_layers.annotations.commands.exceptions import ( +from superset.commands.annotation_layer.annotation.exceptions import ( AnnotationDatesValidationError, AnnotationInvalidError, AnnotationNotFoundError, AnnotationUniquenessValidationError, AnnotationUpdateFailedError, ) -from superset.annotation_layers.commands.exceptions import AnnotationLayerNotFoundError +from superset.commands.annotation_layer.exceptions import AnnotationLayerNotFoundError from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationDAO, AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationDAO, AnnotationLayerDAO from superset.daos.exceptions import DAOUpdateFailedError from superset.models.annotations import Annotation diff --git a/superset/annotation_layers/commands/create.py b/superset/commands/annotation_layer/create.py similarity index 94% rename from superset/annotation_layers/commands/create.py rename to superset/commands/annotation_layer/create.py index 39ce752d2..6b87ad570 100644 --- a/superset/annotation_layers/commands/create.py +++ b/superset/commands/annotation_layer/create.py @@ -20,13 +20,13 @@ from typing import Any from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError -from superset.annotation_layers.commands.exceptions import ( +from superset.commands.annotation_layer.exceptions import ( AnnotationLayerCreateFailedError, AnnotationLayerInvalidError, AnnotationLayerNameUniquenessValidationError, ) from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationLayerDAO from superset.daos.exceptions import DAOCreateFailedError logger = logging.getLogger(__name__) diff --git a/superset/annotation_layers/commands/delete.py b/superset/commands/annotation_layer/delete.py similarity index 94% rename from superset/annotation_layers/commands/delete.py rename to superset/commands/annotation_layer/delete.py index 41c727054..a75ee42b7 100644 --- a/superset/annotation_layers/commands/delete.py +++ b/superset/commands/annotation_layer/delete.py @@ -17,13 +17,13 @@ import logging from typing import Optional -from superset.annotation_layers.commands.exceptions import ( +from superset.commands.annotation_layer.exceptions import ( AnnotationLayerDeleteFailedError, AnnotationLayerDeleteIntegrityError, AnnotationLayerNotFoundError, ) from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationLayerDAO from superset.daos.exceptions import DAODeleteFailedError from superset.models.annotations import AnnotationLayer diff --git a/superset/annotation_layers/commands/exceptions.py b/superset/commands/annotation_layer/exceptions.py similarity index 100% rename from superset/annotation_layers/commands/exceptions.py rename to superset/commands/annotation_layer/exceptions.py diff --git a/superset/annotation_layers/commands/update.py b/superset/commands/annotation_layer/update.py similarity index 95% rename from superset/annotation_layers/commands/update.py rename to superset/commands/annotation_layer/update.py index e7f6963e8..d15440882 100644 --- a/superset/annotation_layers/commands/update.py +++ b/superset/commands/annotation_layer/update.py @@ -20,14 +20,14 @@ from typing import Any, Optional from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError -from superset.annotation_layers.commands.exceptions import ( +from superset.commands.annotation_layer.exceptions import ( AnnotationLayerInvalidError, AnnotationLayerNameUniquenessValidationError, AnnotationLayerNotFoundError, AnnotationLayerUpdateFailedError, ) from superset.commands.base import BaseCommand -from superset.daos.annotation import AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationLayerDAO from superset.daos.exceptions import DAOUpdateFailedError from superset.models.annotations import AnnotationLayer diff --git a/superset/charts/commands/__init__.py b/superset/commands/chart/__init__.py similarity index 100% rename from superset/charts/commands/__init__.py rename to superset/commands/chart/__init__.py diff --git a/superset/charts/commands/create.py b/superset/commands/chart/create.py similarity index 98% rename from superset/charts/commands/create.py rename to superset/commands/chart/create.py index 876073e33..2b251029c 100644 --- a/superset/charts/commands/create.py +++ b/superset/commands/chart/create.py @@ -23,13 +23,13 @@ from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError from superset import security_manager -from superset.charts.commands.exceptions import ( +from superset.commands.base import BaseCommand, CreateMixin +from superset.commands.chart.exceptions import ( ChartCreateFailedError, ChartInvalidError, DashboardsForbiddenError, DashboardsNotFoundValidationError, ) -from superset.commands.base import BaseCommand, CreateMixin from superset.commands.utils import get_datasource_by_id from superset.daos.chart import ChartDAO from superset.daos.dashboard import DashboardDAO diff --git a/superset/charts/commands/importers/__init__.py b/superset/commands/chart/data/__init__.py similarity index 100% rename from superset/charts/commands/importers/__init__.py rename to superset/commands/chart/data/__init__.py diff --git a/superset/charts/data/commands/create_async_job_command.py b/superset/commands/chart/data/create_async_job_command.py similarity index 100% rename from superset/charts/data/commands/create_async_job_command.py rename to superset/commands/chart/data/create_async_job_command.py diff --git a/superset/charts/data/commands/get_data_command.py b/superset/commands/chart/data/get_data_command.py similarity index 97% rename from superset/charts/data/commands/get_data_command.py rename to superset/commands/chart/data/get_data_command.py index c791ace9d..971c343cb 100644 --- a/superset/charts/data/commands/get_data_command.py +++ b/superset/commands/chart/data/get_data_command.py @@ -19,11 +19,11 @@ from typing import Any from flask_babel import gettext as _ -from superset.charts.commands.exceptions import ( +from superset.commands.base import BaseCommand +from superset.commands.chart.exceptions import ( ChartDataCacheLoadError, ChartDataQueryFailedError, ) -from superset.commands.base import BaseCommand from superset.common.query_context import QueryContext from superset.exceptions import CacheLoadError diff --git a/superset/charts/commands/delete.py b/superset/commands/chart/delete.py similarity index 98% rename from superset/charts/commands/delete.py rename to superset/commands/chart/delete.py index a31d22be3..ee635f04a 100644 --- a/superset/charts/commands/delete.py +++ b/superset/commands/chart/delete.py @@ -20,13 +20,13 @@ from typing import Optional from flask_babel import lazy_gettext as _ from superset import security_manager -from superset.charts.commands.exceptions import ( +from superset.commands.base import BaseCommand +from superset.commands.chart.exceptions import ( ChartDeleteFailedError, ChartDeleteFailedReportsExistError, ChartForbiddenError, ChartNotFoundError, ) -from superset.commands.base import BaseCommand from superset.daos.chart import ChartDAO from superset.daos.exceptions import DAODeleteFailedError from superset.daos.report import ReportScheduleDAO diff --git a/superset/charts/commands/exceptions.py b/superset/commands/chart/exceptions.py similarity index 100% rename from superset/charts/commands/exceptions.py rename to superset/commands/chart/exceptions.py diff --git a/superset/charts/commands/export.py b/superset/commands/chart/export.py similarity index 95% rename from superset/charts/commands/export.py rename to superset/commands/chart/export.py index c942aa96c..fcb721c70 100644 --- a/superset/charts/commands/export.py +++ b/superset/commands/chart/export.py @@ -22,9 +22,9 @@ from collections.abc import Iterator import yaml -from superset.charts.commands.exceptions import ChartNotFoundError +from superset.commands.chart.exceptions import ChartNotFoundError from superset.daos.chart import ChartDAO -from superset.datasets.commands.export import ExportDatasetsCommand +from superset.commands.dataset.export import ExportDatasetsCommand from superset.commands.export.models import ExportModelsCommand from superset.models.slice import Slice from superset.utils.dict_import_export import EXPORT_VERSION diff --git a/superset/charts/data/commands/__init__.py b/superset/commands/chart/importers/__init__.py similarity index 100% rename from superset/charts/data/commands/__init__.py rename to superset/commands/chart/importers/__init__.py diff --git a/superset/charts/commands/importers/dispatcher.py b/superset/commands/chart/importers/dispatcher.py similarity index 98% rename from superset/charts/commands/importers/dispatcher.py rename to superset/commands/chart/importers/dispatcher.py index fb5007a50..6d2d31ccf 100644 --- a/superset/charts/commands/importers/dispatcher.py +++ b/superset/commands/chart/importers/dispatcher.py @@ -20,8 +20,8 @@ from typing import Any from marshmallow.exceptions import ValidationError -from superset.charts.commands.importers import v1 from superset.commands.base import BaseCommand +from superset.commands.chart.importers import v1 from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError diff --git a/superset/charts/commands/importers/v1/__init__.py b/superset/commands/chart/importers/v1/__init__.py similarity index 93% rename from superset/charts/commands/importers/v1/__init__.py rename to superset/commands/chart/importers/v1/__init__.py index 043018fa3..783f300c0 100644 --- a/superset/charts/commands/importers/v1/__init__.py +++ b/superset/commands/chart/importers/v1/__init__.py @@ -20,15 +20,15 @@ from typing import Any from marshmallow import Schema from sqlalchemy.orm import Session -from superset.charts.commands.exceptions import ChartImportError -from superset.charts.commands.importers.v1.utils import import_chart from superset.charts.schemas import ImportV1ChartSchema +from superset.commands.chart.exceptions import ChartImportError +from superset.commands.chart.importers.v1.utils import import_chart +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.importers.v1.utils import import_dataset from superset.commands.importers.v1 import ImportModelsCommand from superset.connectors.sqla.models import SqlaTable from superset.daos.chart import ChartDAO -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema diff --git a/superset/charts/commands/importers/v1/utils.py b/superset/commands/chart/importers/v1/utils.py similarity index 100% rename from superset/charts/commands/importers/v1/utils.py rename to superset/commands/chart/importers/v1/utils.py diff --git a/superset/charts/commands/update.py b/superset/commands/chart/update.py similarity index 98% rename from superset/charts/commands/update.py rename to superset/commands/chart/update.py index 32fd49e7c..40b36ebcc 100644 --- a/superset/charts/commands/update.py +++ b/superset/commands/chart/update.py @@ -23,7 +23,8 @@ from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError from superset import security_manager -from superset.charts.commands.exceptions import ( +from superset.commands.base import BaseCommand, UpdateMixin +from superset.commands.chart.exceptions import ( ChartForbiddenError, ChartInvalidError, ChartNotFoundError, @@ -31,7 +32,6 @@ from superset.charts.commands.exceptions import ( DashboardsNotFoundValidationError, DatasourceTypeUpdateRequiredValidationError, ) -from superset.commands.base import BaseCommand, UpdateMixin from superset.commands.utils import get_datasource_by_id from superset.daos.chart import ChartDAO from superset.daos.dashboard import DashboardDAO diff --git a/superset/charts/commands/warm_up_cache.py b/superset/commands/chart/warm_up_cache.py similarity index 96% rename from superset/charts/commands/warm_up_cache.py rename to superset/commands/chart/warm_up_cache.py index a684ee5e7..2e5c0ac3a 100644 --- a/superset/charts/commands/warm_up_cache.py +++ b/superset/commands/chart/warm_up_cache.py @@ -21,12 +21,12 @@ from typing import Any, Optional, Union import simplejson as json from flask import g -from superset.charts.commands.exceptions import ( +from superset.commands.base import BaseCommand +from superset.commands.chart.data.get_data_command import ChartDataCommand +from superset.commands.chart.exceptions import ( ChartInvalidError, WarmUpCacheChartNotFoundError, ) -from superset.charts.data.commands.get_data_command import ChartDataCommand -from superset.commands.base import BaseCommand from superset.extensions import db from superset.models.slice import Slice from superset.utils.core import error_msg_from_exception diff --git a/superset/css_templates/commands/__init__.py b/superset/commands/css/__init__.py similarity index 100% rename from superset/css_templates/commands/__init__.py rename to superset/commands/css/__init__.py diff --git a/superset/css_templates/commands/delete.py b/superset/commands/css/delete.py similarity index 97% rename from superset/css_templates/commands/delete.py rename to superset/commands/css/delete.py index 123658cb4..b8362f6b4 100644 --- a/superset/css_templates/commands/delete.py +++ b/superset/commands/css/delete.py @@ -18,7 +18,7 @@ import logging from typing import Optional from superset.commands.base import BaseCommand -from superset.css_templates.commands.exceptions import ( +from superset.commands.css.exceptions import ( CssTemplateDeleteFailedError, CssTemplateNotFoundError, ) diff --git a/superset/css_templates/commands/exceptions.py b/superset/commands/css/exceptions.py similarity index 100% rename from superset/css_templates/commands/exceptions.py rename to superset/commands/css/exceptions.py diff --git a/superset/dashboards/commands/__init__.py b/superset/commands/dashboard/__init__.py similarity index 100% rename from superset/dashboards/commands/__init__.py rename to superset/commands/dashboard/__init__.py diff --git a/superset/dashboards/commands/create.py b/superset/commands/dashboard/create.py similarity index 98% rename from superset/dashboards/commands/create.py rename to superset/commands/dashboard/create.py index 4b5cd5fb0..174539123 100644 --- a/superset/dashboards/commands/create.py +++ b/superset/commands/dashboard/create.py @@ -21,14 +21,14 @@ from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError from superset.commands.base import BaseCommand, CreateMixin -from superset.commands.utils import populate_roles -from superset.daos.dashboard import DashboardDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardCreateFailedError, DashboardInvalidError, DashboardSlugExistsValidationError, ) +from superset.commands.utils import populate_roles +from superset.daos.dashboard import DashboardDAO +from superset.daos.exceptions import DAOCreateFailedError logger = logging.getLogger(__name__) diff --git a/superset/dashboards/commands/delete.py b/superset/commands/dashboard/delete.py similarity index 98% rename from superset/dashboards/commands/delete.py rename to superset/commands/dashboard/delete.py index 7111758bb..13ffcb443 100644 --- a/superset/dashboards/commands/delete.py +++ b/superset/commands/dashboard/delete.py @@ -21,15 +21,15 @@ from flask_babel import lazy_gettext as _ from superset import security_manager from superset.commands.base import BaseCommand -from superset.daos.dashboard import DashboardDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.report import ReportScheduleDAO -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardDeleteFailedError, DashboardDeleteFailedReportsExistError, DashboardForbiddenError, DashboardNotFoundError, ) +from superset.daos.dashboard import DashboardDAO +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.report import ReportScheduleDAO from superset.exceptions import SupersetSecurityException from superset.models.dashboard import Dashboard diff --git a/superset/dashboards/commands/importers/__init__.py b/superset/commands/dashboard/embedded/__init__.py similarity index 100% rename from superset/dashboards/commands/importers/__init__.py rename to superset/commands/dashboard/embedded/__init__.py diff --git a/superset/embedded_dashboard/commands/exceptions.py b/superset/commands/dashboard/embedded/exceptions.py similarity index 100% rename from superset/embedded_dashboard/commands/exceptions.py rename to superset/commands/dashboard/embedded/exceptions.py diff --git a/superset/dashboards/commands/exceptions.py b/superset/commands/dashboard/exceptions.py similarity index 100% rename from superset/dashboards/commands/exceptions.py rename to superset/commands/dashboard/exceptions.py diff --git a/superset/dashboards/commands/export.py b/superset/commands/dashboard/export.py similarity index 95% rename from superset/dashboards/commands/export.py rename to superset/commands/dashboard/export.py index 4e25e5c1f..fd06c60fa 100644 --- a/superset/dashboards/commands/export.py +++ b/superset/commands/dashboard/export.py @@ -25,12 +25,12 @@ from collections.abc import Iterator import yaml -from superset.charts.commands.export import ExportChartsCommand -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.commands.importers.v1.utils import find_chart_uuids +from superset.commands.chart.export import ExportChartsCommand +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.importers.v1.utils import find_chart_uuids from superset.daos.dashboard import DashboardDAO from superset.commands.export.models import ExportModelsCommand -from superset.datasets.commands.export import ExportDatasetsCommand +from superset.commands.dataset.export import ExportDatasetsCommand from superset.daos.dataset import DatasetDAO from superset.models.dashboard import Dashboard from superset.models.slice import Slice diff --git a/superset/dashboards/filter_sets/commands/__init__.py b/superset/commands/dashboard/filter_set/__init__.py similarity index 100% rename from superset/dashboards/filter_sets/commands/__init__.py rename to superset/commands/dashboard/filter_set/__init__.py diff --git a/superset/dashboards/filter_sets/commands/base.py b/superset/commands/dashboard/filter_set/base.py similarity index 96% rename from superset/dashboards/filter_sets/commands/base.py rename to superset/commands/dashboard/filter_set/base.py index 8c53e8a81..24abe2509 100644 --- a/superset/dashboards/filter_sets/commands/base.py +++ b/superset/commands/dashboard/filter_set/base.py @@ -20,13 +20,13 @@ from typing import cast, Optional from flask_appbuilder.models.sqla import Model from superset import security_manager -from superset.common.not_authorized_object import NotAuthorizedException -from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.filter_sets.commands.exceptions import ( +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.filter_set.exceptions import ( FilterSetForbiddenError, FilterSetNotFoundError, ) +from superset.common.not_authorized_object import NotAuthorizedException +from superset.daos.dashboard import DashboardDAO from superset.dashboards.filter_sets.consts import USER_OWNER_TYPE from superset.models.dashboard import Dashboard from superset.models.filter_set import FilterSet diff --git a/superset/dashboards/filter_sets/commands/create.py b/superset/commands/dashboard/filter_set/create.py similarity index 95% rename from superset/dashboards/filter_sets/commands/create.py rename to superset/commands/dashboard/filter_set/create.py index d254e86d3..49edb3172 100644 --- a/superset/dashboards/filter_sets/commands/create.py +++ b/superset/commands/dashboard/filter_set/create.py @@ -20,13 +20,13 @@ from typing import Any from flask_appbuilder.models.sqla import Model from superset import security_manager -from superset.daos.dashboard import FilterSetDAO -from superset.dashboards.filter_sets.commands.base import BaseFilterSetCommand -from superset.dashboards.filter_sets.commands.exceptions import ( +from superset.commands.dashboard.filter_set.base import BaseFilterSetCommand +from superset.commands.dashboard.filter_set.exceptions import ( DashboardIdInconsistencyError, FilterSetCreateFailedError, UserIsNotDashboardOwnerError, ) +from superset.daos.dashboard import FilterSetDAO from superset.dashboards.filter_sets.consts import ( DASHBOARD_ID_FIELD, DASHBOARD_OWNER_TYPE, diff --git a/superset/dashboards/filter_sets/commands/delete.py b/superset/commands/dashboard/filter_set/delete.py similarity index 93% rename from superset/dashboards/filter_sets/commands/delete.py rename to superset/commands/dashboard/filter_set/delete.py index 8ac2107ca..ce2bf6fce 100644 --- a/superset/dashboards/filter_sets/commands/delete.py +++ b/superset/commands/dashboard/filter_set/delete.py @@ -16,14 +16,14 @@ # under the License. import logging -from superset.daos.dashboard import FilterSetDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.dashboards.filter_sets.commands.base import BaseFilterSetCommand -from superset.dashboards.filter_sets.commands.exceptions import ( +from superset.commands.dashboard.filter_set.base import BaseFilterSetCommand +from superset.commands.dashboard.filter_set.exceptions import ( FilterSetDeleteFailedError, FilterSetForbiddenError, FilterSetNotFoundError, ) +from superset.daos.dashboard import FilterSetDAO +from superset.daos.exceptions import DAODeleteFailedError logger = logging.getLogger(__name__) diff --git a/superset/dashboards/filter_sets/commands/exceptions.py b/superset/commands/dashboard/filter_set/exceptions.py similarity index 100% rename from superset/dashboards/filter_sets/commands/exceptions.py rename to superset/commands/dashboard/filter_set/exceptions.py diff --git a/superset/dashboards/filter_sets/commands/update.py b/superset/commands/dashboard/filter_set/update.py similarity index 91% rename from superset/dashboards/filter_sets/commands/update.py rename to superset/commands/dashboard/filter_set/update.py index a63c8d46f..5ce9f1fea 100644 --- a/superset/dashboards/filter_sets/commands/update.py +++ b/superset/commands/dashboard/filter_set/update.py @@ -19,12 +19,10 @@ from typing import Any from flask_appbuilder.models.sqla import Model +from superset.commands.dashboard.filter_set.base import BaseFilterSetCommand +from superset.commands.dashboard.filter_set.exceptions import FilterSetUpdateFailedError from superset.daos.dashboard import FilterSetDAO from superset.daos.exceptions import DAOUpdateFailedError -from superset.dashboards.filter_sets.commands.base import BaseFilterSetCommand -from superset.dashboards.filter_sets.commands.exceptions import ( - FilterSetUpdateFailedError, -) from superset.dashboards.filter_sets.consts import OWNER_ID_FIELD, OWNER_TYPE_FIELD logger = logging.getLogger(__name__) diff --git a/superset/dashboards/filter_state/commands/__init__.py b/superset/commands/dashboard/filter_state/__init__.py similarity index 100% rename from superset/dashboards/filter_state/commands/__init__.py rename to superset/commands/dashboard/filter_state/__init__.py diff --git a/superset/dashboards/filter_state/commands/create.py b/superset/commands/dashboard/filter_state/create.py similarity index 87% rename from superset/dashboards/filter_state/commands/create.py rename to superset/commands/dashboard/filter_state/create.py index 48b5e4f5c..1f105ac5c 100644 --- a/superset/dashboards/filter_state/commands/create.py +++ b/superset/commands/dashboard/filter_state/create.py @@ -18,12 +18,12 @@ from typing import cast from flask import session -from superset.dashboards.filter_state.commands.utils import check_access +from superset.commands.dashboard.filter_state.utils import check_access +from superset.commands.temporary_cache.create import CreateTemporaryCacheCommand +from superset.commands.temporary_cache.entry import Entry +from superset.commands.temporary_cache.parameters import CommandParameters from superset.extensions import cache_manager from superset.key_value.utils import random_key -from superset.temporary_cache.commands.create import CreateTemporaryCacheCommand -from superset.temporary_cache.commands.entry import Entry -from superset.temporary_cache.commands.parameters import CommandParameters from superset.temporary_cache.utils import cache_key from superset.utils.core import get_user_id diff --git a/superset/dashboards/filter_state/commands/delete.py b/superset/commands/dashboard/filter_state/delete.py similarity index 84% rename from superset/dashboards/filter_state/commands/delete.py rename to superset/commands/dashboard/filter_state/delete.py index 6086388a8..8be7f44d9 100644 --- a/superset/dashboards/filter_state/commands/delete.py +++ b/superset/commands/dashboard/filter_state/delete.py @@ -16,12 +16,12 @@ # under the License. from flask import session -from superset.dashboards.filter_state.commands.utils import check_access +from superset.commands.dashboard.filter_state.utils import check_access +from superset.commands.temporary_cache.delete import DeleteTemporaryCacheCommand +from superset.commands.temporary_cache.entry import Entry +from superset.commands.temporary_cache.exceptions import TemporaryCacheAccessDeniedError +from superset.commands.temporary_cache.parameters import CommandParameters from superset.extensions import cache_manager -from superset.temporary_cache.commands.delete import DeleteTemporaryCacheCommand -from superset.temporary_cache.commands.entry import Entry -from superset.temporary_cache.commands.exceptions import TemporaryCacheAccessDeniedError -from superset.temporary_cache.commands.parameters import CommandParameters from superset.temporary_cache.utils import cache_key from superset.utils.core import get_user_id diff --git a/superset/dashboards/filter_state/commands/get.py b/superset/commands/dashboard/filter_state/get.py similarity index 89% rename from superset/dashboards/filter_state/commands/get.py rename to superset/commands/dashboard/filter_state/get.py index ca7ffa987..29104b5ee 100644 --- a/superset/dashboards/filter_state/commands/get.py +++ b/superset/commands/dashboard/filter_state/get.py @@ -18,10 +18,10 @@ from typing import Optional from flask import current_app as app -from superset.dashboards.filter_state.commands.utils import check_access +from superset.commands.dashboard.filter_state.utils import check_access +from superset.commands.temporary_cache.get import GetTemporaryCacheCommand +from superset.commands.temporary_cache.parameters import CommandParameters from superset.extensions import cache_manager -from superset.temporary_cache.commands.get import GetTemporaryCacheCommand -from superset.temporary_cache.commands.parameters import CommandParameters from superset.temporary_cache.utils import cache_key diff --git a/superset/dashboards/filter_state/commands/update.py b/superset/commands/dashboard/filter_state/update.py similarity index 87% rename from superset/dashboards/filter_state/commands/update.py rename to superset/commands/dashboard/filter_state/update.py index c1dc529cc..80b8c26ed 100644 --- a/superset/dashboards/filter_state/commands/update.py +++ b/superset/commands/dashboard/filter_state/update.py @@ -18,13 +18,13 @@ from typing import cast, Optional from flask import session -from superset.dashboards.filter_state.commands.utils import check_access +from superset.commands.dashboard.filter_state.utils import check_access +from superset.commands.temporary_cache.entry import Entry +from superset.commands.temporary_cache.exceptions import TemporaryCacheAccessDeniedError +from superset.commands.temporary_cache.parameters import CommandParameters +from superset.commands.temporary_cache.update import UpdateTemporaryCacheCommand from superset.extensions import cache_manager from superset.key_value.utils import random_key -from superset.temporary_cache.commands.entry import Entry -from superset.temporary_cache.commands.exceptions import TemporaryCacheAccessDeniedError -from superset.temporary_cache.commands.parameters import CommandParameters -from superset.temporary_cache.commands.update import UpdateTemporaryCacheCommand from superset.temporary_cache.utils import cache_key from superset.utils.core import get_user_id diff --git a/superset/dashboards/filter_state/commands/utils.py b/superset/commands/dashboard/filter_state/utils.py similarity index 91% rename from superset/dashboards/filter_state/commands/utils.py rename to superset/commands/dashboard/filter_state/utils.py index 7e5251824..14f7eb789 100644 --- a/superset/dashboards/filter_state/commands/utils.py +++ b/superset/commands/dashboard/filter_state/utils.py @@ -15,15 +15,15 @@ # specific language governing permissions and limitations # under the License. -from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardAccessDeniedError, DashboardNotFoundError, ) -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheResourceNotFoundError, ) +from superset.daos.dashboard import DashboardDAO def check_access(resource_id: int) -> None: diff --git a/superset/dashboards/permalink/commands/__init__.py b/superset/commands/dashboard/importers/__init__.py similarity index 100% rename from superset/dashboards/permalink/commands/__init__.py rename to superset/commands/dashboard/importers/__init__.py diff --git a/superset/dashboards/commands/importers/dispatcher.py b/superset/commands/dashboard/importers/dispatcher.py similarity index 97% rename from superset/dashboards/commands/importers/dispatcher.py rename to superset/commands/dashboard/importers/dispatcher.py index d5323b4fe..061558cce 100644 --- a/superset/dashboards/commands/importers/dispatcher.py +++ b/superset/commands/dashboard/importers/dispatcher.py @@ -21,9 +21,9 @@ from typing import Any from marshmallow.exceptions import ValidationError from superset.commands.base import BaseCommand +from superset.commands.dashboard.importers import v0, v1 from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError -from superset.dashboards.commands.importers import v0, v1 logger = logging.getLogger(__name__) diff --git a/superset/dashboards/commands/importers/v0.py b/superset/commands/dashboard/importers/v0.py similarity index 99% rename from superset/dashboards/commands/importers/v0.py rename to superset/commands/dashboard/importers/v0.py index 012dbbc5c..4c2a18e5c 100644 --- a/superset/dashboards/commands/importers/v0.py +++ b/superset/commands/dashboard/importers/v0.py @@ -26,8 +26,8 @@ from sqlalchemy.orm import make_transient, Session from superset import db from superset.commands.base import BaseCommand +from superset.commands.dataset.importers.v0 import import_dataset from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn -from superset.datasets.commands.importers.v0 import import_dataset from superset.exceptions import DashboardImportException from superset.models.dashboard import Dashboard from superset.models.slice import Slice diff --git a/superset/dashboards/commands/importers/v1/__init__.py b/superset/commands/dashboard/importers/v1/__init__.py similarity index 94% rename from superset/dashboards/commands/importers/v1/__init__.py rename to superset/commands/dashboard/importers/v1/__init__.py index 30e63da4e..2717650e9 100644 --- a/superset/dashboards/commands/importers/v1/__init__.py +++ b/superset/commands/dashboard/importers/v1/__init__.py @@ -21,21 +21,21 @@ from marshmallow import Schema from sqlalchemy.orm import Session from sqlalchemy.sql import select -from superset.charts.commands.importers.v1.utils import import_chart from superset.charts.schemas import ImportV1ChartSchema -from superset.commands.importers.v1 import ImportModelsCommand -from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import DashboardImportError -from superset.dashboards.commands.importers.v1.utils import ( +from superset.commands.chart.importers.v1.utils import import_chart +from superset.commands.dashboard.exceptions import DashboardImportError +from superset.commands.dashboard.importers.v1.utils import ( find_chart_uuids, find_native_filter_datasets, import_dashboard, update_id_refs, ) +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.importers.v1.utils import import_dataset +from superset.commands.importers.v1 import ImportModelsCommand +from superset.daos.dashboard import DashboardDAO from superset.dashboards.schemas import ImportV1DashboardSchema -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.dashboard import dashboard_slices diff --git a/superset/dashboards/commands/importers/v1/utils.py b/superset/commands/dashboard/importers/v1/utils.py similarity index 100% rename from superset/dashboards/commands/importers/v1/utils.py rename to superset/commands/dashboard/importers/v1/utils.py diff --git a/superset/databases/commands/__init__.py b/superset/commands/dashboard/permalink/__init__.py similarity index 100% rename from superset/databases/commands/__init__.py rename to superset/commands/dashboard/permalink/__init__.py diff --git a/superset/dashboards/permalink/commands/base.py b/superset/commands/dashboard/permalink/base.py similarity index 100% rename from superset/dashboards/permalink/commands/base.py rename to superset/commands/dashboard/permalink/base.py diff --git a/superset/dashboards/permalink/commands/create.py b/superset/commands/dashboard/permalink/create.py similarity index 94% rename from superset/dashboards/permalink/commands/create.py rename to superset/commands/dashboard/permalink/create.py index 320003ff3..3387d432d 100644 --- a/superset/dashboards/permalink/commands/create.py +++ b/superset/commands/dashboard/permalink/create.py @@ -18,11 +18,11 @@ import logging from sqlalchemy.exc import SQLAlchemyError +from superset.commands.dashboard.permalink.base import BaseDashboardPermalinkCommand +from superset.commands.key_value.upsert import UpsertKeyValueCommand from superset.daos.dashboard import DashboardDAO -from superset.dashboards.permalink.commands.base import BaseDashboardPermalinkCommand from superset.dashboards.permalink.exceptions import DashboardPermalinkCreateFailedError from superset.dashboards.permalink.types import DashboardPermalinkState -from superset.key_value.commands.upsert import UpsertKeyValueCommand from superset.key_value.exceptions import KeyValueCodecEncodeException from superset.key_value.utils import encode_permalink_key, get_deterministic_uuid from superset.utils.core import get_user_id diff --git a/superset/dashboards/permalink/commands/get.py b/superset/commands/dashboard/permalink/get.py similarity index 91% rename from superset/dashboards/permalink/commands/get.py rename to superset/commands/dashboard/permalink/get.py index 6b32a459a..32efa6888 100644 --- a/superset/dashboards/permalink/commands/get.py +++ b/superset/commands/dashboard/permalink/get.py @@ -19,12 +19,12 @@ from typing import Optional from sqlalchemy.exc import SQLAlchemyError +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.permalink.base import BaseDashboardPermalinkCommand +from superset.commands.key_value.get import GetKeyValueCommand from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.permalink.commands.base import BaseDashboardPermalinkCommand from superset.dashboards.permalink.exceptions import DashboardPermalinkGetFailedError from superset.dashboards.permalink.types import DashboardPermalinkValue -from superset.key_value.commands.get import GetKeyValueCommand from superset.key_value.exceptions import ( KeyValueCodecDecodeException, KeyValueGetFailedError, diff --git a/superset/dashboards/commands/update.py b/superset/commands/dashboard/update.py similarity index 98% rename from superset/dashboards/commands/update.py rename to superset/commands/dashboard/update.py index f9975c0dd..22dcad4b2 100644 --- a/superset/dashboards/commands/update.py +++ b/superset/commands/dashboard/update.py @@ -23,16 +23,16 @@ from marshmallow import ValidationError from superset import security_manager from superset.commands.base import BaseCommand, UpdateMixin -from superset.commands.utils import populate_roles -from superset.daos.dashboard import DashboardDAO -from superset.daos.exceptions import DAOUpdateFailedError -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardForbiddenError, DashboardInvalidError, DashboardNotFoundError, DashboardSlugExistsValidationError, DashboardUpdateFailedError, ) +from superset.commands.utils import populate_roles +from superset.daos.dashboard import DashboardDAO +from superset.daos.exceptions import DAOUpdateFailedError from superset.exceptions import SupersetSecurityException from superset.extensions import db from superset.models.dashboard import Dashboard diff --git a/superset/databases/commands/importers/__init__.py b/superset/commands/database/__init__.py similarity index 100% rename from superset/databases/commands/importers/__init__.py rename to superset/commands/database/__init__.py diff --git a/superset/databases/commands/create.py b/superset/commands/database/create.py similarity index 95% rename from superset/databases/commands/create.py rename to superset/commands/database/create.py index d3dfe59e5..a012e9b2a 100644 --- a/superset/databases/commands/create.py +++ b/superset/commands/database/create.py @@ -23,22 +23,22 @@ from marshmallow import ValidationError from superset import is_feature_enabled from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseConnectionFailedError, DatabaseCreateFailedError, DatabaseExistsValidationError, DatabaseInvalidError, DatabaseRequiredFieldValidationError, ) -from superset.databases.commands.test_connection import TestConnectionDatabaseCommand -from superset.databases.ssh_tunnel.commands.create import CreateSSHTunnelCommand -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelCreateFailedError, SSHTunnelingNotEnabledError, SSHTunnelInvalidError, ) +from superset.commands.database.test_connection import TestConnectionDatabaseCommand +from superset.daos.database import DatabaseDAO +from superset.daos.exceptions import DAOCreateFailedError from superset.exceptions import SupersetErrorsException from superset.extensions import db, event_logger, security_manager diff --git a/superset/databases/commands/delete.py b/superset/commands/database/delete.py similarity index 97% rename from superset/databases/commands/delete.py rename to superset/commands/database/delete.py index 59a247a50..2db408c76 100644 --- a/superset/databases/commands/delete.py +++ b/superset/commands/database/delete.py @@ -20,15 +20,15 @@ from typing import Optional from flask_babel import lazy_gettext as _ from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.report import ReportScheduleDAO -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseDeleteDatasetsExistFailedError, DatabaseDeleteFailedError, DatabaseDeleteFailedReportsExistError, DatabaseNotFoundError, ) +from superset.daos.database import DatabaseDAO +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.report import ReportScheduleDAO from superset.models.core import Database logger = logging.getLogger(__name__) diff --git a/superset/databases/commands/exceptions.py b/superset/commands/database/exceptions.py similarity index 100% rename from superset/databases/commands/exceptions.py rename to superset/commands/database/exceptions.py diff --git a/superset/databases/commands/export.py b/superset/commands/database/export.py similarity index 98% rename from superset/databases/commands/export.py rename to superset/commands/database/export.py index 71dc55a02..82c22ea80 100644 --- a/superset/databases/commands/export.py +++ b/superset/commands/database/export.py @@ -23,7 +23,7 @@ from collections.abc import Iterator import yaml -from superset.databases.commands.exceptions import DatabaseNotFoundError +from superset.commands.database.exceptions import DatabaseNotFoundError from superset.daos.database import DatabaseDAO from superset.commands.export.models import ExportModelsCommand from superset.models.core import Database diff --git a/superset/databases/ssh_tunnel/commands/__init__.py b/superset/commands/database/importers/__init__.py similarity index 100% rename from superset/databases/ssh_tunnel/commands/__init__.py rename to superset/commands/database/importers/__init__.py diff --git a/superset/databases/commands/importers/dispatcher.py b/superset/commands/database/importers/dispatcher.py similarity index 97% rename from superset/databases/commands/importers/dispatcher.py rename to superset/commands/database/importers/dispatcher.py index 70031b09e..bdf487a75 100644 --- a/superset/databases/commands/importers/dispatcher.py +++ b/superset/commands/database/importers/dispatcher.py @@ -21,9 +21,9 @@ from typing import Any from marshmallow.exceptions import ValidationError from superset.commands.base import BaseCommand +from superset.commands.database.importers import v1 from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError -from superset.databases.commands.importers import v1 logger = logging.getLogger(__name__) diff --git a/superset/databases/commands/importers/v1/__init__.py b/superset/commands/database/importers/v1/__init__.py similarity index 91% rename from superset/databases/commands/importers/v1/__init__.py rename to superset/commands/database/importers/v1/__init__.py index 585c2d54c..73b1bca53 100644 --- a/superset/databases/commands/importers/v1/__init__.py +++ b/superset/commands/database/importers/v1/__init__.py @@ -20,12 +20,12 @@ from typing import Any from marshmallow import Schema from sqlalchemy.orm import Session +from superset.commands.database.exceptions import DatabaseImportError +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.importers.v1.utils import import_dataset from superset.commands.importers.v1 import ImportModelsCommand from superset.daos.database import DatabaseDAO -from superset.databases.commands.exceptions import DatabaseImportError -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema diff --git a/superset/databases/commands/importers/v1/utils.py b/superset/commands/database/importers/v1/utils.py similarity index 100% rename from superset/databases/commands/importers/v1/utils.py rename to superset/commands/database/importers/v1/utils.py diff --git a/superset/datasets/columns/commands/__init__.py b/superset/commands/database/ssh_tunnel/__init__.py similarity index 100% rename from superset/datasets/columns/commands/__init__.py rename to superset/commands/database/ssh_tunnel/__init__.py diff --git a/superset/databases/ssh_tunnel/commands/create.py b/superset/commands/database/ssh_tunnel/create.py similarity index 98% rename from superset/databases/ssh_tunnel/commands/create.py rename to superset/commands/database/ssh_tunnel/create.py index 36f33e46f..07209f010 100644 --- a/superset/databases/ssh_tunnel/commands/create.py +++ b/superset/commands/database/ssh_tunnel/create.py @@ -21,13 +21,13 @@ from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError from superset.commands.base import BaseCommand -from superset.daos.database import SSHTunnelDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelCreateFailedError, SSHTunnelInvalidError, SSHTunnelRequiredFieldValidationError, ) +from superset.daos.database import SSHTunnelDAO +from superset.daos.exceptions import DAOCreateFailedError from superset.extensions import db, event_logger logger = logging.getLogger(__name__) diff --git a/superset/databases/ssh_tunnel/commands/delete.py b/superset/commands/database/ssh_tunnel/delete.py similarity index 96% rename from superset/databases/ssh_tunnel/commands/delete.py rename to superset/commands/database/ssh_tunnel/delete.py index 70be55ce4..b8919e6d7 100644 --- a/superset/databases/ssh_tunnel/commands/delete.py +++ b/superset/commands/database/ssh_tunnel/delete.py @@ -19,13 +19,13 @@ from typing import Optional from superset import is_feature_enabled from superset.commands.base import BaseCommand -from superset.daos.database import SSHTunnelDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelDeleteFailedError, SSHTunnelingNotEnabledError, SSHTunnelNotFoundError, ) +from superset.daos.database import SSHTunnelDAO +from superset.daos.exceptions import DAODeleteFailedError from superset.databases.ssh_tunnel.models import SSHTunnel logger = logging.getLogger(__name__) diff --git a/superset/databases/ssh_tunnel/commands/exceptions.py b/superset/commands/database/ssh_tunnel/exceptions.py similarity index 100% rename from superset/databases/ssh_tunnel/commands/exceptions.py rename to superset/commands/database/ssh_tunnel/exceptions.py diff --git a/superset/databases/ssh_tunnel/commands/update.py b/superset/commands/database/ssh_tunnel/update.py similarity index 97% rename from superset/databases/ssh_tunnel/commands/update.py rename to superset/commands/database/ssh_tunnel/update.py index 4e4edcb66..ae7ee78af 100644 --- a/superset/databases/ssh_tunnel/commands/update.py +++ b/superset/commands/database/ssh_tunnel/update.py @@ -20,14 +20,14 @@ from typing import Any, Optional from flask_appbuilder.models.sqla import Model from superset.commands.base import BaseCommand -from superset.daos.database import SSHTunnelDAO -from superset.daos.exceptions import DAOUpdateFailedError -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelInvalidError, SSHTunnelNotFoundError, SSHTunnelRequiredFieldValidationError, SSHTunnelUpdateFailedError, ) +from superset.daos.database import SSHTunnelDAO +from superset.daos.exceptions import DAOUpdateFailedError from superset.databases.ssh_tunnel.models import SSHTunnel logger = logging.getLogger(__name__) diff --git a/superset/databases/commands/tables.py b/superset/commands/database/tables.py similarity index 98% rename from superset/databases/commands/tables.py rename to superset/commands/database/tables.py index 6232470ec..fa98bcbc7 100644 --- a/superset/databases/commands/tables.py +++ b/superset/commands/database/tables.py @@ -20,12 +20,12 @@ from typing import Any, cast from sqlalchemy.orm import lazyload, load_only from superset.commands.base import BaseCommand -from superset.connectors.sqla.models import SqlaTable -from superset.daos.database import DatabaseDAO -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseNotFoundError, DatabaseTablesUnexpectedError, ) +from superset.connectors.sqla.models import SqlaTable +from superset.daos.database import DatabaseDAO from superset.exceptions import SupersetException from superset.extensions import db, security_manager from superset.models.core import Database diff --git a/superset/databases/commands/test_connection.py b/superset/commands/database/test_connection.py similarity index 98% rename from superset/databases/commands/test_connection.py rename to superset/commands/database/test_connection.py index 49c5340dd..0ffdf3ddd 100644 --- a/superset/databases/commands/test_connection.py +++ b/superset/commands/database/test_connection.py @@ -27,15 +27,13 @@ from sqlalchemy.exc import DBAPIError, NoSuchModuleError from superset import is_feature_enabled from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO, SSHTunnelDAO -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseSecurityUnsafeError, DatabaseTestConnectionDriverError, DatabaseTestConnectionUnexpectedError, ) -from superset.databases.ssh_tunnel.commands.exceptions import ( - SSHTunnelingNotEnabledError, -) +from superset.commands.database.ssh_tunnel.exceptions import SSHTunnelingNotEnabledError +from superset.daos.database import DatabaseDAO, SSHTunnelDAO from superset.databases.ssh_tunnel.models import SSHTunnel from superset.databases.utils import make_url_safe from superset.errors import ErrorLevel, SupersetErrorType diff --git a/superset/databases/commands/update.py b/superset/commands/database/update.py similarity index 96% rename from superset/databases/commands/update.py rename to superset/commands/database/update.py index d8d86c6d2..039d731d7 100644 --- a/superset/databases/commands/update.py +++ b/superset/commands/database/update.py @@ -22,23 +22,23 @@ from marshmallow import ValidationError from superset import is_feature_enabled from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO -from superset.daos.exceptions import DAOCreateFailedError, DAOUpdateFailedError -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseConnectionFailedError, DatabaseExistsValidationError, DatabaseInvalidError, DatabaseNotFoundError, DatabaseUpdateFailedError, ) -from superset.databases.ssh_tunnel.commands.create import CreateSSHTunnelCommand -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelCreateFailedError, SSHTunnelingNotEnabledError, SSHTunnelInvalidError, SSHTunnelUpdateFailedError, ) -from superset.databases.ssh_tunnel.commands.update import UpdateSSHTunnelCommand +from superset.commands.database.ssh_tunnel.update import UpdateSSHTunnelCommand +from superset.daos.database import DatabaseDAO +from superset.daos.exceptions import DAOCreateFailedError, DAOUpdateFailedError from superset.extensions import db, security_manager from superset.models.core import Database from superset.utils.core import DatasourceType diff --git a/superset/databases/commands/validate.py b/superset/commands/database/validate.py similarity index 98% rename from superset/databases/commands/validate.py rename to superset/commands/database/validate.py index 6ea412b49..83bbc4e90 100644 --- a/superset/databases/commands/validate.py +++ b/superset/commands/database/validate.py @@ -21,13 +21,13 @@ from typing import Any, Optional from flask_babel import gettext as __ from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseOfflineError, DatabaseTestConnectionFailedError, InvalidEngineError, InvalidParametersError, ) +from superset.daos.database import DatabaseDAO from superset.databases.utils import make_url_safe from superset.db_engine_specs import get_engine_spec from superset.errors import ErrorLevel, SupersetError, SupersetErrorType diff --git a/superset/databases/commands/validate_sql.py b/superset/commands/database/validate_sql.py similarity index 98% rename from superset/databases/commands/validate_sql.py rename to superset/commands/database/validate_sql.py index 6fc0c3a39..9a00526bf 100644 --- a/superset/databases/commands/validate_sql.py +++ b/superset/commands/database/validate_sql.py @@ -22,8 +22,7 @@ from flask import current_app from flask_babel import gettext as __ from superset.commands.base import BaseCommand -from superset.daos.database import DatabaseDAO -from superset.databases.commands.exceptions import ( +from superset.commands.database.exceptions import ( DatabaseNotFoundError, NoValidatorConfigFoundError, NoValidatorFoundError, @@ -31,6 +30,7 @@ from superset.databases.commands.exceptions import ( ValidatorSQLError, ValidatorSQLUnexpectedError, ) +from superset.daos.database import DatabaseDAO from superset.errors import ErrorLevel, SupersetError, SupersetErrorType from superset.models.core import Database from superset.sql_validators import get_validator_by_name diff --git a/superset/datasets/commands/__init__.py b/superset/commands/dataset/__init__.py similarity index 100% rename from superset/datasets/commands/__init__.py rename to superset/commands/dataset/__init__.py diff --git a/superset/datasets/commands/importers/__init__.py b/superset/commands/dataset/columns/__init__.py similarity index 100% rename from superset/datasets/commands/importers/__init__.py rename to superset/commands/dataset/columns/__init__.py diff --git a/superset/datasets/columns/commands/delete.py b/superset/commands/dataset/columns/delete.py similarity index 97% rename from superset/datasets/columns/commands/delete.py rename to superset/commands/dataset/columns/delete.py index 0eaa78b0d..4739c2520 100644 --- a/superset/datasets/columns/commands/delete.py +++ b/superset/commands/dataset/columns/delete.py @@ -19,14 +19,14 @@ from typing import Optional from superset import security_manager from superset.commands.base import BaseCommand -from superset.connectors.sqla.models import TableColumn -from superset.daos.dataset import DatasetColumnDAO, DatasetDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.datasets.columns.commands.exceptions import ( +from superset.commands.dataset.columns.exceptions import ( DatasetColumnDeleteFailedError, DatasetColumnForbiddenError, DatasetColumnNotFoundError, ) +from superset.connectors.sqla.models import TableColumn +from superset.daos.dataset import DatasetColumnDAO, DatasetDAO +from superset.daos.exceptions import DAODeleteFailedError from superset.exceptions import SupersetSecurityException logger = logging.getLogger(__name__) diff --git a/superset/datasets/columns/commands/exceptions.py b/superset/commands/dataset/columns/exceptions.py similarity index 100% rename from superset/datasets/columns/commands/exceptions.py rename to superset/commands/dataset/columns/exceptions.py diff --git a/superset/datasets/commands/create.py b/superset/commands/dataset/create.py similarity index 98% rename from superset/datasets/commands/create.py rename to superset/commands/dataset/create.py index 8f486b0c9..1c354e835 100644 --- a/superset/datasets/commands/create.py +++ b/superset/commands/dataset/create.py @@ -22,15 +22,15 @@ from marshmallow import ValidationError from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand, CreateMixin -from superset.daos.dataset import DatasetDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatabaseNotFoundValidationError, DatasetCreateFailedError, DatasetExistsValidationError, DatasetInvalidError, TableNotFoundValidationError, ) +from superset.daos.dataset import DatasetDAO +from superset.daos.exceptions import DAOCreateFailedError from superset.extensions import db logger = logging.getLogger(__name__) diff --git a/superset/datasets/commands/delete.py b/superset/commands/dataset/delete.py similarity index 97% rename from superset/datasets/commands/delete.py rename to superset/commands/dataset/delete.py index 478267d01..4b7e61ab4 100644 --- a/superset/datasets/commands/delete.py +++ b/superset/commands/dataset/delete.py @@ -19,14 +19,14 @@ from typing import Optional from superset import security_manager from superset.commands.base import BaseCommand -from superset.connectors.sqla.models import SqlaTable -from superset.daos.dataset import DatasetDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetDeleteFailedError, DatasetForbiddenError, DatasetNotFoundError, ) +from superset.connectors.sqla.models import SqlaTable +from superset.daos.dataset import DatasetDAO +from superset.daos.exceptions import DAODeleteFailedError from superset.exceptions import SupersetSecurityException logger = logging.getLogger(__name__) diff --git a/superset/datasets/commands/duplicate.py b/superset/commands/dataset/duplicate.py similarity index 99% rename from superset/datasets/commands/duplicate.py rename to superset/commands/dataset/duplicate.py index 12ae96e0a..0ae47c35b 100644 --- a/superset/datasets/commands/duplicate.py +++ b/superset/commands/dataset/duplicate.py @@ -23,16 +23,16 @@ from marshmallow import ValidationError from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand, CreateMixin -from superset.commands.exceptions import DatasourceTypeInvalidError -from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn -from superset.daos.dataset import DatasetDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetDuplicateFailedError, DatasetExistsValidationError, DatasetInvalidError, DatasetNotFoundError, ) +from superset.commands.exceptions import DatasourceTypeInvalidError +from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn +from superset.daos.dataset import DatasetDAO +from superset.daos.exceptions import DAOCreateFailedError from superset.errors import ErrorLevel, SupersetError, SupersetErrorType from superset.exceptions import SupersetErrorException from superset.extensions import db diff --git a/superset/datasets/commands/exceptions.py b/superset/commands/dataset/exceptions.py similarity index 100% rename from superset/datasets/commands/exceptions.py rename to superset/commands/dataset/exceptions.py diff --git a/superset/datasets/commands/export.py b/superset/commands/dataset/export.py similarity index 98% rename from superset/datasets/commands/export.py rename to superset/commands/dataset/export.py index 392265232..afecdd2fe 100644 --- a/superset/datasets/commands/export.py +++ b/superset/commands/dataset/export.py @@ -25,7 +25,7 @@ import yaml from superset.commands.export.models import ExportModelsCommand from superset.connectors.sqla.models import SqlaTable from superset.daos.database import DatabaseDAO -from superset.datasets.commands.exceptions import DatasetNotFoundError +from superset.commands.dataset.exceptions import DatasetNotFoundError from superset.daos.dataset import DatasetDAO from superset.utils.dict_import_export import EXPORT_VERSION from superset.utils.file import get_filename diff --git a/superset/datasets/metrics/commands/__init__.py b/superset/commands/dataset/importers/__init__.py similarity index 100% rename from superset/datasets/metrics/commands/__init__.py rename to superset/commands/dataset/importers/__init__.py diff --git a/superset/datasets/commands/importers/dispatcher.py b/superset/commands/dataset/importers/dispatcher.py similarity index 97% rename from superset/datasets/commands/importers/dispatcher.py rename to superset/commands/dataset/importers/dispatcher.py index 6be8635da..9138d4f97 100644 --- a/superset/datasets/commands/importers/dispatcher.py +++ b/superset/commands/dataset/importers/dispatcher.py @@ -21,9 +21,9 @@ from typing import Any from marshmallow.exceptions import ValidationError from superset.commands.base import BaseCommand +from superset.commands.dataset.importers import v0, v1 from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError -from superset.datasets.commands.importers import v0, v1 logger = logging.getLogger(__name__) diff --git a/superset/datasets/commands/importers/v0.py b/superset/commands/dataset/importers/v0.py similarity index 98% rename from superset/datasets/commands/importers/v0.py rename to superset/commands/dataset/importers/v0.py index 064726308..d389a1765 100644 --- a/superset/datasets/commands/importers/v0.py +++ b/superset/commands/dataset/importers/v0.py @@ -25,6 +25,8 @@ from sqlalchemy.orm.session import make_transient from superset import db from superset.commands.base import BaseCommand +from superset.commands.database.exceptions import DatabaseNotFoundError +from superset.commands.dataset.exceptions import DatasetInvalidError from superset.commands.importers.exceptions import IncorrectVersionError from superset.connectors.sqla.models import ( BaseDatasource, @@ -32,8 +34,6 @@ from superset.connectors.sqla.models import ( SqlMetric, TableColumn, ) -from superset.databases.commands.exceptions import DatabaseNotFoundError -from superset.datasets.commands.exceptions import DatasetInvalidError from superset.models.core import Database from superset.utils.dict_import_export import DATABASES_KEY diff --git a/superset/datasets/commands/importers/v1/__init__.py b/superset/commands/dataset/importers/v1/__init__.py similarity index 92% rename from superset/datasets/commands/importers/v1/__init__.py rename to superset/commands/dataset/importers/v1/__init__.py index f46c137b7..600a39bf4 100644 --- a/superset/datasets/commands/importers/v1/__init__.py +++ b/superset/commands/dataset/importers/v1/__init__.py @@ -20,12 +20,12 @@ from typing import Any from marshmallow import Schema from sqlalchemy.orm import Session +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.exceptions import DatasetImportError +from superset.commands.dataset.importers.v1.utils import import_dataset from superset.commands.importers.v1 import ImportModelsCommand from superset.daos.dataset import DatasetDAO -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.exceptions import DatasetImportError -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema diff --git a/superset/datasets/commands/importers/v1/utils.py b/superset/commands/dataset/importers/v1/utils.py similarity index 99% rename from superset/datasets/commands/importers/v1/utils.py rename to superset/commands/dataset/importers/v1/utils.py index c45f7a565..c145cc50f 100644 --- a/superset/datasets/commands/importers/v1/utils.py +++ b/superset/commands/dataset/importers/v1/utils.py @@ -29,9 +29,9 @@ from sqlalchemy.orm.exc import MultipleResultsFound from sqlalchemy.sql.visitors import VisitableType from superset import security_manager +from superset.commands.dataset.exceptions import DatasetForbiddenDataURI from superset.commands.exceptions import ImportFailedError from superset.connectors.sqla.models import SqlaTable -from superset.datasets.commands.exceptions import DatasetForbiddenDataURI from superset.models.core import Database logger = logging.getLogger(__name__) diff --git a/superset/embedded_dashboard/commands/__init__.py b/superset/commands/dataset/metrics/__init__.py similarity index 100% rename from superset/embedded_dashboard/commands/__init__.py rename to superset/commands/dataset/metrics/__init__.py diff --git a/superset/datasets/metrics/commands/delete.py b/superset/commands/dataset/metrics/delete.py similarity index 97% rename from superset/datasets/metrics/commands/delete.py rename to superset/commands/dataset/metrics/delete.py index c19aff7aa..b48668852 100644 --- a/superset/datasets/metrics/commands/delete.py +++ b/superset/commands/dataset/metrics/delete.py @@ -19,14 +19,14 @@ from typing import Optional from superset import security_manager from superset.commands.base import BaseCommand -from superset.connectors.sqla.models import SqlMetric -from superset.daos.dataset import DatasetDAO, DatasetMetricDAO -from superset.daos.exceptions import DAODeleteFailedError -from superset.datasets.metrics.commands.exceptions import ( +from superset.commands.dataset.metrics.exceptions import ( DatasetMetricDeleteFailedError, DatasetMetricForbiddenError, DatasetMetricNotFoundError, ) +from superset.connectors.sqla.models import SqlMetric +from superset.daos.dataset import DatasetDAO, DatasetMetricDAO +from superset.daos.exceptions import DAODeleteFailedError from superset.exceptions import SupersetSecurityException logger = logging.getLogger(__name__) diff --git a/superset/datasets/metrics/commands/exceptions.py b/superset/commands/dataset/metrics/exceptions.py similarity index 100% rename from superset/datasets/metrics/commands/exceptions.py rename to superset/commands/dataset/metrics/exceptions.py diff --git a/superset/datasets/commands/refresh.py b/superset/commands/dataset/refresh.py similarity index 97% rename from superset/datasets/commands/refresh.py rename to superset/commands/dataset/refresh.py index a25609636..5976956d7 100644 --- a/superset/datasets/commands/refresh.py +++ b/superset/commands/dataset/refresh.py @@ -21,13 +21,13 @@ from flask_appbuilder.models.sqla import Model from superset import security_manager from superset.commands.base import BaseCommand -from superset.connectors.sqla.models import SqlaTable -from superset.daos.dataset import DatasetDAO -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetForbiddenError, DatasetNotFoundError, DatasetRefreshFailedError, ) +from superset.connectors.sqla.models import SqlaTable +from superset.daos.dataset import DatasetDAO from superset.exceptions import SupersetSecurityException logger = logging.getLogger(__name__) diff --git a/superset/datasets/commands/update.py b/superset/commands/dataset/update.py similarity index 99% rename from superset/datasets/commands/update.py rename to superset/commands/dataset/update.py index 8dcc4dfd5..8a72c24fd 100644 --- a/superset/datasets/commands/update.py +++ b/superset/commands/dataset/update.py @@ -23,10 +23,7 @@ from marshmallow import ValidationError from superset import security_manager from superset.commands.base import BaseCommand, UpdateMixin -from superset.connectors.sqla.models import SqlaTable -from superset.daos.dataset import DatasetDAO -from superset.daos.exceptions import DAOUpdateFailedError -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatabaseChangeValidationError, DatasetColumnNotFoundValidationError, DatasetColumnsDuplicateValidationError, @@ -40,6 +37,9 @@ from superset.datasets.commands.exceptions import ( DatasetNotFoundError, DatasetUpdateFailedError, ) +from superset.connectors.sqla.models import SqlaTable +from superset.daos.dataset import DatasetDAO +from superset.daos.exceptions import DAOUpdateFailedError from superset.exceptions import SupersetSecurityException logger = logging.getLogger(__name__) diff --git a/superset/datasets/commands/warm_up_cache.py b/superset/commands/dataset/warm_up_cache.py similarity index 89% rename from superset/datasets/commands/warm_up_cache.py rename to superset/commands/dataset/warm_up_cache.py index 64becc9cd..97b00c477 100644 --- a/superset/datasets/commands/warm_up_cache.py +++ b/superset/commands/dataset/warm_up_cache.py @@ -18,10 +18,10 @@ from typing import Any, Optional -from superset.charts.commands.warm_up_cache import ChartWarmUpCacheCommand from superset.commands.base import BaseCommand +from superset.commands.chart.warm_up_cache import ChartWarmUpCacheCommand +from superset.commands.dataset.exceptions import WarmUpCacheTableNotFoundError from superset.connectors.sqla.models import SqlaTable -from superset.datasets.commands.exceptions import WarmUpCacheTableNotFoundError from superset.extensions import db from superset.models.core import Database from superset.models.slice import Slice @@ -45,7 +45,9 @@ class DatasetWarmUpCacheCommand(BaseCommand): self.validate() return [ ChartWarmUpCacheCommand( - chart, self._dashboard_id, self._extra_filters + chart, + self._dashboard_id, + self._extra_filters, ).run() for chart in self._charts ] diff --git a/superset/explore/commands/__init__.py b/superset/commands/explore/__init__.py similarity index 100% rename from superset/explore/commands/__init__.py rename to superset/commands/explore/__init__.py diff --git a/superset/explore/form_data/commands/__init__.py b/superset/commands/explore/form_data/__init__.py similarity index 100% rename from superset/explore/form_data/commands/__init__.py rename to superset/commands/explore/form_data/__init__.py diff --git a/superset/explore/form_data/commands/create.py b/superset/commands/explore/form_data/create.py similarity index 91% rename from superset/explore/form_data/commands/create.py rename to superset/commands/explore/form_data/create.py index df0250f2f..e85f84013 100644 --- a/superset/explore/form_data/commands/create.py +++ b/superset/commands/explore/form_data/create.py @@ -20,12 +20,12 @@ from flask import session from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.state import TemporaryExploreState -from superset.explore.form_data.commands.utils import check_access +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.state import TemporaryExploreState +from superset.commands.explore.form_data.utils import check_access +from superset.commands.temporary_cache.exceptions import TemporaryCacheCreateFailedError from superset.extensions import cache_manager from superset.key_value.utils import random_key -from superset.temporary_cache.commands.exceptions import TemporaryCacheCreateFailedError from superset.temporary_cache.utils import cache_key from superset.utils.core import DatasourceType, get_user_id from superset.utils.schema import validate_json diff --git a/superset/explore/form_data/commands/delete.py b/superset/commands/explore/form_data/delete.py similarity index 91% rename from superset/explore/form_data/commands/delete.py rename to superset/commands/explore/form_data/delete.py index bce13b719..d998f132d 100644 --- a/superset/explore/form_data/commands/delete.py +++ b/superset/commands/explore/form_data/delete.py @@ -22,14 +22,14 @@ from flask import session from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.state import TemporaryExploreState -from superset.explore.form_data.commands.utils import check_access -from superset.extensions import cache_manager -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.state import TemporaryExploreState +from superset.commands.explore.form_data.utils import check_access +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheDeleteFailedError, ) +from superset.extensions import cache_manager from superset.temporary_cache.utils import cache_key from superset.utils.core import DatasourceType, get_user_id diff --git a/superset/explore/form_data/commands/get.py b/superset/commands/explore/form_data/get.py similarity index 89% rename from superset/explore/form_data/commands/get.py rename to superset/commands/explore/form_data/get.py index 53fd6ea6a..0153888d4 100644 --- a/superset/explore/form_data/commands/get.py +++ b/superset/commands/explore/form_data/get.py @@ -22,11 +22,11 @@ from flask import current_app as app from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.state import TemporaryExploreState -from superset.explore.form_data.commands.utils import check_access +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.state import TemporaryExploreState +from superset.commands.explore.form_data.utils import check_access +from superset.commands.temporary_cache.exceptions import TemporaryCacheGetFailedError from superset.extensions import cache_manager -from superset.temporary_cache.commands.exceptions import TemporaryCacheGetFailedError from superset.utils.core import DatasourceType logger = logging.getLogger(__name__) diff --git a/superset/explore/form_data/commands/parameters.py b/superset/commands/explore/form_data/parameters.py similarity index 100% rename from superset/explore/form_data/commands/parameters.py rename to superset/commands/explore/form_data/parameters.py diff --git a/superset/explore/form_data/commands/state.py b/superset/commands/explore/form_data/state.py similarity index 100% rename from superset/explore/form_data/commands/state.py rename to superset/commands/explore/form_data/state.py diff --git a/superset/explore/form_data/commands/update.py b/superset/commands/explore/form_data/update.py similarity index 93% rename from superset/explore/form_data/commands/update.py rename to superset/commands/explore/form_data/update.py index ace57350c..fbb6ee071 100644 --- a/superset/explore/form_data/commands/update.py +++ b/superset/commands/explore/form_data/update.py @@ -22,15 +22,15 @@ from flask import session from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.state import TemporaryExploreState -from superset.explore.form_data.commands.utils import check_access -from superset.extensions import cache_manager -from superset.key_value.utils import random_key -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.state import TemporaryExploreState +from superset.commands.explore.form_data.utils import check_access +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheUpdateFailedError, ) +from superset.extensions import cache_manager +from superset.key_value.utils import random_key from superset.temporary_cache.utils import cache_key from superset.utils.core import DatasourceType, get_user_id from superset.utils.schema import validate_json diff --git a/superset/explore/form_data/commands/utils.py b/superset/commands/explore/form_data/utils.py similarity index 90% rename from superset/explore/form_data/commands/utils.py rename to superset/commands/explore/form_data/utils.py index e4a843dc6..45b46fb8b 100644 --- a/superset/explore/form_data/commands/utils.py +++ b/superset/commands/explore/form_data/utils.py @@ -16,19 +16,19 @@ # under the License. from typing import Optional -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( ChartAccessDeniedError, ChartNotFoundError, ) -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetAccessDeniedError, DatasetNotFoundError, ) -from superset.explore.utils import check_access as explore_check_access -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheResourceNotFoundError, ) +from superset.explore.utils import check_access as explore_check_access from superset.utils.core import DatasourceType diff --git a/superset/explore/commands/get.py b/superset/commands/explore/get.py similarity index 96% rename from superset/explore/commands/get.py rename to superset/commands/explore/get.py index 1994e7ad4..bb8f5a85e 100644 --- a/superset/explore/commands/get.py +++ b/superset/commands/explore/get.py @@ -26,17 +26,17 @@ from sqlalchemy.exc import SQLAlchemyError from superset import db from superset.commands.base import BaseCommand +from superset.commands.explore.form_data.get import GetFormDataCommand +from superset.commands.explore.form_data.parameters import ( + CommandParameters as FormDataCommandParameters, +) +from superset.commands.explore.parameters import CommandParameters +from superset.commands.explore.permalink.get import GetExplorePermalinkCommand from superset.connectors.sqla.models import BaseDatasource, SqlaTable from superset.daos.datasource import DatasourceDAO from superset.daos.exceptions import DatasourceNotFound from superset.exceptions import SupersetException -from superset.explore.commands.parameters import CommandParameters from superset.explore.exceptions import WrongEndpointError -from superset.explore.form_data.commands.get import GetFormDataCommand -from superset.explore.form_data.commands.parameters import ( - CommandParameters as FormDataCommandParameters, -) -from superset.explore.permalink.commands.get import GetExplorePermalinkCommand from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError from superset.utils import core as utils from superset.views.utils import ( diff --git a/superset/explore/commands/parameters.py b/superset/commands/explore/parameters.py similarity index 100% rename from superset/explore/commands/parameters.py rename to superset/commands/explore/parameters.py diff --git a/superset/explore/permalink/commands/__init__.py b/superset/commands/explore/permalink/__init__.py similarity index 100% rename from superset/explore/permalink/commands/__init__.py rename to superset/commands/explore/permalink/__init__.py diff --git a/superset/explore/permalink/commands/base.py b/superset/commands/explore/permalink/base.py similarity index 100% rename from superset/explore/permalink/commands/base.py rename to superset/commands/explore/permalink/base.py diff --git a/superset/explore/permalink/commands/create.py b/superset/commands/explore/permalink/create.py similarity index 95% rename from superset/explore/permalink/commands/create.py rename to superset/commands/explore/permalink/create.py index 97a8bcbf0..befb1d5a4 100644 --- a/superset/explore/permalink/commands/create.py +++ b/superset/commands/explore/permalink/create.py @@ -19,10 +19,10 @@ from typing import Any, Optional from sqlalchemy.exc import SQLAlchemyError -from superset.explore.permalink.commands.base import BaseExplorePermalinkCommand +from superset.commands.explore.permalink.base import BaseExplorePermalinkCommand +from superset.commands.key_value.create import CreateKeyValueCommand from superset.explore.permalink.exceptions import ExplorePermalinkCreateFailedError from superset.explore.utils import check_access as check_chart_access -from superset.key_value.commands.create import CreateKeyValueCommand from superset.key_value.exceptions import KeyValueCodecEncodeException from superset.key_value.utils import encode_permalink_key from superset.utils.core import DatasourceType diff --git a/superset/explore/permalink/commands/get.py b/superset/commands/explore/permalink/get.py similarity index 93% rename from superset/explore/permalink/commands/get.py rename to superset/commands/explore/permalink/get.py index 1aa093b38..4c01db1cc 100644 --- a/superset/explore/permalink/commands/get.py +++ b/superset/commands/explore/permalink/get.py @@ -19,12 +19,12 @@ from typing import Optional from sqlalchemy.exc import SQLAlchemyError -from superset.datasets.commands.exceptions import DatasetNotFoundError -from superset.explore.permalink.commands.base import BaseExplorePermalinkCommand +from superset.commands.dataset.exceptions import DatasetNotFoundError +from superset.commands.explore.permalink.base import BaseExplorePermalinkCommand +from superset.commands.key_value.get import GetKeyValueCommand from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError from superset.explore.permalink.types import ExplorePermalinkValue from superset.explore.utils import check_access as check_chart_access -from superset.key_value.commands.get import GetKeyValueCommand from superset.key_value.exceptions import ( KeyValueCodecDecodeException, KeyValueGetFailedError, diff --git a/superset/commands/export/assets.py b/superset/commands/export/assets.py index 1bd2cf6d6..61d805aca 100644 --- a/superset/commands/export/assets.py +++ b/superset/commands/export/assets.py @@ -20,12 +20,12 @@ from datetime import datetime, timezone import yaml -from superset.charts.commands.export import ExportChartsCommand from superset.commands.base import BaseCommand -from superset.dashboards.commands.export import ExportDashboardsCommand -from superset.databases.commands.export import ExportDatabasesCommand -from superset.datasets.commands.export import ExportDatasetsCommand -from superset.queries.saved_queries.commands.export import ExportSavedQueriesCommand +from superset.commands.chart.export import ExportChartsCommand +from superset.commands.dashboard.export import ExportDashboardsCommand +from superset.commands.database.export import ExportDatabasesCommand +from superset.commands.dataset.export import ExportDatasetsCommand +from superset.commands.query.export import ExportSavedQueriesCommand from superset.utils.dict_import_export import EXPORT_VERSION METADATA_FILE_NAME = "metadata.yaml" diff --git a/superset/commands/importers/v1/assets.py b/superset/commands/importers/v1/assets.py index 4c8971315..b6bc29e0f 100644 --- a/superset/commands/importers/v1/assets.py +++ b/superset/commands/importers/v1/assets.py @@ -22,29 +22,27 @@ from sqlalchemy.orm import Session from sqlalchemy.sql import delete, insert from superset import db -from superset.charts.commands.importers.v1.utils import import_chart from superset.charts.schemas import ImportV1ChartSchema from superset.commands.base import BaseCommand +from superset.commands.chart.importers.v1.utils import import_chart +from superset.commands.dashboard.importers.v1.utils import ( + find_chart_uuids, + import_dashboard, + update_id_refs, +) +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.importers.v1.utils import import_dataset from superset.commands.exceptions import CommandInvalidError, ImportFailedError from superset.commands.importers.v1.utils import ( load_configs, load_metadata, validate_metadata_type, ) -from superset.dashboards.commands.importers.v1.utils import ( - find_chart_uuids, - import_dashboard, - update_id_refs, -) +from superset.commands.query.importers.v1.utils import import_saved_query from superset.dashboards.schemas import ImportV1DashboardSchema -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.dashboard import dashboard_slices -from superset.queries.saved_queries.commands.importers.v1.utils import ( - import_saved_query, -) from superset.queries.saved_queries.schemas import ImportV1SavedQuerySchema diff --git a/superset/commands/importers/v1/examples.py b/superset/commands/importers/v1/examples.py index 737be25f8..94194921a 100644 --- a/superset/commands/importers/v1/examples.py +++ b/superset/commands/importers/v1/examples.py @@ -22,24 +22,24 @@ from sqlalchemy.orm.exc import MultipleResultsFound from sqlalchemy.sql import select from superset import db -from superset.charts.commands.importers.v1 import ImportChartsCommand -from superset.charts.commands.importers.v1.utils import import_chart from superset.charts.schemas import ImportV1ChartSchema -from superset.commands.exceptions import CommandException -from superset.commands.importers.v1 import ImportModelsCommand -from superset.daos.base import BaseDAO -from superset.dashboards.commands.importers.v1 import ImportDashboardsCommand -from superset.dashboards.commands.importers.v1.utils import ( +from superset.commands.chart.importers.v1 import ImportChartsCommand +from superset.commands.chart.importers.v1.utils import import_chart +from superset.commands.dashboard.importers.v1 import ImportDashboardsCommand +from superset.commands.dashboard.importers.v1.utils import ( find_chart_uuids, import_dashboard, update_id_refs, ) +from superset.commands.database.importers.v1 import ImportDatabasesCommand +from superset.commands.database.importers.v1.utils import import_database +from superset.commands.dataset.importers.v1 import ImportDatasetsCommand +from superset.commands.dataset.importers.v1.utils import import_dataset +from superset.commands.exceptions import CommandException +from superset.commands.importers.v1 import ImportModelsCommand +from superset.daos.base import BaseDAO from superset.dashboards.schemas import ImportV1DashboardSchema -from superset.databases.commands.importers.v1 import ImportDatabasesCommand -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.datasets.commands.importers.v1 import ImportDatasetsCommand -from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.dashboard import dashboard_slices from superset.utils.core import get_example_default_schema diff --git a/superset/key_value/commands/__init__.py b/superset/commands/key_value/__init__.py similarity index 100% rename from superset/key_value/commands/__init__.py rename to superset/commands/key_value/__init__.py diff --git a/superset/key_value/commands/create.py b/superset/commands/key_value/create.py similarity index 100% rename from superset/key_value/commands/create.py rename to superset/commands/key_value/create.py diff --git a/superset/key_value/commands/delete.py b/superset/commands/key_value/delete.py similarity index 100% rename from superset/key_value/commands/delete.py rename to superset/commands/key_value/delete.py diff --git a/superset/key_value/commands/delete_expired.py b/superset/commands/key_value/delete_expired.py similarity index 100% rename from superset/key_value/commands/delete_expired.py rename to superset/commands/key_value/delete_expired.py diff --git a/superset/key_value/commands/get.py b/superset/commands/key_value/get.py similarity index 100% rename from superset/key_value/commands/get.py rename to superset/commands/key_value/get.py diff --git a/superset/key_value/commands/update.py b/superset/commands/key_value/update.py similarity index 100% rename from superset/key_value/commands/update.py rename to superset/commands/key_value/update.py diff --git a/superset/key_value/commands/upsert.py b/superset/commands/key_value/upsert.py similarity index 98% rename from superset/key_value/commands/upsert.py rename to superset/commands/key_value/upsert.py index 66d6785f2..84f02cb9c 100644 --- a/superset/key_value/commands/upsert.py +++ b/superset/commands/key_value/upsert.py @@ -24,7 +24,7 @@ from sqlalchemy.exc import SQLAlchemyError from superset import db from superset.commands.base import BaseCommand -from superset.key_value.commands.create import CreateKeyValueCommand +from superset.commands.key_value.create import CreateKeyValueCommand from superset.key_value.exceptions import ( KeyValueCreateFailedError, KeyValueUpsertFailedError, diff --git a/superset/queries/saved_queries/commands/__init__.py b/superset/commands/query/__init__.py similarity index 100% rename from superset/queries/saved_queries/commands/__init__.py rename to superset/commands/query/__init__.py diff --git a/superset/queries/saved_queries/commands/delete.py b/superset/commands/query/delete.py similarity index 96% rename from superset/queries/saved_queries/commands/delete.py rename to superset/commands/query/delete.py index 40b73658e..978f30c5c 100644 --- a/superset/queries/saved_queries/commands/delete.py +++ b/superset/commands/query/delete.py @@ -18,13 +18,13 @@ import logging from typing import Optional from superset.commands.base import BaseCommand -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.query import SavedQueryDAO -from superset.models.dashboard import Dashboard -from superset.queries.saved_queries.commands.exceptions import ( +from superset.commands.query.exceptions import ( SavedQueryDeleteFailedError, SavedQueryNotFoundError, ) +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.query import SavedQueryDAO +from superset.models.dashboard import Dashboard logger = logging.getLogger(__name__) diff --git a/superset/queries/saved_queries/commands/exceptions.py b/superset/commands/query/exceptions.py similarity index 100% rename from superset/queries/saved_queries/commands/exceptions.py rename to superset/commands/query/exceptions.py diff --git a/superset/queries/saved_queries/commands/export.py b/superset/commands/query/export.py similarity index 97% rename from superset/queries/saved_queries/commands/export.py rename to superset/commands/query/export.py index 1b85cda79..a8fa8acbf 100644 --- a/superset/queries/saved_queries/commands/export.py +++ b/superset/commands/query/export.py @@ -25,7 +25,7 @@ from werkzeug.utils import secure_filename from superset.commands.export.models import ExportModelsCommand from superset.models.sql_lab import SavedQuery -from superset.queries.saved_queries.commands.exceptions import SavedQueryNotFoundError +from superset.commands.query.exceptions import SavedQueryNotFoundError from superset.daos.query import SavedQueryDAO from superset.utils.dict_import_export import EXPORT_VERSION diff --git a/superset/queries/saved_queries/commands/importers/__init__.py b/superset/commands/query/importers/__init__.py similarity index 100% rename from superset/queries/saved_queries/commands/importers/__init__.py rename to superset/commands/query/importers/__init__.py diff --git a/superset/queries/saved_queries/commands/importers/dispatcher.py b/superset/commands/query/importers/dispatcher.py similarity index 97% rename from superset/queries/saved_queries/commands/importers/dispatcher.py rename to superset/commands/query/importers/dispatcher.py index c2208f0e2..438ea8351 100644 --- a/superset/queries/saved_queries/commands/importers/dispatcher.py +++ b/superset/commands/query/importers/dispatcher.py @@ -23,7 +23,7 @@ from marshmallow.exceptions import ValidationError from superset.commands.base import BaseCommand from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError -from superset.queries.saved_queries.commands.importers import v1 +from superset.commands.query.importers import v1 logger = logging.getLogger(__name__) diff --git a/superset/queries/saved_queries/commands/importers/v1/__init__.py b/superset/commands/query/importers/v1/__init__.py similarity index 91% rename from superset/queries/saved_queries/commands/importers/v1/__init__.py rename to superset/commands/query/importers/v1/__init__.py index c8a159c7f..fa1f21b6f 100644 --- a/superset/queries/saved_queries/commands/importers/v1/__init__.py +++ b/superset/commands/query/importers/v1/__init__.py @@ -20,15 +20,13 @@ from typing import Any from marshmallow import Schema from sqlalchemy.orm import Session +from superset.commands.database.importers.v1.utils import import_database from superset.commands.importers.v1 import ImportModelsCommand +from superset.commands.query.exceptions import SavedQueryImportError +from superset.commands.query.importers.v1.utils import import_saved_query from superset.connectors.sqla.models import SqlaTable from superset.daos.query import SavedQueryDAO -from superset.databases.commands.importers.v1.utils import import_database from superset.databases.schemas import ImportV1DatabaseSchema -from superset.queries.saved_queries.commands.exceptions import SavedQueryImportError -from superset.queries.saved_queries.commands.importers.v1.utils import ( - import_saved_query, -) from superset.queries.saved_queries.schemas import ImportV1SavedQuerySchema diff --git a/superset/queries/saved_queries/commands/importers/v1/utils.py b/superset/commands/query/importers/v1/utils.py similarity index 100% rename from superset/queries/saved_queries/commands/importers/v1/utils.py rename to superset/commands/query/importers/v1/utils.py diff --git a/superset/reports/commands/__init__.py b/superset/commands/report/__init__.py similarity index 100% rename from superset/reports/commands/__init__.py rename to superset/commands/report/__init__.py diff --git a/superset/reports/commands/alert.py b/superset/commands/report/alert.py similarity index 99% rename from superset/reports/commands/alert.py rename to superset/commands/report/alert.py index 2c36d3589..68013a2c0 100644 --- a/superset/reports/commands/alert.py +++ b/superset/commands/report/alert.py @@ -29,7 +29,7 @@ from flask_babel import lazy_gettext as _ from superset import app, jinja_context, security_manager from superset.commands.base import BaseCommand -from superset.reports.commands.exceptions import ( +from superset.commands.report.exceptions import ( AlertQueryError, AlertQueryInvalidTypeError, AlertQueryMultipleColumnsError, diff --git a/superset/reports/commands/base.py b/superset/commands/report/base.py similarity index 98% rename from superset/reports/commands/base.py rename to superset/commands/report/base.py index da871ef17..3b2f28081 100644 --- a/superset/reports/commands/base.py +++ b/superset/commands/report/base.py @@ -20,9 +20,7 @@ from typing import Any from marshmallow import ValidationError from superset.commands.base import BaseCommand -from superset.daos.chart import ChartDAO -from superset.daos.dashboard import DashboardDAO -from superset.reports.commands.exceptions import ( +from superset.commands.report.exceptions import ( ChartNotFoundValidationError, ChartNotSavedValidationError, DashboardNotFoundValidationError, @@ -30,6 +28,8 @@ from superset.reports.commands.exceptions import ( ReportScheduleEitherChartOrDashboardError, ReportScheduleOnlyChartOrDashboardError, ) +from superset.daos.chart import ChartDAO +from superset.daos.dashboard import DashboardDAO from superset.reports.models import ReportCreationMethod logger = logging.getLogger(__name__) diff --git a/superset/reports/commands/create.py b/superset/commands/report/create.py similarity index 97% rename from superset/reports/commands/create.py rename to superset/commands/report/create.py index 177e01c33..aa9bfefc6 100644 --- a/superset/reports/commands/create.py +++ b/superset/commands/report/create.py @@ -22,11 +22,8 @@ from flask_babel import gettext as _ from marshmallow import ValidationError from superset.commands.base import CreateMixin -from superset.daos.database import DatabaseDAO -from superset.daos.exceptions import DAOCreateFailedError -from superset.daos.report import ReportScheduleDAO -from superset.reports.commands.base import BaseReportScheduleCommand -from superset.reports.commands.exceptions import ( +from superset.commands.report.base import BaseReportScheduleCommand +from superset.commands.report.exceptions import ( DatabaseNotFoundValidationError, ReportScheduleAlertRequiredDatabaseValidationError, ReportScheduleCreateFailedError, @@ -35,6 +32,9 @@ from superset.reports.commands.exceptions import ( ReportScheduleNameUniquenessValidationError, ReportScheduleRequiredTypeValidationError, ) +from superset.daos.database import DatabaseDAO +from superset.daos.exceptions import DAOCreateFailedError +from superset.daos.report import ReportScheduleDAO from superset.reports.models import ( ReportCreationMethod, ReportSchedule, diff --git a/superset/reports/commands/delete.py b/superset/commands/report/delete.py similarity index 97% rename from superset/reports/commands/delete.py rename to superset/commands/report/delete.py index 2cdac17c4..87ea4b99d 100644 --- a/superset/reports/commands/delete.py +++ b/superset/commands/report/delete.py @@ -19,14 +19,14 @@ from typing import Optional from superset import security_manager from superset.commands.base import BaseCommand -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.report import ReportScheduleDAO -from superset.exceptions import SupersetSecurityException -from superset.reports.commands.exceptions import ( +from superset.commands.report.exceptions import ( ReportScheduleDeleteFailedError, ReportScheduleForbiddenError, ReportScheduleNotFoundError, ) +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.report import ReportScheduleDAO +from superset.exceptions import SupersetSecurityException from superset.reports.models import ReportSchedule logger = logging.getLogger(__name__) diff --git a/superset/reports/commands/exceptions.py b/superset/commands/report/exceptions.py similarity index 100% rename from superset/reports/commands/exceptions.py rename to superset/commands/report/exceptions.py diff --git a/superset/reports/commands/execute.py b/superset/commands/report/execute.py similarity index 99% rename from superset/reports/commands/execute.py rename to superset/commands/report/execute.py index 7cd8203a5..d4b53e30d 100644 --- a/superset/reports/commands/execute.py +++ b/superset/commands/report/execute.py @@ -26,20 +26,10 @@ from sqlalchemy.orm import Session from superset import app, security_manager from superset.commands.base import BaseCommand +from superset.commands.dashboard.permalink.create import CreateDashboardPermalinkCommand from superset.commands.exceptions import CommandException -from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType -from superset.daos.report import ( - REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER, - ReportScheduleDAO, -) -from superset.dashboards.permalink.commands.create import ( - CreateDashboardPermalinkCommand, -) -from superset.errors import ErrorLevel, SupersetError, SupersetErrorType -from superset.exceptions import SupersetErrorsException, SupersetException -from superset.extensions import feature_flag_manager, machine_auth_provider_factory -from superset.reports.commands.alert import AlertCommand -from superset.reports.commands.exceptions import ( +from superset.commands.report.alert import AlertCommand +from superset.commands.report.exceptions import ( ReportScheduleAlertGracePeriodError, ReportScheduleClientErrorsException, ReportScheduleCsvFailedError, @@ -56,6 +46,14 @@ from superset.reports.commands.exceptions import ( ReportScheduleUnexpectedError, ReportScheduleWorkingTimeoutError, ) +from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType +from superset.daos.report import ( + REPORT_SCHEDULE_ERROR_NOTIFICATION_MARKER, + ReportScheduleDAO, +) +from superset.errors import ErrorLevel, SupersetError, SupersetErrorType +from superset.exceptions import SupersetErrorsException, SupersetException +from superset.extensions import feature_flag_manager, machine_auth_provider_factory from superset.reports.models import ( ReportDataFormat, ReportExecutionLog, diff --git a/superset/reports/commands/log_prune.py b/superset/commands/report/log_prune.py similarity index 96% rename from superset/reports/commands/log_prune.py rename to superset/commands/report/log_prune.py index 09d999541..3a9883c9f 100644 --- a/superset/reports/commands/log_prune.py +++ b/superset/commands/report/log_prune.py @@ -18,9 +18,9 @@ import logging from datetime import datetime, timedelta from superset.commands.base import BaseCommand +from superset.commands.report.exceptions import ReportSchedulePruneLogError from superset.daos.exceptions import DAODeleteFailedError from superset.daos.report import ReportScheduleDAO -from superset.reports.commands.exceptions import ReportSchedulePruneLogError from superset.reports.models import ReportSchedule from superset.utils.celery import session_scope diff --git a/superset/reports/commands/update.py b/superset/commands/report/update.py similarity index 97% rename from superset/reports/commands/update.py rename to superset/commands/report/update.py index 7c3351e5e..a33ba6b59 100644 --- a/superset/reports/commands/update.py +++ b/superset/commands/report/update.py @@ -23,12 +23,8 @@ from marshmallow import ValidationError from superset import security_manager from superset.commands.base import UpdateMixin -from superset.daos.database import DatabaseDAO -from superset.daos.exceptions import DAOUpdateFailedError -from superset.daos.report import ReportScheduleDAO -from superset.exceptions import SupersetSecurityException -from superset.reports.commands.base import BaseReportScheduleCommand -from superset.reports.commands.exceptions import ( +from superset.commands.report.base import BaseReportScheduleCommand +from superset.commands.report.exceptions import ( DatabaseNotFoundValidationError, ReportScheduleForbiddenError, ReportScheduleInvalidError, @@ -36,6 +32,10 @@ from superset.reports.commands.exceptions import ( ReportScheduleNotFoundError, ReportScheduleUpdateFailedError, ) +from superset.daos.database import DatabaseDAO +from superset.daos.exceptions import DAOUpdateFailedError +from superset.daos.report import ReportScheduleDAO +from superset.exceptions import SupersetSecurityException from superset.reports.models import ReportSchedule, ReportScheduleType, ReportState logger = logging.getLogger(__name__) diff --git a/superset/row_level_security/commands/__init__.py b/superset/commands/security/__init__.py similarity index 100% rename from superset/row_level_security/commands/__init__.py rename to superset/commands/security/__init__.py diff --git a/superset/row_level_security/commands/create.py b/superset/commands/security/create.py similarity index 100% rename from superset/row_level_security/commands/create.py rename to superset/commands/security/create.py diff --git a/superset/row_level_security/commands/delete.py b/superset/commands/security/delete.py similarity index 96% rename from superset/row_level_security/commands/delete.py rename to superset/commands/security/delete.py index d669f7d90..2c19c5f89 100644 --- a/superset/row_level_security/commands/delete.py +++ b/superset/commands/security/delete.py @@ -18,13 +18,13 @@ import logging from superset.commands.base import BaseCommand -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.security import RLSDAO -from superset.reports.models import ReportSchedule -from superset.row_level_security.commands.exceptions import ( +from superset.commands.security.exceptions import ( RLSRuleNotFoundError, RuleDeleteFailedError, ) +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.security import RLSDAO +from superset.reports.models import ReportSchedule logger = logging.getLogger(__name__) diff --git a/superset/row_level_security/commands/exceptions.py b/superset/commands/security/exceptions.py similarity index 100% rename from superset/row_level_security/commands/exceptions.py rename to superset/commands/security/exceptions.py diff --git a/superset/row_level_security/commands/update.py b/superset/commands/security/update.py similarity index 96% rename from superset/row_level_security/commands/update.py rename to superset/commands/security/update.py index bc5ef368b..f3a6cea60 100644 --- a/superset/row_level_security/commands/update.py +++ b/superset/commands/security/update.py @@ -21,12 +21,12 @@ from typing import Any, Optional from superset.commands.base import BaseCommand from superset.commands.exceptions import DatasourceNotFoundValidationError +from superset.commands.security.exceptions import RLSRuleNotFoundError from superset.commands.utils import populate_roles from superset.connectors.sqla.models import RowLevelSecurityFilter, SqlaTable from superset.daos.exceptions import DAOUpdateFailedError from superset.daos.security import RLSDAO from superset.extensions import db -from superset.row_level_security.commands.exceptions import RLSRuleNotFoundError logger = logging.getLogger(__name__) diff --git a/superset/sqllab/commands/__init__.py b/superset/commands/sql_lab/__init__.py similarity index 100% rename from superset/sqllab/commands/__init__.py rename to superset/commands/sql_lab/__init__.py diff --git a/superset/sqllab/commands/estimate.py b/superset/commands/sql_lab/estimate.py similarity index 100% rename from superset/sqllab/commands/estimate.py rename to superset/commands/sql_lab/estimate.py diff --git a/superset/sqllab/commands/execute.py b/superset/commands/sql_lab/execute.py similarity index 100% rename from superset/sqllab/commands/execute.py rename to superset/commands/sql_lab/execute.py diff --git a/superset/sqllab/commands/export.py b/superset/commands/sql_lab/export.py similarity index 100% rename from superset/sqllab/commands/export.py rename to superset/commands/sql_lab/export.py diff --git a/superset/sqllab/commands/results.py b/superset/commands/sql_lab/results.py similarity index 100% rename from superset/sqllab/commands/results.py rename to superset/commands/sql_lab/results.py diff --git a/superset/tags/commands/__init__.py b/superset/commands/tag/__init__.py similarity index 100% rename from superset/tags/commands/__init__.py rename to superset/commands/tag/__init__.py diff --git a/superset/tags/commands/create.py b/superset/commands/tag/create.py similarity index 96% rename from superset/tags/commands/create.py rename to superset/commands/tag/create.py index eb3d4458a..ea23b8d59 100644 --- a/superset/tags/commands/create.py +++ b/superset/commands/tag/create.py @@ -19,11 +19,11 @@ from typing import Any from superset import db, security_manager from superset.commands.base import BaseCommand, CreateMixin +from superset.commands.tag.exceptions import TagCreateFailedError, TagInvalidError +from superset.commands.tag.utils import to_object_model, to_object_type from superset.daos.exceptions import DAOCreateFailedError from superset.daos.tag import TagDAO from superset.exceptions import SupersetSecurityException -from superset.tags.commands.exceptions import TagCreateFailedError, TagInvalidError -from superset.tags.commands.utils import to_object_model, to_object_type from superset.tags.models import ObjectType, TagType logger = logging.getLogger(__name__) diff --git a/superset/tags/commands/delete.py b/superset/commands/tag/delete.py similarity index 97% rename from superset/tags/commands/delete.py rename to superset/commands/tag/delete.py index 5c10a934e..c4f223900 100644 --- a/superset/tags/commands/delete.py +++ b/superset/commands/tag/delete.py @@ -17,16 +17,16 @@ import logging from superset.commands.base import BaseCommand -from superset.daos.exceptions import DAODeleteFailedError -from superset.daos.tag import TagDAO -from superset.tags.commands.exceptions import ( +from superset.commands.tag.exceptions import ( TagDeleteFailedError, TaggedObjectDeleteFailedError, TaggedObjectNotFoundError, TagInvalidError, TagNotFoundError, ) -from superset.tags.commands.utils import to_object_type +from superset.commands.tag.utils import to_object_type +from superset.daos.exceptions import DAODeleteFailedError +from superset.daos.tag import TagDAO from superset.tags.models import ObjectType from superset.views.base import DeleteMixin diff --git a/superset/tags/commands/exceptions.py b/superset/commands/tag/exceptions.py similarity index 100% rename from superset/tags/commands/exceptions.py rename to superset/commands/tag/exceptions.py diff --git a/superset/tags/commands/update.py b/superset/commands/tag/update.py similarity index 94% rename from superset/tags/commands/update.py rename to superset/commands/tag/update.py index 182376438..431bf93c4 100644 --- a/superset/tags/commands/update.py +++ b/superset/commands/tag/update.py @@ -21,9 +21,9 @@ from flask_appbuilder.models.sqla import Model from superset import db from superset.commands.base import BaseCommand, UpdateMixin +from superset.commands.tag.exceptions import TagInvalidError, TagNotFoundError +from superset.commands.tag.utils import to_object_type from superset.daos.tag import TagDAO -from superset.tags.commands.exceptions import TagInvalidError, TagNotFoundError -from superset.tags.commands.utils import to_object_type from superset.tags.models import Tag logger = logging.getLogger(__name__) diff --git a/superset/tags/commands/utils.py b/superset/commands/tag/utils.py similarity index 100% rename from superset/tags/commands/utils.py rename to superset/commands/tag/utils.py diff --git a/superset/temporary_cache/commands/__init__.py b/superset/commands/temporary_cache/__init__.py similarity index 100% rename from superset/temporary_cache/commands/__init__.py rename to superset/commands/temporary_cache/__init__.py diff --git a/superset/temporary_cache/commands/create.py b/superset/commands/temporary_cache/create.py similarity index 92% rename from superset/temporary_cache/commands/create.py rename to superset/commands/temporary_cache/create.py index af3b5350f..e43d48e54 100644 --- a/superset/temporary_cache/commands/create.py +++ b/superset/commands/temporary_cache/create.py @@ -20,8 +20,8 @@ from abc import ABC, abstractmethod from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.temporary_cache.commands.exceptions import TemporaryCacheCreateFailedError -from superset.temporary_cache.commands.parameters import CommandParameters +from superset.commands.temporary_cache.exceptions import TemporaryCacheCreateFailedError +from superset.commands.temporary_cache.parameters import CommandParameters logger = logging.getLogger(__name__) diff --git a/superset/temporary_cache/commands/delete.py b/superset/commands/temporary_cache/delete.py similarity index 92% rename from superset/temporary_cache/commands/delete.py rename to superset/commands/temporary_cache/delete.py index 1281c8deb..d35b184d8 100644 --- a/superset/temporary_cache/commands/delete.py +++ b/superset/commands/temporary_cache/delete.py @@ -20,8 +20,8 @@ from abc import ABC, abstractmethod from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.temporary_cache.commands.exceptions import TemporaryCacheDeleteFailedError -from superset.temporary_cache.commands.parameters import CommandParameters +from superset.commands.temporary_cache.exceptions import TemporaryCacheDeleteFailedError +from superset.commands.temporary_cache.parameters import CommandParameters logger = logging.getLogger(__name__) diff --git a/superset/temporary_cache/commands/entry.py b/superset/commands/temporary_cache/entry.py similarity index 100% rename from superset/temporary_cache/commands/entry.py rename to superset/commands/temporary_cache/entry.py diff --git a/superset/temporary_cache/commands/exceptions.py b/superset/commands/temporary_cache/exceptions.py similarity index 100% rename from superset/temporary_cache/commands/exceptions.py rename to superset/commands/temporary_cache/exceptions.py diff --git a/superset/temporary_cache/commands/get.py b/superset/commands/temporary_cache/get.py similarity index 92% rename from superset/temporary_cache/commands/get.py rename to superset/commands/temporary_cache/get.py index 8c220b9c0..fa16977a8 100644 --- a/superset/temporary_cache/commands/get.py +++ b/superset/commands/temporary_cache/get.py @@ -21,8 +21,8 @@ from typing import Optional from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.temporary_cache.commands.exceptions import TemporaryCacheGetFailedError -from superset.temporary_cache.commands.parameters import CommandParameters +from superset.commands.temporary_cache.exceptions import TemporaryCacheGetFailedError +from superset.commands.temporary_cache.parameters import CommandParameters logger = logging.getLogger(__name__) diff --git a/superset/temporary_cache/commands/parameters.py b/superset/commands/temporary_cache/parameters.py similarity index 100% rename from superset/temporary_cache/commands/parameters.py rename to superset/commands/temporary_cache/parameters.py diff --git a/superset/temporary_cache/commands/update.py b/superset/commands/temporary_cache/update.py similarity index 92% rename from superset/temporary_cache/commands/update.py rename to superset/commands/temporary_cache/update.py index 92af8c14f..90b1c3d48 100644 --- a/superset/temporary_cache/commands/update.py +++ b/superset/commands/temporary_cache/update.py @@ -21,8 +21,8 @@ from typing import Optional from sqlalchemy.exc import SQLAlchemyError from superset.commands.base import BaseCommand -from superset.temporary_cache.commands.exceptions import TemporaryCacheUpdateFailedError -from superset.temporary_cache.commands.parameters import CommandParameters +from superset.commands.temporary_cache.exceptions import TemporaryCacheUpdateFailedError +from superset.commands.temporary_cache.parameters import CommandParameters logger = logging.getLogger(__name__) diff --git a/superset/common/query_context_processor.py b/superset/common/query_context_processor.py index 7967313cd..5b1414d53 100644 --- a/superset/common/query_context_processor.py +++ b/superset/common/query_context_processor.py @@ -38,7 +38,7 @@ from superset.common.utils.time_range_utils import ( ) from superset.connectors.sqla.models import BaseDatasource from superset.constants import CacheRegion, TimeGrain -from superset.daos.annotation import AnnotationLayerDAO +from superset.daos.annotation_layer import AnnotationLayerDAO from superset.daos.chart import ChartDAO from superset.exceptions import ( InvalidPostProcessingError, @@ -682,7 +682,7 @@ class QueryContextProcessor: annotation_layer: dict[str, Any], force: bool ) -> dict[str, Any]: # pylint: disable=import-outside-toplevel - from superset.charts.data.commands.get_data_command import ChartDataCommand + from superset.commands.chart.data.get_data_command import ChartDataCommand if not (chart := ChartDAO.find_by_id(annotation_layer["value"])): raise QueryObjectValidationError(_("The chart does not exist")) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 3d1435dc7..598bc6741 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -75,6 +75,7 @@ from sqlalchemy.sql.expression import Label, TextAsFrom from sqlalchemy.sql.selectable import Alias, TableClause from superset import app, db, is_feature_enabled, security_manager +from superset.commands.dataset.exceptions import DatasetNotFoundError from superset.common.db_query_status import QueryStatus from superset.connectors.sqla.utils import ( get_columns_description, @@ -82,7 +83,6 @@ from superset.connectors.sqla.utils import ( get_virtual_table_metadata, ) from superset.constants import EMPTY_STRING, NULL_STRING -from superset.datasets.commands.exceptions import DatasetNotFoundError from superset.db_engine_specs.base import BaseEngineSpec, TimestampExpression from superset.exceptions import ( ColumnNotFoundException, diff --git a/superset/css_templates/api.py b/superset/css_templates/api.py index ee5d5fac7..25f4d50f3 100644 --- a/superset/css_templates/api.py +++ b/superset/css_templates/api.py @@ -22,12 +22,12 @@ from flask_appbuilder.api import expose, protect, rison, safe from flask_appbuilder.models.sqla.interface import SQLAInterface from flask_babel import ngettext -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.css_templates.commands.delete import DeleteCssTemplateCommand -from superset.css_templates.commands.exceptions import ( +from superset.commands.css.delete import DeleteCssTemplateCommand +from superset.commands.css.exceptions import ( CssTemplateDeleteFailedError, CssTemplateNotFoundError, ) +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.css_templates.filters import CssTemplateAllTextFilter from superset.css_templates.schemas import ( get_delete_ids_schema, diff --git a/superset/daos/annotation.py b/superset/daos/annotation_layer.py similarity index 100% rename from superset/daos/annotation.py rename to superset/daos/annotation_layer.py diff --git a/superset/daos/dashboard.py b/superset/daos/dashboard.py index 77f2dd9f3..b98252070 100644 --- a/superset/daos/dashboard.py +++ b/superset/daos/dashboard.py @@ -25,12 +25,12 @@ from flask import g from flask_appbuilder.models.sqla.interface import SQLAInterface from superset import is_feature_enabled, security_manager -from superset.daos.base import BaseDAO -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardAccessDeniedError, DashboardForbiddenError, DashboardNotFoundError, ) +from superset.daos.base import BaseDAO from superset.dashboards.filter_sets.consts import ( DASHBOARD_ID_FIELD, DESCRIPTION_FIELD, diff --git a/superset/daos/tag.py b/superset/daos/tag.py index ba5311ed4..fbc9aa229 100644 --- a/superset/daos/tag.py +++ b/superset/daos/tag.py @@ -21,6 +21,8 @@ from typing import Any, Optional from flask import g from sqlalchemy.exc import SQLAlchemyError +from superset.commands.tag.exceptions import TagNotFoundError +from superset.commands.tag.utils import to_object_type from superset.daos.base import BaseDAO from superset.daos.exceptions import DAOCreateFailedError, DAODeleteFailedError from superset.exceptions import MissingUserContextException @@ -28,8 +30,6 @@ from superset.extensions import db from superset.models.dashboard import Dashboard from superset.models.slice import Slice from superset.models.sql_lab import SavedQuery -from superset.tags.commands.exceptions import TagNotFoundError -from superset.tags.commands.utils import to_object_type from superset.tags.models import ( get_tag, ObjectType, @@ -409,7 +409,9 @@ class TagDAO(BaseDAO[Tag]): for object_type, object_id in tagged_objects_to_delete: # delete objects that were removed TagDAO.delete_tagged_object( - object_type, object_id, tag.name # type: ignore + object_type, # type: ignore + object_id, + tag.name, ) db.session.add_all(tagged_objects) diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py index b6ba689d8..be773b83c 100644 --- a/superset/dashboards/api.py +++ b/superset/dashboards/api.py @@ -35,13 +35,9 @@ from werkzeug.wsgi import FileWrapper from superset import is_feature_enabled, thumbnail_cache from superset.charts.schemas import ChartEntityResponseSchema -from superset.commands.importers.exceptions import NoValidFilesFoundError -from superset.commands.importers.v1.utils import get_contents_from_bundle -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.daos.dashboard import DashboardDAO, EmbeddedDashboardDAO -from superset.dashboards.commands.create import CreateDashboardCommand -from superset.dashboards.commands.delete import DeleteDashboardCommand -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.create import CreateDashboardCommand +from superset.commands.dashboard.delete import DeleteDashboardCommand +from superset.commands.dashboard.exceptions import ( DashboardAccessDeniedError, DashboardCreateFailedError, DashboardDeleteFailedError, @@ -50,9 +46,13 @@ from superset.dashboards.commands.exceptions import ( DashboardNotFoundError, DashboardUpdateFailedError, ) -from superset.dashboards.commands.export import ExportDashboardsCommand -from superset.dashboards.commands.importers.dispatcher import ImportDashboardsCommand -from superset.dashboards.commands.update import UpdateDashboardCommand +from superset.commands.dashboard.export import ExportDashboardsCommand +from superset.commands.dashboard.importers.dispatcher import ImportDashboardsCommand +from superset.commands.dashboard.update import UpdateDashboardCommand +from superset.commands.importers.exceptions import NoValidFilesFoundError +from superset.commands.importers.v1.utils import get_contents_from_bundle +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.daos.dashboard import DashboardDAO, EmbeddedDashboardDAO from superset.dashboards.filters import ( DashboardAccessFilter, DashboardCertifiedFilter, diff --git a/superset/dashboards/filter_sets/api.py b/superset/dashboards/filter_sets/api.py index 5a2bf0192..ee7297ef4 100644 --- a/superset/dashboards/filter_sets/api.py +++ b/superset/dashboards/filter_sets/api.py @@ -29,12 +29,10 @@ from flask_appbuilder.api import ( from flask_appbuilder.models.sqla.interface import SQLAInterface from marshmallow import ValidationError -from superset.commands.exceptions import ObjectNotFoundError -from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.filter_sets.commands.create import CreateFilterSetCommand -from superset.dashboards.filter_sets.commands.delete import DeleteFilterSetCommand -from superset.dashboards.filter_sets.commands.exceptions import ( +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.filter_set.create import CreateFilterSetCommand +from superset.commands.dashboard.filter_set.delete import DeleteFilterSetCommand +from superset.commands.dashboard.filter_set.exceptions import ( FilterSetCreateFailedError, FilterSetDeleteFailedError, FilterSetForbiddenError, @@ -42,7 +40,9 @@ from superset.dashboards.filter_sets.commands.exceptions import ( FilterSetUpdateFailedError, UserIsNotDashboardOwnerError, ) -from superset.dashboards.filter_sets.commands.update import UpdateFilterSetCommand +from superset.commands.dashboard.filter_set.update import UpdateFilterSetCommand +from superset.commands.exceptions import ObjectNotFoundError +from superset.daos.dashboard import DashboardDAO from superset.dashboards.filter_sets.consts import ( DASHBOARD_FIELD, DASHBOARD_ID_FIELD, diff --git a/superset/dashboards/filter_state/api.py b/superset/dashboards/filter_state/api.py index 9e0720646..d3b6ce8f7 100644 --- a/superset/dashboards/filter_state/api.py +++ b/superset/dashboards/filter_state/api.py @@ -19,10 +19,10 @@ import logging from flask import Response from flask_appbuilder.api import expose, protect, safe -from superset.dashboards.filter_state.commands.create import CreateFilterStateCommand -from superset.dashboards.filter_state.commands.delete import DeleteFilterStateCommand -from superset.dashboards.filter_state.commands.get import GetFilterStateCommand -from superset.dashboards.filter_state.commands.update import UpdateFilterStateCommand +from superset.commands.dashboard.filter_state.create import CreateFilterStateCommand +from superset.commands.dashboard.filter_state.delete import DeleteFilterStateCommand +from superset.commands.dashboard.filter_state.get import GetFilterStateCommand +from superset.commands.dashboard.filter_state.update import UpdateFilterStateCommand from superset.extensions import event_logger from superset.temporary_cache.api import TemporaryCacheRestApi diff --git a/superset/dashboards/permalink/api.py b/superset/dashboards/permalink/api.py index 0a786d1de..a6ae2910f 100644 --- a/superset/dashboards/permalink/api.py +++ b/superset/dashboards/permalink/api.py @@ -20,15 +20,13 @@ from flask import request, Response from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.dashboards.commands.exceptions import ( +from superset.commands.dashboard.exceptions import ( DashboardAccessDeniedError, DashboardNotFoundError, ) -from superset.dashboards.permalink.commands.create import ( - CreateDashboardPermalinkCommand, -) -from superset.dashboards.permalink.commands.get import GetDashboardPermalinkCommand +from superset.commands.dashboard.permalink.create import CreateDashboardPermalinkCommand +from superset.commands.dashboard.permalink.get import GetDashboardPermalinkCommand +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP from superset.dashboards.permalink.exceptions import DashboardPermalinkInvalidStateError from superset.dashboards.permalink.schemas import DashboardPermalinkStateSchema from superset.extensions import event_logger diff --git a/superset/databases/api.py b/superset/databases/api.py index 116e2ddb1..df69d9ccd 100644 --- a/superset/databases/api.py +++ b/superset/databases/api.py @@ -29,16 +29,9 @@ from marshmallow import ValidationError from sqlalchemy.exc import NoSuchTableError, OperationalError, SQLAlchemyError from superset import app, event_logger -from superset.commands.importers.exceptions import ( - IncorrectFormatError, - NoValidFilesFoundError, -) -from superset.commands.importers.v1.utils import get_contents_from_bundle -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.daos.database import DatabaseDAO -from superset.databases.commands.create import CreateDatabaseCommand -from superset.databases.commands.delete import DeleteDatabaseCommand -from superset.databases.commands.exceptions import ( +from superset.commands.database.create import CreateDatabaseCommand +from superset.commands.database.delete import DeleteDatabaseCommand +from superset.commands.database.exceptions import ( DatabaseConnectionFailedError, DatabaseCreateFailedError, DatabaseDeleteDatasetsExistFailedError, @@ -49,13 +42,26 @@ from superset.databases.commands.exceptions import ( DatabaseUpdateFailedError, InvalidParametersError, ) -from superset.databases.commands.export import ExportDatabasesCommand -from superset.databases.commands.importers.dispatcher import ImportDatabasesCommand -from superset.databases.commands.tables import TablesDatabaseCommand -from superset.databases.commands.test_connection import TestConnectionDatabaseCommand -from superset.databases.commands.update import UpdateDatabaseCommand -from superset.databases.commands.validate import ValidateDatabaseParametersCommand -from superset.databases.commands.validate_sql import ValidateSQLCommand +from superset.commands.database.export import ExportDatabasesCommand +from superset.commands.database.importers.dispatcher import ImportDatabasesCommand +from superset.commands.database.ssh_tunnel.delete import DeleteSSHTunnelCommand +from superset.commands.database.ssh_tunnel.exceptions import ( + SSHTunnelDeleteFailedError, + SSHTunnelingNotEnabledError, + SSHTunnelNotFoundError, +) +from superset.commands.database.tables import TablesDatabaseCommand +from superset.commands.database.test_connection import TestConnectionDatabaseCommand +from superset.commands.database.update import UpdateDatabaseCommand +from superset.commands.database.validate import ValidateDatabaseParametersCommand +from superset.commands.database.validate_sql import ValidateSQLCommand +from superset.commands.importers.exceptions import ( + IncorrectFormatError, + NoValidFilesFoundError, +) +from superset.commands.importers.v1.utils import get_contents_from_bundle +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.daos.database import DatabaseDAO from superset.databases.decorators import check_datasource_access from superset.databases.filters import DatabaseFilter, DatabaseUploadEnabledFilter from superset.databases.schemas import ( @@ -79,12 +85,6 @@ from superset.databases.schemas import ( ValidateSQLRequest, ValidateSQLResponse, ) -from superset.databases.ssh_tunnel.commands.delete import DeleteSSHTunnelCommand -from superset.databases.ssh_tunnel.commands.exceptions import ( - SSHTunnelDeleteFailedError, - SSHTunnelingNotEnabledError, - SSHTunnelNotFoundError, -) from superset.databases.utils import get_table_metadata from superset.db_engine_specs import get_available_engine_specs from superset.errors import ErrorLevel, SupersetError, SupersetErrorType diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py index abba9036a..ac4d0e127 100644 --- a/superset/databases/schemas.py +++ b/superset/databases/schemas.py @@ -28,13 +28,13 @@ from marshmallow.validate import Length, ValidationError from sqlalchemy import MetaData from superset import db, is_feature_enabled -from superset.constants import PASSWORD_MASK -from superset.databases.commands.exceptions import DatabaseInvalidError -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.exceptions import DatabaseInvalidError +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelingNotEnabledError, SSHTunnelInvalidCredentials, SSHTunnelMissingCredentials, ) +from superset.constants import PASSWORD_MASK from superset.databases.utils import make_url_safe from superset.db_engine_specs import get_engine_spec from superset.exceptions import CertificateException, SupersetSecurityException diff --git a/superset/databases/utils.py b/superset/databases/utils.py index fa163e4d9..21abd7b9c 100644 --- a/superset/databases/utils.py +++ b/superset/databases/utils.py @@ -18,7 +18,7 @@ from typing import Any, Optional, Union from sqlalchemy.engine.url import make_url, URL -from superset.databases.commands.exceptions import DatabaseInvalidError +from superset.commands.database.exceptions import DatabaseInvalidError def get_foreign_keys_metadata( diff --git a/superset/datasets/api.py b/superset/datasets/api.py index e1d7e5a09..e256ff99d 100644 --- a/superset/datasets/api.py +++ b/superset/datasets/api.py @@ -30,17 +30,10 @@ from flask_babel import ngettext from marshmallow import ValidationError from superset import event_logger, is_feature_enabled -from superset.commands.exceptions import CommandException -from superset.commands.importers.exceptions import NoValidFilesFoundError -from superset.commands.importers.v1.utils import get_contents_from_bundle -from superset.connectors.sqla.models import SqlaTable -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.daos.dataset import DatasetDAO -from superset.databases.filters import DatabaseFilter -from superset.datasets.commands.create import CreateDatasetCommand -from superset.datasets.commands.delete import DeleteDatasetCommand -from superset.datasets.commands.duplicate import DuplicateDatasetCommand -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.create import CreateDatasetCommand +from superset.commands.dataset.delete import DeleteDatasetCommand +from superset.commands.dataset.duplicate import DuplicateDatasetCommand +from superset.commands.dataset.exceptions import ( DatasetCreateFailedError, DatasetDeleteFailedError, DatasetForbiddenError, @@ -49,11 +42,18 @@ from superset.datasets.commands.exceptions import ( DatasetRefreshFailedError, DatasetUpdateFailedError, ) -from superset.datasets.commands.export import ExportDatasetsCommand -from superset.datasets.commands.importers.dispatcher import ImportDatasetsCommand -from superset.datasets.commands.refresh import RefreshDatasetCommand -from superset.datasets.commands.update import UpdateDatasetCommand -from superset.datasets.commands.warm_up_cache import DatasetWarmUpCacheCommand +from superset.commands.dataset.export import ExportDatasetsCommand +from superset.commands.dataset.importers.dispatcher import ImportDatasetsCommand +from superset.commands.dataset.refresh import RefreshDatasetCommand +from superset.commands.dataset.update import UpdateDatasetCommand +from superset.commands.dataset.warm_up_cache import DatasetWarmUpCacheCommand +from superset.commands.exceptions import CommandException +from superset.commands.importers.exceptions import NoValidFilesFoundError +from superset.commands.importers.v1.utils import get_contents_from_bundle +from superset.connectors.sqla.models import SqlaTable +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.daos.dataset import DatasetDAO +from superset.databases.filters import DatabaseFilter from superset.datasets.filters import DatasetCertifiedFilter, DatasetIsNullOrEmptyFilter from superset.datasets.schemas import ( DatasetCacheWarmUpRequestSchema, diff --git a/superset/datasets/columns/api.py b/superset/datasets/columns/api.py index 0aafab5d3..90de0f775 100644 --- a/superset/datasets/columns/api.py +++ b/superset/datasets/columns/api.py @@ -20,14 +20,14 @@ from flask import Response from flask_appbuilder.api import expose, permission_name, protect, safe from flask_appbuilder.models.sqla.interface import SQLAInterface -from superset.connectors.sqla.models import TableColumn -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.datasets.columns.commands.delete import DeleteDatasetColumnCommand -from superset.datasets.columns.commands.exceptions import ( +from superset.commands.dataset.columns.delete import DeleteDatasetColumnCommand +from superset.commands.dataset.columns.exceptions import ( DatasetColumnDeleteFailedError, DatasetColumnForbiddenError, DatasetColumnNotFoundError, ) +from superset.connectors.sqla.models import TableColumn +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP from superset.views.base_api import BaseSupersetModelRestApi, statsd_metrics logger = logging.getLogger(__name__) diff --git a/superset/datasets/metrics/api.py b/superset/datasets/metrics/api.py index 28ec9474e..aa29254fc 100644 --- a/superset/datasets/metrics/api.py +++ b/superset/datasets/metrics/api.py @@ -20,14 +20,14 @@ from flask import Response from flask_appbuilder.api import expose, permission_name, protect, safe from flask_appbuilder.models.sqla.interface import SQLAInterface -from superset.connectors.sqla.models import TableColumn -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.datasets.metrics.commands.delete import DeleteDatasetMetricCommand -from superset.datasets.metrics.commands.exceptions import ( +from superset.commands.dataset.metrics.delete import DeleteDatasetMetricCommand +from superset.commands.dataset.metrics.exceptions import ( DatasetMetricDeleteFailedError, DatasetMetricForbiddenError, DatasetMetricNotFoundError, ) +from superset.connectors.sqla.models import TableColumn +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP from superset.views.base_api import BaseSupersetModelRestApi, statsd_metrics logger = logging.getLogger(__name__) diff --git a/superset/embedded/api.py b/superset/embedded/api.py index ae800bf2b..b907422bf 100644 --- a/superset/embedded/api.py +++ b/superset/embedded/api.py @@ -23,12 +23,12 @@ from flask_appbuilder.hooks import before_request from flask_appbuilder.models.sqla.interface import SQLAInterface from superset import is_feature_enabled +from superset.commands.dashboard.embedded.exceptions import ( + EmbeddedDashboardNotFoundError, +) from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.daos.dashboard import EmbeddedDashboardDAO from superset.dashboards.schemas import EmbeddedDashboardResponseSchema -from superset.embedded_dashboard.commands.exceptions import ( - EmbeddedDashboardNotFoundError, -) from superset.extensions import event_logger from superset.models.embedded_dashboard import EmbeddedDashboard from superset.reports.logs.schemas import openapi_spec_methods_override diff --git a/superset/explore/api.py b/superset/explore/api.py index ebda161be..faadbe8d9 100644 --- a/superset/explore/api.py +++ b/superset/explore/api.py @@ -19,18 +19,18 @@ import logging from flask import g, request, Response from flask_appbuilder.api import expose, protect, safe -from superset.charts.commands.exceptions import ChartNotFoundError +from superset.commands.chart.exceptions import ChartNotFoundError +from superset.commands.explore.get import GetExploreCommand +from superset.commands.explore.parameters import CommandParameters +from superset.commands.temporary_cache.exceptions import ( + TemporaryCacheAccessDeniedError, + TemporaryCacheResourceNotFoundError, +) from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.explore.commands.get import GetExploreCommand -from superset.explore.commands.parameters import CommandParameters from superset.explore.exceptions import DatasetAccessDeniedError, WrongEndpointError from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError from superset.explore.schemas import ExploreContextSchema from superset.extensions import event_logger -from superset.temporary_cache.commands.exceptions import ( - TemporaryCacheAccessDeniedError, - TemporaryCacheResourceNotFoundError, -) from superset.views.base_api import BaseSupersetApi, statsd_metrics logger = logging.getLogger(__name__) diff --git a/superset/explore/form_data/api.py b/superset/explore/form_data/api.py index 36489ca44..6c882d92a 100644 --- a/superset/explore/form_data/api.py +++ b/superset/explore/form_data/api.py @@ -20,18 +20,18 @@ from flask import request, Response from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.explore.form_data.commands.create import CreateFormDataCommand -from superset.explore.form_data.commands.delete import DeleteFormDataCommand -from superset.explore.form_data.commands.get import GetFormDataCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.update import UpdateFormDataCommand -from superset.explore.form_data.schemas import FormDataPostSchema, FormDataPutSchema -from superset.extensions import event_logger -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.explore.form_data.create import CreateFormDataCommand +from superset.commands.explore.form_data.delete import DeleteFormDataCommand +from superset.commands.explore.form_data.get import GetFormDataCommand +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.update import UpdateFormDataCommand +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheResourceNotFoundError, ) +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP +from superset.explore.form_data.schemas import FormDataPostSchema, FormDataPutSchema +from superset.extensions import event_logger from superset.views.base_api import BaseSupersetApi, requires_json, statsd_metrics logger = logging.getLogger(__name__) diff --git a/superset/explore/permalink/api.py b/superset/explore/permalink/api.py index b249d4dee..bc9bd1cf6 100644 --- a/superset/explore/permalink/api.py +++ b/superset/explore/permalink/api.py @@ -20,17 +20,17 @@ from flask import request, Response from flask_appbuilder.api import expose, protect, safe from marshmallow import ValidationError -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( ChartAccessDeniedError, ChartNotFoundError, ) -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetAccessDeniedError, DatasetNotFoundError, ) -from superset.explore.permalink.commands.create import CreateExplorePermalinkCommand -from superset.explore.permalink.commands.get import GetExplorePermalinkCommand +from superset.commands.explore.permalink.create import CreateExplorePermalinkCommand +from superset.commands.explore.permalink.get import GetExplorePermalinkCommand +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP from superset.explore.permalink.exceptions import ExplorePermalinkInvalidStateError from superset.explore.permalink.schemas import ExplorePermalinkStateSchema from superset.extensions import event_logger diff --git a/superset/explore/utils.py b/superset/explore/utils.py index ca73cb39f..7d5c0d86b 100644 --- a/superset/explore/utils.py +++ b/superset/explore/utils.py @@ -17,10 +17,14 @@ from typing import Optional from superset import security_manager -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( ChartAccessDeniedError, ChartNotFoundError, ) +from superset.commands.dataset.exceptions import ( + DatasetAccessDeniedError, + DatasetNotFoundError, +) from superset.commands.exceptions import ( DatasourceNotFoundValidationError, DatasourceTypeInvalidError, @@ -29,10 +33,6 @@ from superset.commands.exceptions import ( from superset.daos.chart import ChartDAO from superset.daos.dataset import DatasetDAO from superset.daos.query import QueryDAO -from superset.datasets.commands.exceptions import ( - DatasetAccessDeniedError, - DatasetNotFoundError, -) from superset.utils.core import DatasourceType diff --git a/superset/extensions/metastore_cache.py b/superset/extensions/metastore_cache.py index b6effdfe9..435c38ced 100644 --- a/superset/extensions/metastore_cache.py +++ b/superset/extensions/metastore_cache.py @@ -71,7 +71,7 @@ class SupersetMetastoreCache(BaseCache): @staticmethod def _prune() -> None: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.delete_expired import ( + from superset.commands.key_value.delete_expired import ( DeleteExpiredKeyValueCommand, ) @@ -85,7 +85,7 @@ class SupersetMetastoreCache(BaseCache): def set(self, key: str, value: Any, timeout: Optional[int] = None) -> bool: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.upsert import UpsertKeyValueCommand + from superset.commands.key_value.upsert import UpsertKeyValueCommand UpsertKeyValueCommand( resource=RESOURCE, @@ -98,7 +98,7 @@ class SupersetMetastoreCache(BaseCache): def add(self, key: str, value: Any, timeout: Optional[int] = None) -> bool: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand try: CreateKeyValueCommand( @@ -115,7 +115,7 @@ class SupersetMetastoreCache(BaseCache): def get(self, key: str) -> Any: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand return GetKeyValueCommand( resource=RESOURCE, @@ -131,6 +131,6 @@ class SupersetMetastoreCache(BaseCache): def delete(self, key: str) -> Any: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.delete import DeleteKeyValueCommand + from superset.commands.key_value.delete import DeleteKeyValueCommand return DeleteKeyValueCommand(resource=RESOURCE, key=self.get_key(key)).run() diff --git a/superset/jinja_context.py b/superset/jinja_context.py index 13a639df7..3b046b732 100644 --- a/superset/jinja_context.py +++ b/superset/jinja_context.py @@ -30,8 +30,8 @@ from sqlalchemy.engine.interfaces import Dialect from sqlalchemy.sql.expression import bindparam from sqlalchemy.types import String +from superset.commands.dataset.exceptions import DatasetNotFoundError from superset.constants import LRU_CACHE_MAX_SIZE -from superset.datasets.commands.exceptions import DatasetNotFoundError from superset.exceptions import SupersetTemplateException from superset.extensions import feature_flag_manager from superset.utils.core import ( diff --git a/superset/key_value/shared_entries.py b/superset/key_value/shared_entries.py index 7895b7590..130313157 100644 --- a/superset/key_value/shared_entries.py +++ b/superset/key_value/shared_entries.py @@ -28,7 +28,7 @@ CODEC = JsonKeyValueCodec() def get_shared_value(key: SharedKey) -> Optional[Any]: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand uuid_key = uuid3(NAMESPACE, key) return GetKeyValueCommand(RESOURCE, key=uuid_key, codec=CODEC).run() @@ -36,7 +36,7 @@ def get_shared_value(key: SharedKey) -> Optional[Any]: def set_shared_value(key: SharedKey, value: Any) -> None: # pylint: disable=import-outside-toplevel - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand uuid_key = uuid3(NAMESPACE, key) CreateKeyValueCommand( diff --git a/superset/models/core.py b/superset/models/core.py index d2b38ea80..eece661ec 100755 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -59,8 +59,8 @@ from sqlalchemy.schema import UniqueConstraint from sqlalchemy.sql import ColumnElement, expression, Select from superset import app, db_engine_specs +from superset.commands.database.exceptions import DatabaseInvalidError from superset.constants import LRU_CACHE_MAX_SIZE, PASSWORD_MASK -from superset.databases.commands.exceptions import DatabaseInvalidError from superset.databases.utils import make_url_safe from superset.db_engine_specs.base import MetricType, TimeGrain from superset.extensions import ( diff --git a/superset/queries/saved_queries/api.py b/superset/queries/saved_queries/api.py index 69e1a6191..25ac520e4 100644 --- a/superset/queries/saved_queries/api.py +++ b/superset/queries/saved_queries/api.py @@ -32,19 +32,17 @@ from superset.commands.importers.exceptions import ( NoValidFilesFoundError, ) from superset.commands.importers.v1.utils import get_contents_from_bundle +from superset.commands.query.delete import DeleteSavedQueryCommand +from superset.commands.query.exceptions import ( + SavedQueryDeleteFailedError, + SavedQueryNotFoundError, +) +from superset.commands.query.export import ExportSavedQueriesCommand +from superset.commands.query.importers.dispatcher import ImportSavedQueriesCommand from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.databases.filters import DatabaseFilter from superset.extensions import event_logger from superset.models.sql_lab import SavedQuery -from superset.queries.saved_queries.commands.delete import DeleteSavedQueryCommand -from superset.queries.saved_queries.commands.exceptions import ( - SavedQueryDeleteFailedError, - SavedQueryNotFoundError, -) -from superset.queries.saved_queries.commands.export import ExportSavedQueriesCommand -from superset.queries.saved_queries.commands.importers.dispatcher import ( - ImportSavedQueriesCommand, -) from superset.queries.saved_queries.filters import ( SavedQueryAllTextFilter, SavedQueryFavoriteFilter, diff --git a/superset/reports/api.py b/superset/reports/api.py index 3116aef3b..ab4f80ae1 100644 --- a/superset/reports/api.py +++ b/superset/reports/api.py @@ -26,13 +26,9 @@ from marshmallow import ValidationError from superset import is_feature_enabled from superset.charts.filters import ChartFilter -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.dashboards.filters import DashboardAccessFilter -from superset.databases.filters import DatabaseFilter -from superset.extensions import event_logger -from superset.reports.commands.create import CreateReportScheduleCommand -from superset.reports.commands.delete import DeleteReportScheduleCommand -from superset.reports.commands.exceptions import ( +from superset.commands.report.create import CreateReportScheduleCommand +from superset.commands.report.delete import DeleteReportScheduleCommand +from superset.commands.report.exceptions import ( ReportScheduleCreateFailedError, ReportScheduleDeleteFailedError, ReportScheduleForbiddenError, @@ -40,7 +36,11 @@ from superset.reports.commands.exceptions import ( ReportScheduleNotFoundError, ReportScheduleUpdateFailedError, ) -from superset.reports.commands.update import UpdateReportScheduleCommand +from superset.commands.report.update import UpdateReportScheduleCommand +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.dashboards.filters import DashboardAccessFilter +from superset.databases.filters import DatabaseFilter +from superset.extensions import event_logger from superset.reports.filters import ReportScheduleAllTextFilter, ReportScheduleFilter from superset.reports.models import ReportSchedule from superset.reports.schemas import ( diff --git a/superset/row_level_security/api.py b/superset/row_level_security/api.py index 0a823f74d..e7347f528 100644 --- a/superset/row_level_security/api.py +++ b/superset/row_level_security/api.py @@ -28,14 +28,14 @@ from superset.commands.exceptions import ( DatasourceNotFoundValidationError, RolesNotFoundValidationError, ) +from superset.commands.security.create import CreateRLSRuleCommand +from superset.commands.security.delete import DeleteRLSRuleCommand +from superset.commands.security.exceptions import RLSRuleNotFoundError +from superset.commands.security.update import UpdateRLSRuleCommand from superset.connectors.sqla.models import RowLevelSecurityFilter from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod from superset.daos.exceptions import DAOCreateFailedError, DAOUpdateFailedError from superset.extensions import event_logger -from superset.row_level_security.commands.create import CreateRLSRuleCommand -from superset.row_level_security.commands.delete import DeleteRLSRuleCommand -from superset.row_level_security.commands.exceptions import RLSRuleNotFoundError -from superset.row_level_security.commands.update import UpdateRLSRuleCommand from superset.row_level_security.schemas import ( get_delete_ids_schema, openapi_spec_methods_override, diff --git a/superset/security/api.py b/superset/security/api.py index b4a306975..acafc3257 100644 --- a/superset/security/api.py +++ b/superset/security/api.py @@ -24,7 +24,7 @@ from flask_appbuilder.security.decorators import permission_name, protect from flask_wtf.csrf import generate_csrf from marshmallow import EXCLUDE, fields, post_load, Schema, ValidationError -from superset.embedded_dashboard.commands.exceptions import ( +from superset.commands.dashboard.embedded.exceptions import ( EmbeddedDashboardNotFoundError, ) from superset.extensions import event_logger diff --git a/superset/security/manager.py b/superset/security/manager.py index 03f0ee56c..5eb1afdda 100644 --- a/superset/security/manager.py +++ b/superset/security/manager.py @@ -2153,10 +2153,10 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods @staticmethod def validate_guest_token_resources(resources: GuestTokenResources) -> None: # pylint: disable=import-outside-toplevel - from superset.daos.dashboard import EmbeddedDashboardDAO - from superset.embedded_dashboard.commands.exceptions import ( + from superset.commands.dashboard.embedded.exceptions import ( EmbeddedDashboardNotFoundError, ) + from superset.daos.dashboard import EmbeddedDashboardDAO from superset.models.dashboard import Dashboard for resource in resources: diff --git a/superset/sqllab/api.py b/superset/sqllab/api.py index 16070b52c..6be378a9b 100644 --- a/superset/sqllab/api.py +++ b/superset/sqllab/api.py @@ -27,6 +27,10 @@ from flask_appbuilder.models.sqla.interface import SQLAInterface from marshmallow import ValidationError from superset import app, is_feature_enabled +from superset.commands.sql_lab.estimate import QueryEstimationCommand +from superset.commands.sql_lab.execute import CommandResult, ExecuteSqlCommand +from superset.commands.sql_lab.export import SqlResultExportCommand +from superset.commands.sql_lab.results import SqlExecutionResultsCommand from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP from superset.daos.database import DatabaseDAO from superset.daos.query import QueryDAO @@ -35,10 +39,6 @@ from superset.jinja_context import get_template_processor from superset.models.sql_lab import Query from superset.sql_lab import get_sql_results from superset.sqllab.command_status import SqlJsonExecutionStatus -from superset.sqllab.commands.estimate import QueryEstimationCommand -from superset.sqllab.commands.execute import CommandResult, ExecuteSqlCommand -from superset.sqllab.commands.export import SqlResultExportCommand -from superset.sqllab.commands.results import SqlExecutionResultsCommand from superset.sqllab.exceptions import ( QueryIsForbiddenToAccessException, SqlLabException, diff --git a/superset/sqllab/query_render.py b/superset/sqllab/query_render.py index 4fb64c8ce..f4c1c26c6 100644 --- a/superset/sqllab/query_render.py +++ b/superset/sqllab/query_render.py @@ -24,9 +24,9 @@ from jinja2 import TemplateError from jinja2.meta import find_undeclared_variables from superset import is_feature_enabled +from superset.commands.sql_lab.execute import SqlQueryRender from superset.errors import SupersetErrorType from superset.sql_parse import ParsedQuery -from superset.sqllab.commands.execute import SqlQueryRender from superset.sqllab.exceptions import SqlLabException from superset.utils import core as utils diff --git a/superset/sqllab/validators.py b/superset/sqllab/validators.py index 5bc8a6225..b79789da4 100644 --- a/superset/sqllab/validators.py +++ b/superset/sqllab/validators.py @@ -20,7 +20,7 @@ from __future__ import annotations from typing import TYPE_CHECKING from superset import security_manager -from superset.sqllab.commands.execute import CanAccessQueryValidator +from superset.commands.sql_lab.execute import CanAccessQueryValidator if TYPE_CHECKING: from superset.models.sql_lab import Query diff --git a/superset/tags/api.py b/superset/tags/api.py index 8e01fd240..a4fc185f2 100644 --- a/superset/tags/api.py +++ b/superset/tags/api.py @@ -22,16 +22,12 @@ from flask_appbuilder.api import expose, protect, rison, safe from flask_appbuilder.models.sqla.interface import SQLAInterface from marshmallow import ValidationError -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.daos.tag import TagDAO -from superset.exceptions import MissingUserContextException -from superset.extensions import event_logger -from superset.tags.commands.create import ( +from superset.commands.tag.create import ( CreateCustomTagCommand, CreateCustomTagWithRelationshipsCommand, ) -from superset.tags.commands.delete import DeleteTaggedObjectCommand, DeleteTagsCommand -from superset.tags.commands.exceptions import ( +from superset.commands.tag.delete import DeleteTaggedObjectCommand, DeleteTagsCommand +from superset.commands.tag.exceptions import ( TagDeleteFailedError, TaggedObjectDeleteFailedError, TaggedObjectNotFoundError, @@ -39,7 +35,11 @@ from superset.tags.commands.exceptions import ( TagNotFoundError, TagUpdateFailedError, ) -from superset.tags.commands.update import UpdateTagCommand +from superset.commands.tag.update import UpdateTagCommand +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.daos.tag import TagDAO +from superset.exceptions import MissingUserContextException +from superset.extensions import event_logger from superset.tags.models import ObjectType, Tag from superset.tags.schemas import ( delete_tags_schema, diff --git a/superset/tasks/async_queries.py b/superset/tasks/async_queries.py index 609af3bc8..61970ca1f 100644 --- a/superset/tasks/async_queries.py +++ b/superset/tasks/async_queries.py @@ -64,7 +64,7 @@ def load_chart_data_into_cache( form_data: dict[str, Any], ) -> None: # pylint: disable=import-outside-toplevel - from superset.charts.data.commands.get_data_command import ChartDataCommand + from superset.commands.chart.data.get_data_command import ChartDataCommand user = ( security_manager.get_user_by_id(job_metadata.get("user_id")) diff --git a/superset/tasks/scheduler.py b/superset/tasks/scheduler.py index f3cc270b8..7b1350a07 100644 --- a/superset/tasks/scheduler.py +++ b/superset/tasks/scheduler.py @@ -22,11 +22,11 @@ from celery.exceptions import SoftTimeLimitExceeded from superset import app, is_feature_enabled from superset.commands.exceptions import CommandException +from superset.commands.report.exceptions import ReportScheduleUnexpectedError +from superset.commands.report.execute import AsyncExecuteReportScheduleCommand +from superset.commands.report.log_prune import AsyncPruneReportScheduleLogCommand from superset.daos.report import ReportScheduleDAO from superset.extensions import celery_app -from superset.reports.commands.exceptions import ReportScheduleUnexpectedError -from superset.reports.commands.execute import AsyncExecuteReportScheduleCommand -from superset.reports.commands.log_prune import AsyncPruneReportScheduleLogCommand from superset.stats_logger import BaseStatsLogger from superset.tasks.cron_util import cron_schedule_window from superset.utils.celery import session_scope diff --git a/superset/temporary_cache/api.py b/superset/temporary_cache/api.py index 0ecab44bf..5dc95c122 100644 --- a/superset/temporary_cache/api.py +++ b/superset/temporary_cache/api.py @@ -24,13 +24,13 @@ from apispec.exceptions import DuplicateComponentNameError from flask import request, Response from marshmallow import ValidationError -from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod -from superset.key_value.types import JsonKeyValueCodec -from superset.temporary_cache.commands.exceptions import ( +from superset.commands.temporary_cache.exceptions import ( TemporaryCacheAccessDeniedError, TemporaryCacheResourceNotFoundError, ) -from superset.temporary_cache.commands.parameters import CommandParameters +from superset.commands.temporary_cache.parameters import CommandParameters +from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod +from superset.key_value.types import JsonKeyValueCodec from superset.temporary_cache.schemas import ( TemporaryCachePostSchema, TemporaryCachePutSchema, diff --git a/superset/utils/date_parser.py b/superset/utils/date_parser.py index 438e379a9..2d49424a8 100644 --- a/superset/utils/date_parser.py +++ b/superset/utils/date_parser.py @@ -41,7 +41,7 @@ from pyparsing import ( Suppress, ) -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( TimeDeltaAmbiguousError, TimeRangeAmbiguousError, TimeRangeParseFailError, diff --git a/superset/views/api.py b/superset/views/api.py index 312efb947..eeedd7c64 100644 --- a/superset/views/api.py +++ b/superset/views/api.py @@ -26,7 +26,7 @@ from flask_appbuilder.security.decorators import has_access_api from flask_babel import lazy_gettext as _ from superset import db, event_logger -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( TimeRangeAmbiguousError, TimeRangeParseFailError, ) diff --git a/superset/views/core.py b/superset/views/core.py index 28d84d223..9ad2f63fd 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -44,26 +44,26 @@ from superset import ( security_manager, ) from superset.async_events.async_query_manager import AsyncQueryTokenException -from superset.charts.commands.exceptions import ChartNotFoundError -from superset.charts.commands.warm_up_cache import ChartWarmUpCacheCommand +from superset.commands.chart.exceptions import ChartNotFoundError +from superset.commands.chart.warm_up_cache import ChartWarmUpCacheCommand +from superset.commands.dashboard.importers.v0 import ImportDashboardsCommand +from superset.commands.dashboard.permalink.get import GetDashboardPermalinkCommand +from superset.commands.dataset.exceptions import DatasetNotFoundError +from superset.commands.explore.form_data.create import CreateFormDataCommand +from superset.commands.explore.form_data.get import GetFormDataCommand +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.permalink.get import GetExplorePermalinkCommand from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType from superset.connectors.sqla.models import BaseDatasource, SqlaTable from superset.daos.chart import ChartDAO from superset.daos.datasource import DatasourceDAO -from superset.dashboards.commands.importers.v0 import ImportDashboardsCommand -from superset.dashboards.permalink.commands.get import GetDashboardPermalinkCommand from superset.dashboards.permalink.exceptions import DashboardPermalinkGetFailedError -from superset.datasets.commands.exceptions import DatasetNotFoundError from superset.exceptions import ( CacheLoadError, DatabaseNotFound, SupersetException, SupersetSecurityException, ) -from superset.explore.form_data.commands.create import CreateFormDataCommand -from superset.explore.form_data.commands.get import GetFormDataCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.permalink.commands.get import GetExplorePermalinkCommand from superset.explore.permalink.exceptions import ExplorePermalinkGetFailedError from superset.extensions import async_query_manager, cache_manager from superset.models.core import Database diff --git a/superset/views/database/validators.py b/superset/views/database/validators.py index 2ee49c821..e4fef3446 100644 --- a/superset/views/database/validators.py +++ b/superset/views/database/validators.py @@ -21,7 +21,7 @@ from flask_babel import lazy_gettext as _ from marshmallow import ValidationError from superset import security_manager -from superset.databases.commands.exceptions import DatabaseInvalidError +from superset.commands.database.exceptions import DatabaseInvalidError from superset.databases.utils import make_url_safe from superset.models.core import Database diff --git a/superset/views/datasource/utils.py b/superset/views/datasource/utils.py index afed5f7fd..61b7cc85b 100644 --- a/superset/views/datasource/utils.py +++ b/superset/views/datasource/utils.py @@ -17,12 +17,12 @@ from typing import Any, Optional from superset import app, db +from superset.commands.dataset.exceptions import DatasetSamplesFailedError from superset.common.chart_data import ChartDataResultType from superset.common.query_context_factory import QueryContextFactory from superset.common.utils.query_cache_manager import QueryCacheManager from superset.constants import CacheRegion from superset.daos.datasource import DatasourceDAO -from superset.datasets.commands.exceptions import DatasetSamplesFailedError from superset.utils.core import QueryStatus from superset.views.datasource.schemas import SamplesPayloadSchema diff --git a/superset/views/datasource/views.py b/superset/views/datasource/views.py index 56acbd858..a4c158a11 100644 --- a/superset/views/datasource/views.py +++ b/superset/views/datasource/views.py @@ -28,14 +28,14 @@ from sqlalchemy.exc import NoSuchTableError from sqlalchemy.orm.exc import NoResultFound from superset import db, event_logger, security_manager +from superset.commands.dataset.exceptions import ( + DatasetForbiddenError, + DatasetNotFoundError, +) from superset.commands.utils import populate_owners from superset.connectors.sqla.models import SqlaTable from superset.connectors.sqla.utils import get_physical_table_metadata from superset.daos.datasource import DatasourceDAO -from superset.datasets.commands.exceptions import ( - DatasetForbiddenError, - DatasetNotFoundError, -) from superset.exceptions import SupersetException, SupersetSecurityException from superset.models.core import Database from superset.superset_typing import FlaskResponse diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index ae64eba80..fe489a0f3 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -28,8 +28,8 @@ from parameterized import parameterized from sqlalchemy import and_ from sqlalchemy.sql import func -from superset.charts.commands.exceptions import ChartDataQueryFailedError -from superset.charts.data.commands.get_data_command import ChartDataCommand +from superset.commands.chart.data.get_data_command import ChartDataCommand +from superset.commands.chart.exceptions import ChartDataQueryFailedError from superset.connectors.sqla.models import SqlaTable from superset.extensions import cache_manager, db, security_manager from superset.models.core import Database, FavStar, FavStarClassName diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py index f9785a4dd..87c7823ae 100644 --- a/tests/integration_tests/charts/commands_tests.py +++ b/tests/integration_tests/charts/commands_tests.py @@ -22,15 +22,15 @@ import yaml from flask import g from superset import db, security_manager -from superset.charts.commands.create import CreateChartCommand -from superset.charts.commands.exceptions import ( +from superset.commands.chart.create import CreateChartCommand +from superset.commands.chart.exceptions import ( ChartNotFoundError, WarmUpCacheChartNotFoundError, ) -from superset.charts.commands.export import ExportChartsCommand -from superset.charts.commands.importers.v1 import ImportChartsCommand -from superset.charts.commands.update import UpdateChartCommand -from superset.charts.commands.warm_up_cache import ChartWarmUpCacheCommand +from superset.commands.chart.export import ExportChartsCommand +from superset.commands.chart.importers.v1 import ImportChartsCommand +from superset.commands.chart.update import UpdateChartCommand +from superset.commands.chart.warm_up_cache import ChartWarmUpCacheCommand from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError from superset.connectors.sqla.models import SqlaTable @@ -171,7 +171,7 @@ class TestExportChartsCommand(SupersetTestCase): class TestImportChartsCommand(SupersetTestCase): - @patch("superset.charts.commands.importers.v1.utils.g") + @patch("superset.commands.chart.importers.v1.utils.g") @patch("superset.security.manager.g") def test_import_v1_chart(self, sm_g, utils_g): """Test that we can import a chart""" @@ -324,7 +324,7 @@ class TestImportChartsCommand(SupersetTestCase): class TestChartsCreateCommand(SupersetTestCase): @patch("superset.utils.core.g") - @patch("superset.charts.commands.create.g") + @patch("superset.commands.chart.create.g") @patch("superset.security.manager.g") @pytest.mark.usefixtures("load_energy_table_with_slice") def test_create_v1_response(self, mock_sm_g, mock_c_g, mock_u_g): @@ -354,7 +354,7 @@ class TestChartsCreateCommand(SupersetTestCase): class TestChartsUpdateCommand(SupersetTestCase): - @patch("superset.charts.commands.update.g") + @patch("superset.commands.chart.update.g") @patch("superset.utils.core.g") @patch("superset.security.manager.g") @pytest.mark.usefixtures("load_energy_table_with_slice") diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py index 5a62ce0a8..4def03ff4 100644 --- a/tests/integration_tests/charts/data/api_tests.py +++ b/tests/integration_tests/charts/data/api_tests.py @@ -42,7 +42,7 @@ from tests.integration_tests.fixtures.energy_dashboard import ( import pytest from superset.models.slice import Slice -from superset.charts.data.commands.get_data_command import ChartDataCommand +from superset.commands.chart.data.get_data_command import ChartDataCommand from superset.connectors.sqla.models import TableColumn, SqlaTable from superset.errors import SupersetErrorType from superset.extensions import async_query_manager_factory, db diff --git a/tests/integration_tests/cli_tests.py b/tests/integration_tests/cli_tests.py index f9195a6c2..55557ab32 100644 --- a/tests/integration_tests/cli_tests.py +++ b/tests/integration_tests/cli_tests.py @@ -137,7 +137,7 @@ def test_export_dashboards_versioned_export(app_context, fs): "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) @mock.patch( - "superset.dashboards.commands.export.ExportDashboardsCommand.run", + "superset.commands.dashboard.export.ExportDashboardsCommand.run", side_effect=Exception(), ) def test_failing_export_dashboards_versioned_export( @@ -191,7 +191,7 @@ def test_export_datasources_versioned_export(app_context, fs): "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) @mock.patch( - "superset.dashboards.commands.export.ExportDatasetsCommand.run", + "superset.commands.dashboard.export.ExportDatasetsCommand.run", side_effect=Exception(), ) def test_failing_export_datasources_versioned_export( @@ -217,7 +217,7 @@ def test_failing_export_datasources_versioned_export( @mock.patch.dict( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) -@mock.patch("superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand") +@mock.patch("superset.commands.dashboard.importers.dispatcher.ImportDashboardsCommand") def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs): """ Test that both ZIP and JSON can be imported. @@ -261,7 +261,7 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) @mock.patch( - "superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand.run", + "superset.commands.dashboard.importers.dispatcher.ImportDashboardsCommand.run", side_effect=Exception(), ) def test_failing_import_dashboards_versioned_export( @@ -304,7 +304,7 @@ def test_failing_import_dashboards_versioned_export( @mock.patch.dict( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) -@mock.patch("superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand") +@mock.patch("superset.commands.dataset.importers.dispatcher.ImportDatasetsCommand") def test_import_datasets_versioned_export(import_datasets_command, app_context, fs): """ Test that both ZIP and YAML can be imported. @@ -347,7 +347,7 @@ def test_import_datasets_versioned_export(import_datasets_command, app_context, @mock.patch.dict( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True ) -@mock.patch("superset.datasets.commands.importers.v0.ImportDatasetsCommand") +@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand") def test_import_datasets_sync_argument_columns_metrics( import_datasets_command, app_context, fs ): @@ -384,7 +384,7 @@ def test_import_datasets_sync_argument_columns_metrics( @mock.patch.dict( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True ) -@mock.patch("superset.datasets.commands.importers.v0.ImportDatasetsCommand") +@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand") def test_import_datasets_sync_argument_columns( import_datasets_command, app_context, fs ): @@ -421,7 +421,7 @@ def test_import_datasets_sync_argument_columns( @mock.patch.dict( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True ) -@mock.patch("superset.datasets.commands.importers.v0.ImportDatasetsCommand") +@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand") def test_import_datasets_sync_argument_metrics( import_datasets_command, app_context, fs ): @@ -459,7 +459,7 @@ def test_import_datasets_sync_argument_metrics( "superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True ) @mock.patch( - "superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand.run", + "superset.commands.dataset.importers.dispatcher.ImportDatasetsCommand.run", side_effect=Exception(), ) def test_failing_import_datasets_versioned_export( diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py index f83d1b01c..25f8e624e 100644 --- a/tests/integration_tests/core_tests.py +++ b/tests/integration_tests/core_tests.py @@ -35,8 +35,8 @@ from sqlalchemy.exc import SQLAlchemyError import superset.utils.database import superset.views.utils from superset import dataframe, db, security_manager, sql_lab -from superset.charts.commands.exceptions import ChartDataQueryFailedError -from superset.charts.data.commands.get_data_command import ChartDataCommand +from superset.commands.chart.data.get_data_command import ChartDataCommand +from superset.commands.chart.exceptions import ChartDataQueryFailedError from superset.common.db_query_status import QueryStatus from superset.connectors.sqla.models import SqlaTable from superset.db_engine_specs.base import BaseEngineSpec @@ -1165,7 +1165,7 @@ class TestCore(SupersetTestCase): self.assertIn("Error message", data) @pytest.mark.usefixtures("load_energy_table_with_slice") - @mock.patch("superset.explore.form_data.commands.create.CreateFormDataCommand.run") + @mock.patch("superset.commands.explore.form_data.create.CreateFormDataCommand.run") def test_explore_redirect(self, mock_command: mock.Mock): self.login(username="admin") random_key = "random_key" diff --git a/tests/integration_tests/dashboards/commands_tests.py b/tests/integration_tests/dashboards/commands_tests.py index 75bdd17bc..cfc992b95 100644 --- a/tests/integration_tests/dashboards/commands_tests.py +++ b/tests/integration_tests/dashboards/commands_tests.py @@ -23,16 +23,16 @@ import yaml from werkzeug.utils import secure_filename from superset import db, security_manager -from superset.commands.exceptions import CommandInvalidError -from superset.commands.importers.exceptions import IncorrectVersionError -from superset.connectors.sqla.models import SqlaTable -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.commands.export import ( +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.export import ( append_charts, ExportDashboardsCommand, get_default_position, ) -from superset.dashboards.commands.importers import v0, v1 +from superset.commands.dashboard.importers import v0, v1 +from superset.commands.exceptions import CommandInvalidError +from superset.commands.importers.exceptions import IncorrectVersionError +from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.dashboard import Dashboard from superset.models.slice import Slice @@ -292,7 +292,7 @@ class TestExportDashboardsCommand(SupersetTestCase): ] @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") - @patch("superset.dashboards.commands.export.suffix") + @patch("superset.commands.dashboard.export.suffix") def test_append_charts(self, mock_suffix): """Test that orphaned charts are added to the dashboard position""" # return deterministic IDs @@ -490,7 +490,7 @@ class TestImportDashboardsCommand(SupersetTestCase): db.session.delete(dataset) db.session.commit() - @patch("superset.dashboards.commands.importers.v1.utils.g") + @patch("superset.commands.dashboard.importers.v1.utils.g") @patch("superset.security.manager.g") def test_import_v1_dashboard(self, sm_g, utils_g): """Test that we can import a dashboard""" diff --git a/tests/integration_tests/dashboards/filter_state/api_tests.py b/tests/integration_tests/dashboards/filter_state/api_tests.py index 15b479686..3538e1401 100644 --- a/tests/integration_tests/dashboards/filter_state/api_tests.py +++ b/tests/integration_tests/dashboards/filter_state/api_tests.py @@ -22,10 +22,10 @@ from flask.ctx import AppContext from flask_appbuilder.security.sqla.models import User from sqlalchemy.orm import Session -from superset.dashboards.commands.exceptions import DashboardAccessDeniedError +from superset.commands.dashboard.exceptions import DashboardAccessDeniedError +from superset.commands.temporary_cache.entry import Entry from superset.extensions import cache_manager from superset.models.dashboard import Dashboard -from superset.temporary_cache.commands.entry import Entry from superset.temporary_cache.utils import cache_key from tests.integration_tests.fixtures.world_bank_dashboard import ( load_world_bank_dashboard_with_slices, diff --git a/tests/integration_tests/dashboards/permalink/api_tests.py b/tests/integration_tests/dashboards/permalink/api_tests.py index 3c560a446..a49f1e6f4 100644 --- a/tests/integration_tests/dashboards/permalink/api_tests.py +++ b/tests/integration_tests/dashboards/permalink/api_tests.py @@ -23,7 +23,7 @@ from flask_appbuilder.security.sqla.models import User from sqlalchemy.orm import Session from superset import db -from superset.dashboards.commands.exceptions import DashboardAccessDeniedError +from superset.commands.dashboard.exceptions import DashboardAccessDeniedError from superset.key_value.models import KeyValueEntry from superset.key_value.types import KeyValueResource from superset.key_value.utils import decode_permalink_id diff --git a/tests/integration_tests/dashboards/security/security_rbac_tests.py b/tests/integration_tests/dashboards/security/security_rbac_tests.py index 8b7f2ad1e..792c9d171 100644 --- a/tests/integration_tests/dashboards/security/security_rbac_tests.py +++ b/tests/integration_tests/dashboards/security/security_rbac_tests.py @@ -21,8 +21,8 @@ from unittest.mock import patch import pytest +from superset.commands.dashboard.exceptions import DashboardForbiddenError from superset.daos.dashboard import DashboardDAO -from superset.dashboards.commands.exceptions import DashboardForbiddenError from superset.utils.core import backend, override_user from tests.integration_tests.conftest import with_feature_flags from tests.integration_tests.dashboards.dashboard_test_utils import * diff --git a/tests/integration_tests/databases/api_tests.py b/tests/integration_tests/databases/api_tests.py index cbdacc8f3..6e6f6e15b 100644 --- a/tests/integration_tests/databases/api_tests.py +++ b/tests/integration_tests/databases/api_tests.py @@ -288,9 +288,9 @@ class TestDatabaseApi(SupersetTestCase): db.session.commit() @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") @mock.patch( "superset.models.core.Database.get_all_schema_names", ) @@ -336,10 +336,10 @@ class TestDatabaseApi(SupersetTestCase): db.session.commit() @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") - @mock.patch("superset.databases.commands.update.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") + @mock.patch("superset.commands.database.update.is_feature_enabled") @mock.patch( "superset.models.core.Database.get_all_schema_names", ) @@ -397,10 +397,10 @@ class TestDatabaseApi(SupersetTestCase): db.session.commit() @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") - @mock.patch("superset.databases.commands.update.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") + @mock.patch("superset.commands.database.update.is_feature_enabled") @mock.patch( "superset.models.core.Database.get_all_schema_names", ) @@ -477,12 +477,12 @@ class TestDatabaseApi(SupersetTestCase): db.session.commit() @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) @mock.patch( "superset.models.core.Database.get_all_schema_names", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") def test_cascade_delete_ssh_tunnel( self, mock_test_connection_database_command_run, @@ -531,9 +531,9 @@ class TestDatabaseApi(SupersetTestCase): assert model_ssh_tunnel is None @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") @mock.patch( "superset.models.core.Database.get_all_schema_names", ) @@ -582,9 +582,9 @@ class TestDatabaseApi(SupersetTestCase): assert model is None @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) - @mock.patch("superset.databases.commands.create.is_feature_enabled") + @mock.patch("superset.commands.database.create.is_feature_enabled") @mock.patch( "superset.models.core.Database.get_all_schema_names", ) @@ -637,7 +637,7 @@ class TestDatabaseApi(SupersetTestCase): db.session.commit() @mock.patch( - "superset.databases.commands.test_connection.TestConnectionDatabaseCommand.run", + "superset.commands.database.test_connection.TestConnectionDatabaseCommand.run", ) @mock.patch( "superset.models.core.Database.get_all_schema_names", @@ -2005,10 +2005,10 @@ class TestDatabaseApi(SupersetTestCase): app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = False @mock.patch( - "superset.databases.commands.test_connection.DatabaseDAO.build_db_for_connection_test", + "superset.commands.database.test_connection.DatabaseDAO.build_db_for_connection_test", ) @mock.patch( - "superset.databases.commands.test_connection.event_logger", + "superset.commands.database.test_connection.event_logger", ) def test_test_connection_failed_invalid_hostname( self, mock_event_logger, mock_build_db @@ -3748,7 +3748,7 @@ class TestDatabaseApi(SupersetTestCase): }, ) - @patch("superset.databases.commands.validate_sql.get_validator_by_name") + @patch("superset.commands.database.validate_sql.get_validator_by_name") @patch.dict( "superset.config.SQL_VALIDATORS_BY_ENGINE", PRESTO_SQL_VALIDATORS_BY_ENGINE, diff --git a/tests/integration_tests/databases/commands_tests.py b/tests/integration_tests/databases/commands_tests.py index d5946d8b6..b46e1b7ea 100644 --- a/tests/integration_tests/databases/commands_tests.py +++ b/tests/integration_tests/databases/commands_tests.py @@ -23,11 +23,8 @@ from func_timeout import FunctionTimedOut from sqlalchemy.exc import DBAPIError from superset import db, event_logger, security_manager -from superset.commands.exceptions import CommandInvalidError -from superset.commands.importers.exceptions import IncorrectVersionError -from superset.connectors.sqla.models import SqlaTable -from superset.databases.commands.create import CreateDatabaseCommand -from superset.databases.commands.exceptions import ( +from superset.commands.database.create import CreateDatabaseCommand +from superset.commands.database.exceptions import ( DatabaseInvalidError, DatabaseNotFoundError, DatabaseSecurityUnsafeError, @@ -35,11 +32,14 @@ from superset.databases.commands.exceptions import ( DatabaseTestConnectionDriverError, DatabaseTestConnectionUnexpectedError, ) -from superset.databases.commands.export import ExportDatabasesCommand -from superset.databases.commands.importers.v1 import ImportDatabasesCommand -from superset.databases.commands.tables import TablesDatabaseCommand -from superset.databases.commands.test_connection import TestConnectionDatabaseCommand -from superset.databases.commands.validate import ValidateDatabaseParametersCommand +from superset.commands.database.export import ExportDatabasesCommand +from superset.commands.database.importers.v1 import ImportDatabasesCommand +from superset.commands.database.tables import TablesDatabaseCommand +from superset.commands.database.test_connection import TestConnectionDatabaseCommand +from superset.commands.database.validate import ValidateDatabaseParametersCommand +from superset.commands.exceptions import CommandInvalidError +from superset.commands.importers.exceptions import IncorrectVersionError +from superset.connectors.sqla.models import SqlaTable from superset.databases.schemas import DatabaseTestConnectionSchema from superset.databases.ssh_tunnel.models import SSHTunnel from superset.errors import ErrorLevel, SupersetError, SupersetErrorType @@ -75,7 +75,7 @@ from tests.integration_tests.fixtures.importexport import ( class TestCreateDatabaseCommand(SupersetTestCase): - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_create_duplicate_error(self, mock_g, mock_logger): example_db = get_example_database() @@ -94,7 +94,7 @@ class TestCreateDatabaseCommand(SupersetTestCase): "DatabaseRequiredFieldValidationError" ) - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_multiple_error_logging(self, mock_g, mock_logger): mock_g.user = security_manager.find_user("admin") @@ -834,7 +834,7 @@ class TestImportDatabasesCommand(SupersetTestCase): } } - @patch("superset.databases.commands.importers.v1.import_dataset") + @patch("superset.commands.database.importers.v1.import_dataset") def test_import_v1_rollback(self, mock_import_dataset): """Test than on an exception everything is rolled back""" num_databases = db.session.query(Database).count() @@ -860,7 +860,7 @@ class TestImportDatabasesCommand(SupersetTestCase): class TestTestConnectionDatabaseCommand(SupersetTestCase): @patch("superset.daos.database.Database._get_sqla_engine") - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_connection_db_exception( self, mock_g, mock_event_logger, mock_get_sqla_engine @@ -881,7 +881,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): mock_event_logger.assert_called() @patch("superset.daos.database.Database._get_sqla_engine") - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_connection_do_ping_exception( self, mock_g, mock_event_logger, mock_get_sqla_engine @@ -903,8 +903,8 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): == SupersetErrorType.GENERIC_DB_ENGINE_ERROR ) - @patch("superset.databases.commands.test_connection.func_timeout") - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.func_timeout") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_connection_do_ping_timeout( self, mock_g, mock_event_logger, mock_func_timeout @@ -926,7 +926,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): ) @patch("superset.daos.database.Database._get_sqla_engine") - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_connection_superset_security_connection( self, mock_g, mock_event_logger, mock_get_sqla_engine @@ -949,7 +949,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): mock_event_logger.assert_called() @patch("superset.daos.database.Database._get_sqla_engine") - @patch("superset.databases.commands.test_connection.event_logger.log_with_context") + @patch("superset.commands.database.test_connection.event_logger.log_with_context") @patch("superset.utils.core.g") def test_connection_db_api_exc( self, mock_g, mock_event_logger, mock_get_sqla_engine @@ -975,7 +975,7 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase): @patch("superset.db_engine_specs.base.is_hostname_valid") @patch("superset.db_engine_specs.base.is_port_open") -@patch("superset.databases.commands.validate.DatabaseDAO") +@patch("superset.commands.database.validate.DatabaseDAO") def test_validate(DatabaseDAO, is_port_open, is_hostname_valid, app_context): """ Test parameter validation. diff --git a/tests/integration_tests/databases/ssh_tunnel/commands/commands_tests.py b/tests/integration_tests/databases/ssh_tunnel/commands/commands_tests.py index 64bc0d857..1cd9afcc8 100644 --- a/tests/integration_tests/databases/ssh_tunnel/commands/commands_tests.py +++ b/tests/integration_tests/databases/ssh_tunnel/commands/commands_tests.py @@ -20,13 +20,13 @@ from unittest.mock import patch import pytest from superset import security_manager -from superset.databases.ssh_tunnel.commands.create import CreateSSHTunnelCommand -from superset.databases.ssh_tunnel.commands.delete import DeleteSSHTunnelCommand -from superset.databases.ssh_tunnel.commands.exceptions import ( +from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand +from superset.commands.database.ssh_tunnel.delete import DeleteSSHTunnelCommand +from superset.commands.database.ssh_tunnel.exceptions import ( SSHTunnelInvalidError, SSHTunnelNotFoundError, ) -from superset.databases.ssh_tunnel.commands.update import UpdateSSHTunnelCommand +from superset.commands.database.ssh_tunnel.update import UpdateSSHTunnelCommand from tests.integration_tests.base_tests import SupersetTestCase @@ -67,7 +67,7 @@ class TestUpdateSSHTunnelCommand(SupersetTestCase): class TestDeleteSSHTunnelCommand(SupersetTestCase): @mock.patch("superset.utils.core.g") - @mock.patch("superset.databases.ssh_tunnel.commands.delete.is_feature_enabled") + @mock.patch("superset.commands.database.ssh_tunnel.delete.is_feature_enabled") def test_delete_ssh_tunnel_not_found(self, mock_g, mock_delete_is_feature_enabled): mock_g.user = security_manager.find_user("admin") mock_delete_is_feature_enabled.return_value = True diff --git a/tests/integration_tests/datasets/api_tests.py b/tests/integration_tests/datasets/api_tests.py index f060d3673..d96989548 100644 --- a/tests/integration_tests/datasets/api_tests.py +++ b/tests/integration_tests/datasets/api_tests.py @@ -30,13 +30,13 @@ from sqlalchemy.orm import joinedload from sqlalchemy.sql import func from superset import app +from superset.commands.dataset.exceptions import DatasetCreateFailedError from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn from superset.daos.exceptions import ( DAOCreateFailedError, DAODeleteFailedError, DAOUpdateFailedError, ) -from superset.datasets.commands.exceptions import DatasetCreateFailedError from superset.datasets.models import Dataset from superset.extensions import db, security_manager from superset.models.core import Database @@ -2458,7 +2458,7 @@ class TestDatasetApi(SupersetTestCase): response = json.loads(rv.data.decode("utf-8")) self.assertEqual(response["message"], {"database": ["Database does not exist"]}) - @patch("superset.datasets.commands.create.CreateDatasetCommand.run") + @patch("superset.commands.dataset.create.CreateDatasetCommand.run") def test_get_or_create_dataset_create_fails(self, command_run_mock): """ Dataset API: Test get or create endpoint when create fails diff --git a/tests/integration_tests/datasets/commands_tests.py b/tests/integration_tests/datasets/commands_tests.py index a718c81e2..1ea554a81 100644 --- a/tests/integration_tests/datasets/commands_tests.py +++ b/tests/integration_tests/datasets/commands_tests.py @@ -23,19 +23,19 @@ import yaml from sqlalchemy.exc import SQLAlchemyError from superset import db, security_manager -from superset.commands.exceptions import CommandInvalidError -from superset.commands.importers.exceptions import IncorrectVersionError -from superset.connectors.sqla.models import SqlaTable -from superset.databases.commands.importers.v1 import ImportDatabasesCommand -from superset.datasets.commands.create import CreateDatasetCommand -from superset.datasets.commands.exceptions import ( +from superset.commands.database.importers.v1 import ImportDatabasesCommand +from superset.commands.dataset.create import CreateDatasetCommand +from superset.commands.dataset.exceptions import ( DatasetInvalidError, DatasetNotFoundError, WarmUpCacheTableNotFoundError, ) -from superset.datasets.commands.export import ExportDatasetsCommand -from superset.datasets.commands.importers import v0, v1 -from superset.datasets.commands.warm_up_cache import DatasetWarmUpCacheCommand +from superset.commands.dataset.export import ExportDatasetsCommand +from superset.commands.dataset.importers import v0, v1 +from superset.commands.dataset.warm_up_cache import DatasetWarmUpCacheCommand +from superset.commands.exceptions import CommandInvalidError +from superset.commands.importers.exceptions import IncorrectVersionError +from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.slice import Slice from superset.utils.core import get_example_default_schema @@ -339,7 +339,7 @@ class TestImportDatasetsCommand(SupersetTestCase): db.session.delete(dataset) db.session.commit() - @patch("superset.datasets.commands.importers.v1.utils.g") + @patch("superset.commands.dataset.importers.v1.utils.g") @patch("superset.security.manager.g") @pytest.mark.usefixtures("load_energy_table_with_slice") def test_import_v1_dataset(self, sm_g, utils_g): diff --git a/tests/integration_tests/datasource_tests.py b/tests/integration_tests/datasource_tests.py index 802c67e85..5ab81b58d 100644 --- a/tests/integration_tests/datasource_tests.py +++ b/tests/integration_tests/datasource_tests.py @@ -24,11 +24,11 @@ import prison import pytest from superset import app, db +from superset.commands.dataset.exceptions import DatasetNotFoundError 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.daos.exceptions import DatasourceNotFound, DatasourceTypeNotSupportedError -from superset.datasets.commands.exceptions import DatasetNotFoundError from superset.exceptions import SupersetGenericDBErrorException from superset.models.core import Database from superset.utils.core import backend, get_example_default_schema diff --git a/tests/integration_tests/explore/api_tests.py b/tests/integration_tests/explore/api_tests.py index 50606257c..e37200e31 100644 --- a/tests/integration_tests/explore/api_tests.py +++ b/tests/integration_tests/explore/api_tests.py @@ -21,9 +21,9 @@ import pytest from flask_appbuilder.security.sqla.models import User from sqlalchemy.orm import Session +from superset.commands.explore.form_data.state import TemporaryExploreState from superset.connectors.sqla.models import SqlaTable from superset.explore.exceptions import DatasetAccessDeniedError -from superset.explore.form_data.commands.state import TemporaryExploreState from superset.extensions import cache_manager from superset.models.slice import Slice from tests.integration_tests.fixtures.world_bank_dashboard import ( diff --git a/tests/integration_tests/explore/form_data/api_tests.py b/tests/integration_tests/explore/form_data/api_tests.py index 0e73d0b51..5dbd67d4f 100644 --- a/tests/integration_tests/explore/form_data/api_tests.py +++ b/tests/integration_tests/explore/form_data/api_tests.py @@ -21,9 +21,9 @@ import pytest from flask_appbuilder.security.sqla.models import User from sqlalchemy.orm import Session +from superset.commands.dataset.exceptions import DatasetAccessDeniedError +from superset.commands.explore.form_data.state import TemporaryExploreState from superset.connectors.sqla.models import SqlaTable -from superset.datasets.commands.exceptions import DatasetAccessDeniedError -from superset.explore.form_data.commands.state import TemporaryExploreState from superset.extensions import cache_manager from superset.models.slice import Slice from superset.utils.core import DatasourceType diff --git a/tests/integration_tests/explore/form_data/commands_tests.py b/tests/integration_tests/explore/form_data/commands_tests.py index 18dd8415f..781c4fdbb 100644 --- a/tests/integration_tests/explore/form_data/commands_tests.py +++ b/tests/integration_tests/explore/form_data/commands_tests.py @@ -22,12 +22,12 @@ import pytest from superset import app, db, security, security_manager from superset.commands.exceptions import DatasourceTypeInvalidError +from superset.commands.explore.form_data.create import CreateFormDataCommand +from superset.commands.explore.form_data.delete import DeleteFormDataCommand +from superset.commands.explore.form_data.get import GetFormDataCommand +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.form_data.update import UpdateFormDataCommand from superset.connectors.sqla.models import SqlaTable -from superset.explore.form_data.commands.create import CreateFormDataCommand -from superset.explore.form_data.commands.delete import DeleteFormDataCommand -from superset.explore.form_data.commands.get import GetFormDataCommand -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.form_data.commands.update import UpdateFormDataCommand from superset.models.slice import Slice from superset.models.sql_lab import Query from superset.utils.core import DatasourceType, get_example_default_schema diff --git a/tests/integration_tests/explore/permalink/commands_tests.py b/tests/integration_tests/explore/permalink/commands_tests.py index eace978d7..5402a419b 100644 --- a/tests/integration_tests/explore/permalink/commands_tests.py +++ b/tests/integration_tests/explore/permalink/commands_tests.py @@ -21,10 +21,10 @@ import pytest from superset import app, db, security, security_manager from superset.commands.exceptions import DatasourceTypeInvalidError +from superset.commands.explore.form_data.parameters import CommandParameters +from superset.commands.explore.permalink.create import CreateExplorePermalinkCommand +from superset.commands.explore.permalink.get import GetExplorePermalinkCommand from superset.connectors.sqla.models import SqlaTable -from superset.explore.form_data.commands.parameters import CommandParameters -from superset.explore.permalink.commands.create import CreateExplorePermalinkCommand -from superset.explore.permalink.commands.get import GetExplorePermalinkCommand from superset.key_value.utils import decode_permalink_id from superset.models.slice import Slice from superset.models.sql_lab import Query @@ -138,8 +138,8 @@ class TestCreatePermalinkDataCommand(SupersetTestCase): assert cache_data.get("datasource") == datasource @patch("superset.security.manager.g") - @patch("superset.key_value.commands.get.GetKeyValueCommand.run") - @patch("superset.explore.permalink.commands.get.decode_permalink_id") + @patch("superset.commands.key_value.get.GetKeyValueCommand.run") + @patch("superset.commands.explore.permalink.get.decode_permalink_id") @pytest.mark.usefixtures("create_dataset", "create_slice") def test_get_permalink_command_with_old_dataset_key( self, decode_id_mock, get_kv_command_mock, mock_g diff --git a/tests/integration_tests/import_export_tests.py b/tests/integration_tests/import_export_tests.py index 5dc8143f7..c195e3a4c 100644 --- a/tests/integration_tests/import_export_tests.py +++ b/tests/integration_tests/import_export_tests.py @@ -32,12 +32,12 @@ from tests.integration_tests.fixtures.energy_dashboard import ( load_energy_table_data, ) from tests.integration_tests.test_app import app -from superset.dashboards.commands.importers.v0 import decode_dashboards +from superset.commands.dashboard.importers.v0 import decode_dashboards from superset import db, security_manager from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn -from superset.dashboards.commands.importers.v0 import import_chart, import_dashboard -from superset.datasets.commands.importers.v0 import import_dataset +from superset.commands.dashboard.importers.v0 import import_chart, import_dashboard +from superset.commands.dataset.importers.v0 import import_dataset from superset.models.dashboard import Dashboard from superset.models.slice import Slice from superset.utils.core import DatasourceType, get_example_default_schema diff --git a/tests/integration_tests/importexport/commands_tests.py b/tests/integration_tests/importexport/commands_tests.py index ceaf09756..9e8f79026 100644 --- a/tests/integration_tests/importexport/commands_tests.py +++ b/tests/integration_tests/importexport/commands_tests.py @@ -21,7 +21,7 @@ import yaml from freezegun import freeze_time from superset import security_manager -from superset.databases.commands.export import ExportDatabasesCommand +from superset.commands.database.export import ExportDatabasesCommand from superset.utils.database import get_example_database from tests.integration_tests.base_tests import SupersetTestCase diff --git a/tests/integration_tests/key_value/commands/create_test.py b/tests/integration_tests/key_value/commands/create_test.py index c7ba076b5..494456fa0 100644 --- a/tests/integration_tests/key_value/commands/create_test.py +++ b/tests/integration_tests/key_value/commands/create_test.py @@ -37,7 +37,7 @@ from tests.integration_tests.key_value.commands.fixtures import ( def test_create_id_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -54,7 +54,7 @@ def test_create_id_entry(app_context: AppContext, admin: User) -> None: def test_create_uuid_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -69,7 +69,7 @@ def test_create_uuid_entry(app_context: AppContext, admin: User) -> None: def test_create_fail_json_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand with pytest.raises(KeyValueCreateFailedError): CreateKeyValueCommand( @@ -80,7 +80,7 @@ def test_create_fail_json_entry(app_context: AppContext, admin: User) -> None: def test_create_pickle_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.create import CreateKeyValueCommand + from superset.commands.key_value.create import CreateKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): diff --git a/tests/integration_tests/key_value/commands/delete_test.py b/tests/integration_tests/key_value/commands/delete_test.py index 3c4892faa..706aab888 100644 --- a/tests/integration_tests/key_value/commands/delete_test.py +++ b/tests/integration_tests/key_value/commands/delete_test.py @@ -58,7 +58,7 @@ def test_delete_id_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.delete import DeleteKeyValueCommand + from superset.commands.key_value.delete import DeleteKeyValueCommand assert DeleteKeyValueCommand(resource=RESOURCE, key=ID_KEY).run() is True @@ -68,7 +68,7 @@ def test_delete_uuid_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.delete import DeleteKeyValueCommand + from superset.commands.key_value.delete import DeleteKeyValueCommand assert DeleteKeyValueCommand(resource=RESOURCE, key=UUID_KEY).run() is True @@ -78,6 +78,6 @@ def test_delete_entry_missing( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.delete import DeleteKeyValueCommand + from superset.commands.key_value.delete import DeleteKeyValueCommand assert DeleteKeyValueCommand(resource=RESOURCE, key=456).run() is False diff --git a/tests/integration_tests/key_value/commands/get_test.py b/tests/integration_tests/key_value/commands/get_test.py index 28a6dd73d..b14c64f75 100644 --- a/tests/integration_tests/key_value/commands/get_test.py +++ b/tests/integration_tests/key_value/commands/get_test.py @@ -38,7 +38,7 @@ if TYPE_CHECKING: def test_get_id_entry(app_context: AppContext, key_value_entry: KeyValueEntry) -> None: - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand value = GetKeyValueCommand(resource=RESOURCE, key=ID_KEY, codec=JSON_CODEC).run() assert value == JSON_VALUE @@ -47,7 +47,7 @@ def test_get_id_entry(app_context: AppContext, key_value_entry: KeyValueEntry) - def test_get_uuid_entry( app_context: AppContext, key_value_entry: KeyValueEntry ) -> None: - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand value = GetKeyValueCommand(resource=RESOURCE, key=UUID_KEY, codec=JSON_CODEC).run() assert value == JSON_VALUE @@ -57,14 +57,14 @@ def test_get_id_entry_missing( app_context: AppContext, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand value = GetKeyValueCommand(resource=RESOURCE, key=456, codec=JSON_CODEC).run() assert value is None def test_get_expired_entry(app_context: AppContext) -> None: - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand from superset.key_value.models import KeyValueEntry entry = KeyValueEntry( @@ -83,7 +83,7 @@ def test_get_expired_entry(app_context: AppContext) -> None: def test_get_future_expiring_entry(app_context: AppContext) -> None: - from superset.key_value.commands.get import GetKeyValueCommand + from superset.commands.key_value.get import GetKeyValueCommand from superset.key_value.models import KeyValueEntry id_ = 789 diff --git a/tests/integration_tests/key_value/commands/update_test.py b/tests/integration_tests/key_value/commands/update_test.py index 816a6f857..62d118b19 100644 --- a/tests/integration_tests/key_value/commands/update_test.py +++ b/tests/integration_tests/key_value/commands/update_test.py @@ -45,7 +45,7 @@ def test_update_id_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.update import UpdateKeyValueCommand + from superset.commands.key_value.update import UpdateKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -67,7 +67,7 @@ def test_update_uuid_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.update import UpdateKeyValueCommand + from superset.commands.key_value.update import UpdateKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -85,7 +85,7 @@ def test_update_uuid_entry( def test_update_missing_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.update import UpdateKeyValueCommand + from superset.commands.key_value.update import UpdateKeyValueCommand with override_user(admin): key = UpdateKeyValueCommand( diff --git a/tests/integration_tests/key_value/commands/upsert_test.py b/tests/integration_tests/key_value/commands/upsert_test.py index 9b094ef65..b23ddaee9 100644 --- a/tests/integration_tests/key_value/commands/upsert_test.py +++ b/tests/integration_tests/key_value/commands/upsert_test.py @@ -45,7 +45,7 @@ def test_upsert_id_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.upsert import UpsertKeyValueCommand + from superset.commands.key_value.upsert import UpsertKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -67,7 +67,7 @@ def test_upsert_uuid_entry( admin: User, key_value_entry: KeyValueEntry, ) -> None: - from superset.key_value.commands.upsert import UpsertKeyValueCommand + from superset.commands.key_value.upsert import UpsertKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): @@ -85,7 +85,7 @@ def test_upsert_uuid_entry( def test_upsert_missing_entry(app_context: AppContext, admin: User) -> None: - from superset.key_value.commands.upsert import UpsertKeyValueCommand + from superset.commands.key_value.upsert import UpsertKeyValueCommand from superset.key_value.models import KeyValueEntry with override_user(admin): diff --git a/tests/integration_tests/queries/saved_queries/commands_tests.py b/tests/integration_tests/queries/saved_queries/commands_tests.py index 5c7b86220..cccc40998 100644 --- a/tests/integration_tests/queries/saved_queries/commands_tests.py +++ b/tests/integration_tests/queries/saved_queries/commands_tests.py @@ -23,13 +23,11 @@ import yaml from superset import db, security_manager from superset.commands.exceptions import CommandInvalidError from superset.commands.importers.exceptions import IncorrectVersionError +from superset.commands.query.exceptions import SavedQueryNotFoundError +from superset.commands.query.export import ExportSavedQueriesCommand +from superset.commands.query.importers.v1 import ImportSavedQueriesCommand from superset.models.core import Database from superset.models.sql_lab import SavedQuery -from superset.queries.saved_queries.commands.exceptions import SavedQueryNotFoundError -from superset.queries.saved_queries.commands.export import ExportSavedQueriesCommand -from superset.queries.saved_queries.commands.importers.v1 import ( - ImportSavedQueriesCommand, -) from superset.utils.database import get_example_database from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.importexport import ( diff --git a/tests/integration_tests/reports/alert_tests.py b/tests/integration_tests/reports/alert_tests.py index 76890a19e..6664d65a9 100644 --- a/tests/integration_tests/reports/alert_tests.py +++ b/tests/integration_tests/reports/alert_tests.py @@ -22,7 +22,7 @@ import pandas as pd import pytest from pytest_mock import MockFixture -from superset.reports.commands.exceptions import AlertQueryError +from superset.commands.report.exceptions import AlertQueryError from superset.reports.models import ReportCreationMethod, ReportScheduleType from superset.tasks.types import ExecutorType from superset.utils.database import get_example_database @@ -64,7 +64,7 @@ def test_execute_query_as_report_executor( app_context: None, get_user, ) -> None: - from superset.reports.commands.alert import AlertCommand + from superset.commands.report.alert import AlertCommand from superset.reports.models import ReportSchedule with app.app_context(): @@ -86,7 +86,7 @@ def test_execute_query_as_report_executor( ) command = AlertCommand(report_schedule=report_schedule) override_user_mock = mocker.patch( - "superset.reports.commands.alert.override_user" + "superset.commands.report.alert.override_user" ) cm = ( pytest.raises(type(expected_result)) @@ -103,10 +103,10 @@ def test_execute_query_as_report_executor( def test_execute_query_succeeded_no_retry( mocker: MockFixture, app_context: None ) -> None: - from superset.reports.commands.alert import AlertCommand + from superset.commands.report.alert import AlertCommand execute_query_mock = mocker.patch( - "superset.reports.commands.alert.AlertCommand._execute_query", + "superset.commands.report.alert.AlertCommand._execute_query", side_effect=lambda: pd.DataFrame([{"sample_col": 0}]), ) @@ -120,10 +120,10 @@ def test_execute_query_succeeded_no_retry( def test_execute_query_succeeded_with_retries( mocker: MockFixture, app_context: None ) -> None: - from superset.reports.commands.alert import AlertCommand, AlertQueryError + from superset.commands.report.alert import AlertCommand, AlertQueryError execute_query_mock = mocker.patch( - "superset.reports.commands.alert.AlertCommand._execute_query" + "superset.commands.report.alert.AlertCommand._execute_query" ) query_executed_count = 0 @@ -150,10 +150,10 @@ def test_execute_query_succeeded_with_retries( def test_execute_query_failed_no_retry(mocker: MockFixture, app_context: None) -> None: - from superset.reports.commands.alert import AlertCommand, AlertQueryTimeout + from superset.commands.report.alert import AlertCommand, AlertQueryTimeout execute_query_mock = mocker.patch( - "superset.reports.commands.alert.AlertCommand._execute_query" + "superset.commands.report.alert.AlertCommand._execute_query" ) def _mocked_execute_query() -> None: @@ -172,10 +172,10 @@ def test_execute_query_failed_no_retry(mocker: MockFixture, app_context: None) - def test_execute_query_failed_max_retries( mocker: MockFixture, app_context: None ) -> None: - from superset.reports.commands.alert import AlertCommand, AlertQueryError + from superset.commands.report.alert import AlertCommand, AlertQueryError execute_query_mock = mocker.patch( - "superset.reports.commands.alert.AlertCommand._execute_query" + "superset.commands.report.alert.AlertCommand._execute_query" ) def _mocked_execute_query() -> None: diff --git a/tests/integration_tests/reports/commands/create_dashboard_report_tests.py b/tests/integration_tests/reports/commands/create_dashboard_report_tests.py index 81945c18a..a7f3001aa 100644 --- a/tests/integration_tests/reports/commands/create_dashboard_report_tests.py +++ b/tests/integration_tests/reports/commands/create_dashboard_report_tests.py @@ -18,9 +18,9 @@ import pytest from superset import db +from superset.commands.report.create import CreateReportScheduleCommand +from superset.commands.report.exceptions import ReportScheduleInvalidError from superset.models.dashboard import Dashboard -from superset.reports.commands.create import CreateReportScheduleCommand -from superset.reports.commands.exceptions import ReportScheduleInvalidError from superset.reports.models import ( ReportCreationMethod, ReportRecipientType, diff --git a/tests/integration_tests/reports/commands/execute_dashboard_report_tests.py b/tests/integration_tests/reports/commands/execute_dashboard_report_tests.py index fe2036576..68150a9c3 100644 --- a/tests/integration_tests/reports/commands/execute_dashboard_report_tests.py +++ b/tests/integration_tests/reports/commands/execute_dashboard_report_tests.py @@ -20,11 +20,9 @@ from uuid import uuid4 from flask import current_app -from superset.dashboards.permalink.commands.create import ( - CreateDashboardPermalinkCommand, -) +from superset.commands.dashboard.permalink.create import CreateDashboardPermalinkCommand +from superset.commands.report.execute import AsyncExecuteReportScheduleCommand from superset.models.dashboard import Dashboard -from superset.reports.commands.execute import AsyncExecuteReportScheduleCommand from superset.reports.models import ReportSourceFormat from tests.integration_tests.fixtures.tabbed_dashboard import tabbed_dashboard from tests.integration_tests.reports.utils import create_dashboard_report @@ -32,10 +30,10 @@ from tests.integration_tests.reports.utils import create_dashboard_report @patch("superset.reports.notifications.email.send_email_smtp") @patch( - "superset.reports.commands.execute.DashboardScreenshot", + "superset.commands.report.execute.DashboardScreenshot", ) @patch( - "superset.dashboards.permalink.commands.create.CreateDashboardPermalinkCommand.run" + "superset.commands.dashboard.permalink.create.CreateDashboardPermalinkCommand.run" ) def test_report_for_dashboard_with_tabs( create_dashboard_permalink_mock: MagicMock, @@ -70,10 +68,10 @@ def test_report_for_dashboard_with_tabs( @patch("superset.reports.notifications.email.send_email_smtp") @patch( - "superset.reports.commands.execute.DashboardScreenshot", + "superset.commands.report.execute.DashboardScreenshot", ) @patch( - "superset.dashboards.permalink.commands.create.CreateDashboardPermalinkCommand.run" + "superset.commands.dashboard.permalink.create.CreateDashboardPermalinkCommand.run" ) def test_report_with_header_data( create_dashboard_permalink_mock: MagicMock, diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index 11ec17012..939c9c0cf 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -39,11 +39,7 @@ from slack_sdk.errors import ( from sqlalchemy.sql import func from superset import db -from superset.exceptions import SupersetException -from superset.models.core import Database -from superset.models.dashboard import Dashboard -from superset.models.slice import Slice -from superset.reports.commands.exceptions import ( +from superset.commands.report.exceptions import ( AlertQueryError, AlertQueryInvalidTypeError, AlertQueryMultipleColumnsError, @@ -58,11 +54,15 @@ from superset.reports.commands.exceptions import ( ReportScheduleSystemErrorsException, ReportScheduleWorkingTimeoutError, ) -from superset.reports.commands.execute import ( +from superset.commands.report.execute import ( AsyncExecuteReportScheduleCommand, BaseReportState, ) -from superset.reports.commands.log_prune import AsyncPruneReportScheduleLogCommand +from superset.commands.report.log_prune import AsyncPruneReportScheduleLogCommand +from superset.exceptions import SupersetException +from superset.models.core import Database +from superset.models.dashboard import Dashboard +from superset.models.slice import Slice from superset.reports.models import ( ReportDataFormat, ReportExecutionLog, @@ -1607,7 +1607,7 @@ def test_soft_timeout_alert(email_mock, create_alert_email_chart): """ from celery.exceptions import SoftTimeLimitExceeded - from superset.reports.commands.exceptions import AlertQueryTimeout + from superset.commands.report.exceptions import AlertQueryTimeout with patch.object( create_alert_email_chart.database.db_engine_spec, "execute", return_value=None @@ -1748,7 +1748,7 @@ def test_fail_screenshot(screenshot_mock, email_mock, create_report_email_chart) """ from celery.exceptions import SoftTimeLimitExceeded - from superset.reports.commands.exceptions import AlertQueryTimeout + from superset.commands.report.exceptions import AlertQueryTimeout screenshot_mock.side_effect = Exception("Unexpected error") with pytest.raises(ReportScheduleScreenshotFailedError): @@ -1963,8 +1963,8 @@ def test_prune_log_soft_time_out(bulk_delete_logs, create_report_email_dashboard assert str(excinfo.value) == "SoftTimeLimitExceeded()" -@patch("superset.reports.commands.execute.logger") -@patch("superset.reports.commands.execute.create_notification") +@patch("superset.commands.report.execute.logger") +@patch("superset.commands.report.execute.create_notification") def test__send_with_client_errors(notification_mock, logger_mock): notification_content = "I am some content" recipients = ["test@foo.com"] @@ -1978,8 +1978,8 @@ def test__send_with_client_errors(notification_mock, logger_mock): ) -@patch("superset.reports.commands.execute.logger") -@patch("superset.reports.commands.execute.create_notification") +@patch("superset.commands.report.execute.logger") +@patch("superset.commands.report.execute.create_notification") def test__send_with_multiple_errors(notification_mock, logger_mock): notification_content = "I am some content" recipients = ["test@foo.com", "test2@bar.com"] @@ -2005,8 +2005,8 @@ def test__send_with_multiple_errors(notification_mock, logger_mock): ) -@patch("superset.reports.commands.execute.logger") -@patch("superset.reports.commands.execute.create_notification") +@patch("superset.commands.report.execute.logger") +@patch("superset.commands.report.execute.create_notification") def test__send_with_server_errors(notification_mock, logger_mock): notification_content = "I am some content" recipients = ["test@foo.com"] diff --git a/tests/integration_tests/reports/scheduler_tests.py b/tests/integration_tests/reports/scheduler_tests.py index 29dd58273..ee93ef48a 100644 --- a/tests/integration_tests/reports/scheduler_tests.py +++ b/tests/integration_tests/reports/scheduler_tests.py @@ -154,11 +154,11 @@ def test_scheduler_feature_flag_off(execute_mock, is_feature_enabled, owners): @pytest.mark.usefixtures("owners") -@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.__init__") -@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.run") +@patch("superset.commands.report.execute.AsyncExecuteReportScheduleCommand.__init__") +@patch("superset.commands.report.execute.AsyncExecuteReportScheduleCommand.run") @patch("superset.tasks.scheduler.execute.update_state") def test_execute_task(update_state_mock, command_mock, init_mock, owners): - from superset.reports.commands.exceptions import ReportScheduleUnexpectedError + from superset.commands.report.exceptions import ReportScheduleUnexpectedError with app.app_context(): report_schedule = insert_report_schedule( @@ -179,8 +179,8 @@ def test_execute_task(update_state_mock, command_mock, init_mock, owners): @pytest.mark.usefixtures("owners") -@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.__init__") -@patch("superset.reports.commands.execute.AsyncExecuteReportScheduleCommand.run") +@patch("superset.commands.report.execute.AsyncExecuteReportScheduleCommand.__init__") +@patch("superset.commands.report.execute.AsyncExecuteReportScheduleCommand.run") @patch("superset.tasks.scheduler.execute.update_state") @patch("superset.utils.log.logger") def test_execute_task_with_command_exception( diff --git a/tests/integration_tests/sql_lab/api_tests.py b/tests/integration_tests/sql_lab/api_tests.py index 49dd4ea32..da050c236 100644 --- a/tests/integration_tests/sql_lab/api_tests.py +++ b/tests/integration_tests/sql_lab/api_tests.py @@ -209,7 +209,7 @@ class TestSqlLabApi(SupersetTestCase): return_value=formatter_response ) - with mock.patch("superset.sqllab.commands.estimate.db") as mock_superset_db: + with mock.patch("superset.commands.sql_lab.estimate.db") as mock_superset_db: mock_superset_db.session.query().get.return_value = db_mock data = {"database_id": 1, "sql": "SELECT 1"} @@ -236,7 +236,7 @@ class TestSqlLabApi(SupersetTestCase): self.assertDictEqual(resp_data, success_resp) self.assertEqual(rv.status_code, 200) - @mock.patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @mock.patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_execute_required_params(self): self.login() client_id = f"{random.getrandbits(64)}"[:10] @@ -276,7 +276,7 @@ class TestSqlLabApi(SupersetTestCase): self.assertDictEqual(resp_data, failed_resp) self.assertEqual(rv.status_code, 400) - @mock.patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @mock.patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_execute_valid_request(self) -> None: from superset import sql_lab as core @@ -320,9 +320,9 @@ class TestSqlLabApi(SupersetTestCase): self.delete_fake_db_for_macros() - @mock.patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @mock.patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_get_results_with_display_limit(self): - from superset.sqllab.commands import results as command + from superset.commands.sql_lab import results as command command.results_backend = mock.Mock() self.login() @@ -355,7 +355,7 @@ class TestSqlLabApi(SupersetTestCase): compressed = utils.zlib_compress(serialized_payload) command.results_backend.get.return_value = compressed - with mock.patch("superset.sqllab.commands.results.db") as mock_superset_db: + with mock.patch("superset.commands.sql_lab.results.db") as mock_superset_db: mock_superset_db.session.query().filter_by().one_or_none.return_value = ( query_mock ) diff --git a/tests/integration_tests/sql_lab/commands_tests.py b/tests/integration_tests/sql_lab/commands_tests.py index d76924a8f..11eb5de0c 100644 --- a/tests/integration_tests/sql_lab/commands_tests.py +++ b/tests/integration_tests/sql_lab/commands_tests.py @@ -22,6 +22,7 @@ import pytest from flask_babel import gettext as __ from superset import app, db, sql_lab +from superset.commands.sql_lab import estimate, export, results from superset.common.db_query_status import QueryStatus from superset.errors import ErrorLevel, SupersetError, SupersetErrorType from superset.exceptions import ( @@ -32,7 +33,6 @@ from superset.exceptions import ( ) from superset.models.core import Database from superset.models.sql_lab import Query -from superset.sqllab.commands import estimate, export, results from superset.sqllab.limiting_factor import LimitingFactor from superset.sqllab.schemas import EstimateQueryCostSchema from superset.utils import core as utils @@ -47,7 +47,7 @@ class TestQueryEstimationCommand(SupersetTestCase): data: EstimateQueryCostSchema = schema.dump(params) command = estimate.QueryEstimationCommand(data) - with mock.patch("superset.sqllab.commands.estimate.db") as mock_superset_db: + with mock.patch("superset.commands.sql_lab.estimate.db") as mock_superset_db: mock_superset_db.session.query().get.return_value = None with pytest.raises(SupersetErrorException) as ex_info: command.validate() @@ -79,7 +79,7 @@ class TestQueryEstimationCommand(SupersetTestCase): db_mock.db_engine_spec.query_cost_formatter = mock.Mock(return_value=None) is_feature_enabled.return_value = False - with mock.patch("superset.sqllab.commands.estimate.db") as mock_superset_db: + with mock.patch("superset.commands.sql_lab.estimate.db") as mock_superset_db: mock_superset_db.session.query().get.return_value = db_mock with pytest.raises(SupersetErrorException) as ex_info: command.run() @@ -105,7 +105,7 @@ class TestQueryEstimationCommand(SupersetTestCase): db_mock.db_engine_spec.estimate_query_cost = mock.Mock(return_value=100) db_mock.db_engine_spec.query_cost_formatter = mock.Mock(return_value=payload) - with mock.patch("superset.sqllab.commands.estimate.db") as mock_superset_db: + with mock.patch("superset.commands.sql_lab.estimate.db") as mock_superset_db: mock_superset_db.session.query().get.return_value = db_mock result = command.run() assert result == payload @@ -223,7 +223,7 @@ class TestSqlResultExportCommand(SupersetTestCase): @pytest.mark.usefixtures("create_database_and_query") @patch("superset.models.sql_lab.Query.raise_for_access", lambda _: None) - @patch("superset.sqllab.commands.export.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.export.results_backend_use_msgpack", False) def test_run_with_results_backend(self) -> None: command = export.SqlResultExportCommand("test") @@ -273,8 +273,8 @@ class TestSqlExecutionResultsCommand(SupersetTestCase): db.session.delete(query_obj) db.session.commit() - @patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) - @patch("superset.sqllab.commands.results.results_backend", None) + @patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.results.results_backend", None) def test_validation_no_results_backend(self) -> None: command = results.SqlExecutionResultsCommand("test", 1000) @@ -285,7 +285,7 @@ class TestSqlExecutionResultsCommand(SupersetTestCase): == SupersetErrorType.RESULTS_BACKEND_NOT_CONFIGURED_ERROR ) - @patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_validation_data_cannot_be_retrieved(self) -> None: results.results_backend = mock.Mock() results.results_backend.get.return_value = None @@ -296,7 +296,7 @@ class TestSqlExecutionResultsCommand(SupersetTestCase): command.run() assert ex_info.value.error.error_type == SupersetErrorType.RESULTS_BACKEND_ERROR - @patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_validation_data_not_found(self) -> None: data = [{"col_0": i} for i in range(100)] payload = { @@ -317,7 +317,7 @@ class TestSqlExecutionResultsCommand(SupersetTestCase): assert ex_info.value.error.error_type == SupersetErrorType.RESULTS_BACKEND_ERROR @pytest.mark.usefixtures("create_database_and_query") - @patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_validation_query_not_found(self) -> None: data = [{"col_0": i} for i in range(104)] payload = { @@ -344,7 +344,7 @@ class TestSqlExecutionResultsCommand(SupersetTestCase): ) @pytest.mark.usefixtures("create_database_and_query") - @patch("superset.sqllab.commands.results.results_backend_use_msgpack", False) + @patch("superset.commands.sql_lab.results.results_backend_use_msgpack", False) def test_run_succeeds(self) -> None: data = [{"col_0": i} for i in range(104)] payload = { diff --git a/tests/integration_tests/tags/commands_tests.py b/tests/integration_tests/tags/commands_tests.py index 057d28abe..48abfd31b 100644 --- a/tests/integration_tests/tags/commands_tests.py +++ b/tests/integration_tests/tags/commands_tests.py @@ -22,21 +22,21 @@ import yaml from werkzeug.utils import secure_filename from superset import db, security_manager -from superset.commands.exceptions import CommandInvalidError -from superset.commands.importers.exceptions import IncorrectVersionError -from superset.connectors.sqla.models import SqlaTable -from superset.dashboards.commands.exceptions import DashboardNotFoundError -from superset.dashboards.commands.export import ( +from superset.commands.dashboard.exceptions import DashboardNotFoundError +from superset.commands.dashboard.export import ( append_charts, ExportDashboardsCommand, get_default_position, ) -from superset.dashboards.commands.importers import v0, v1 +from superset.commands.dashboard.importers import v0, v1 +from superset.commands.exceptions import CommandInvalidError +from superset.commands.importers.exceptions import IncorrectVersionError +from superset.commands.tag.create import CreateCustomTagCommand +from superset.commands.tag.delete import DeleteTaggedObjectCommand, DeleteTagsCommand +from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.dashboard import Dashboard from superset.models.slice import Slice -from superset.tags.commands.create import CreateCustomTagCommand -from superset.tags.commands.delete import DeleteTaggedObjectCommand, DeleteTagsCommand from superset.tags.models import ObjectType, Tag, TaggedObject, TagType from tests.integration_tests.base_tests import SupersetTestCase from tests.integration_tests.fixtures.importexport import ( diff --git a/tests/integration_tests/tasks/async_queries_tests.py b/tests/integration_tests/tasks/async_queries_tests.py index 8e6e59575..01880b7a6 100644 --- a/tests/integration_tests/tasks/async_queries_tests.py +++ b/tests/integration_tests/tasks/async_queries_tests.py @@ -21,8 +21,8 @@ from uuid import uuid4 import pytest from celery.exceptions import SoftTimeLimitExceeded -from superset.charts.commands.exceptions import ChartDataQueryFailedError -from superset.charts.data.commands.get_data_command import ChartDataCommand +from superset.commands.chart.data.get_data_command import ChartDataCommand +from superset.commands.chart.exceptions import ChartDataQueryFailedError from superset.exceptions import SupersetException from superset.extensions import async_query_manager, security_manager from tests.integration_tests.base_tests import SupersetTestCase diff --git a/tests/integration_tests/utils_tests.py b/tests/integration_tests/utils_tests.py index 6f8a7ed45..405040e3d 100644 --- a/tests/integration_tests/utils_tests.py +++ b/tests/integration_tests/utils_tests.py @@ -24,7 +24,7 @@ import re from typing import Any, Optional from unittest.mock import Mock, patch -from superset.databases.commands.exceptions import DatabaseInvalidError +from superset.commands.database.exceptions import DatabaseInvalidError from tests.integration_tests.fixtures.birth_names_dashboard import ( load_birth_names_dashboard_with_slices, load_birth_names_data, diff --git a/tests/unit_tests/charts/commands/importers/v1/import_test.py b/tests/unit_tests/charts/commands/importers/v1/import_test.py index 06e0063fe..f0d142644 100644 --- a/tests/unit_tests/charts/commands/importers/v1/import_test.py +++ b/tests/unit_tests/charts/commands/importers/v1/import_test.py @@ -30,7 +30,7 @@ def test_import_chart(mocker: MockFixture, session: Session) -> None: Test importing a chart. """ from superset import security_manager - from superset.charts.commands.importers.v1.utils import import_chart + from superset.commands.chart.importers.v1.utils import import_chart from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.slice import Slice @@ -57,7 +57,7 @@ def test_import_chart_managed_externally(mocker: MockFixture, session: Session) Test importing a chart that is managed externally. """ from superset import security_manager - from superset.charts.commands.importers.v1.utils import import_chart + from superset.commands.chart.importers.v1.utils import import_chart from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.slice import Slice @@ -87,7 +87,7 @@ def test_import_chart_without_permission( Test importing a chart when a user doesn't have permissions to create. """ from superset import security_manager - from superset.charts.commands.importers.v1.utils import import_chart + from superset.commands.chart.importers.v1.utils import import_chart from superset.connectors.sqla.models import SqlaTable from superset.models.core import Database from superset.models.slice import Slice diff --git a/tests/unit_tests/charts/commands/importers/v1/utils_test.py b/tests/unit_tests/charts/commands/importers/v1/utils_test.py index 2addfa301..de3f805d8 100644 --- a/tests/unit_tests/charts/commands/importers/v1/utils_test.py +++ b/tests/unit_tests/charts/commands/importers/v1/utils_test.py @@ -17,7 +17,7 @@ import json -from superset.charts.commands.importers.v1.utils import migrate_chart +from superset.commands.chart.importers.v1.utils import migrate_chart def test_migrate_chart_area() -> None: diff --git a/tests/unit_tests/dashboards/commands/importers/v1/import_test.py b/tests/unit_tests/dashboards/commands/importers/v1/import_test.py index e07a23f6b..67e089775 100644 --- a/tests/unit_tests/dashboards/commands/importers/v1/import_test.py +++ b/tests/unit_tests/dashboards/commands/importers/v1/import_test.py @@ -30,8 +30,8 @@ def test_import_dashboard(mocker: MockFixture, session: Session) -> None: Test importing a dashboard. """ from superset import security_manager + from superset.commands.dashboard.importers.v1.utils import import_dashboard from superset.connectors.sqla.models import SqlaTable - from superset.dashboards.commands.importers.v1.utils import import_dashboard from superset.models.core import Database from superset.models.slice import Slice from tests.integration_tests.fixtures.importexport import dashboard_config @@ -58,8 +58,8 @@ def test_import_dashboard_managed_externally( Test importing a dashboard that is managed externally. """ from superset import security_manager + from superset.commands.dashboard.importers.v1.utils import import_dashboard from superset.connectors.sqla.models import SqlaTable - from superset.dashboards.commands.importers.v1.utils import import_dashboard from superset.models.core import Database from superset.models.slice import Slice from tests.integration_tests.fixtures.importexport import dashboard_config @@ -86,8 +86,8 @@ def test_import_dashboard_without_permission( Test importing a dashboard when a user doesn't have permissions to create. """ from superset import security_manager + from superset.commands.dashboard.importers.v1.utils import import_dashboard from superset.connectors.sqla.models import SqlaTable - from superset.dashboards.commands.importers.v1.utils import import_dashboard from superset.models.core import Database from superset.models.slice import Slice from tests.integration_tests.fixtures.importexport import dashboard_config diff --git a/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py index 60a659159..0e8436295 100644 --- a/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py +++ b/tests/unit_tests/dashboards/commands/importers/v1/utils_test.py @@ -29,7 +29,7 @@ def test_update_id_refs_immune_missing( # pylint: disable=invalid-name immune to filters. The missing chart ID should be simply ignored when the dashboard is imported. """ - from superset.dashboards.commands.importers.v1.utils import update_id_refs + from superset.commands.dashboard.importers.v1.utils import update_id_refs config = { "position": { @@ -83,7 +83,7 @@ def test_update_id_refs_immune_missing( # pylint: disable=invalid-name def test_update_native_filter_config_scope_excluded(): - from superset.dashboards.commands.importers.v1.utils import update_id_refs + from superset.commands.dashboard.importers.v1.utils import update_id_refs config = { "position": { diff --git a/tests/unit_tests/databases/api_test.py b/tests/unit_tests/databases/api_test.py index aa15645dd..28ca123ec 100644 --- a/tests/unit_tests/databases/api_test.py +++ b/tests/unit_tests/databases/api_test.py @@ -396,7 +396,7 @@ def test_delete_ssh_tunnel( mocker.patch("sqlalchemy.engine.URL.get_driver_name", return_value="gsheets") mocker.patch("superset.utils.log.DBEventLogger.log") mocker.patch( - "superset.databases.ssh_tunnel.commands.delete.is_feature_enabled", + "superset.commands.database.ssh_tunnel.delete.is_feature_enabled", return_value=True, ) @@ -472,7 +472,7 @@ def test_delete_ssh_tunnel_not_found( mocker.patch("sqlalchemy.engine.URL.get_driver_name", return_value="gsheets") mocker.patch("superset.utils.log.DBEventLogger.log") mocker.patch( - "superset.databases.ssh_tunnel.commands.delete.is_feature_enabled", + "superset.commands.database.ssh_tunnel.delete.is_feature_enabled", return_value=True, ) @@ -559,7 +559,7 @@ def test_apply_dynamic_database_filter( mocker.patch("sqlalchemy.engine.URL.get_driver_name", return_value="gsheets") mocker.patch("superset.utils.log.DBEventLogger.log") mocker.patch( - "superset.databases.ssh_tunnel.commands.delete.is_feature_enabled", + "superset.commands.database.ssh_tunnel.delete.is_feature_enabled", return_value=False, ) diff --git a/tests/unit_tests/databases/commands/importers/v1/import_test.py b/tests/unit_tests/databases/commands/importers/v1/import_test.py index b8bd24d94..dcd093a9c 100644 --- a/tests/unit_tests/databases/commands/importers/v1/import_test.py +++ b/tests/unit_tests/databases/commands/importers/v1/import_test.py @@ -30,7 +30,7 @@ def test_import_database(mocker: MockFixture, session: Session) -> None: Test importing a database. """ from superset import security_manager - from superset.databases.commands.importers.v1.utils import import_database + from superset.commands.database.importers.v1.utils import import_database from superset.models.core import Database from tests.integration_tests.fixtures.importexport import database_config @@ -70,7 +70,7 @@ def test_import_database_sqlite_invalid(mocker: MockFixture, session: Session) - Test importing a database. """ from superset import app, security_manager - from superset.databases.commands.importers.v1.utils import import_database + from superset.commands.database.importers.v1.utils import import_database from superset.models.core import Database from tests.integration_tests.fixtures.importexport import database_config_sqlite @@ -99,7 +99,7 @@ def test_import_database_managed_externally( Test importing a database that is managed externally. """ from superset import security_manager - from superset.databases.commands.importers.v1.utils import import_database + from superset.commands.database.importers.v1.utils import import_database from superset.models.core import Database from tests.integration_tests.fixtures.importexport import database_config @@ -125,7 +125,7 @@ def test_import_database_without_permission( Test importing a database when a user doesn't have permissions to create. """ from superset import security_manager - from superset.databases.commands.importers.v1.utils import import_database + from superset.commands.database.importers.v1.utils import import_database from superset.models.core import Database from tests.integration_tests.fixtures.importexport import database_config diff --git a/tests/unit_tests/databases/commands/test_connection_test.py b/tests/unit_tests/databases/commands/test_connection_test.py index 8e86cfd1c..66efa7d71 100644 --- a/tests/unit_tests/databases/commands/test_connection_test.py +++ b/tests/unit_tests/databases/commands/test_connection_test.py @@ -17,7 +17,7 @@ from parameterized import parameterized -from superset.databases.commands.test_connection import get_log_connection_action +from superset.commands.database.test_connection import get_log_connection_action from superset.databases.ssh_tunnel.models import SSHTunnel diff --git a/tests/unit_tests/databases/ssh_tunnel/commands/create_test.py b/tests/unit_tests/databases/ssh_tunnel/commands/create_test.py index fbad104c1..bd891b64f 100644 --- a/tests/unit_tests/databases/ssh_tunnel/commands/create_test.py +++ b/tests/unit_tests/databases/ssh_tunnel/commands/create_test.py @@ -19,11 +19,11 @@ import pytest from sqlalchemy.orm.session import Session -from superset.databases.ssh_tunnel.commands.exceptions import SSHTunnelInvalidError +from superset.commands.database.ssh_tunnel.exceptions import SSHTunnelInvalidError def test_create_ssh_tunnel_command() -> None: - from superset.databases.ssh_tunnel.commands.create import CreateSSHTunnelCommand + from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand from superset.databases.ssh_tunnel.models import SSHTunnel from superset.models.core import Database @@ -44,7 +44,7 @@ def test_create_ssh_tunnel_command() -> None: def test_create_ssh_tunnel_command_invalid_params() -> None: - from superset.databases.ssh_tunnel.commands.create import CreateSSHTunnelCommand + from superset.commands.database.ssh_tunnel.create import CreateSSHTunnelCommand from superset.databases.ssh_tunnel.models import SSHTunnel from superset.models.core import Database diff --git a/tests/unit_tests/databases/ssh_tunnel/commands/delete_test.py b/tests/unit_tests/databases/ssh_tunnel/commands/delete_test.py index 641e34d34..14838ddc5 100644 --- a/tests/unit_tests/databases/ssh_tunnel/commands/delete_test.py +++ b/tests/unit_tests/databases/ssh_tunnel/commands/delete_test.py @@ -54,8 +54,8 @@ def session_with_data(session: Session) -> Iterator[Session]: def test_delete_ssh_tunnel_command( mocker: MockFixture, session_with_data: Session ) -> None: + from superset.commands.database.ssh_tunnel.delete import DeleteSSHTunnelCommand from superset.daos.database import DatabaseDAO - from superset.databases.ssh_tunnel.commands.delete import DeleteSSHTunnelCommand from superset.databases.ssh_tunnel.models import SSHTunnel result = DatabaseDAO.get_ssh_tunnel(1) @@ -64,7 +64,7 @@ def test_delete_ssh_tunnel_command( assert isinstance(result, SSHTunnel) assert 1 == result.database_id mocker.patch( - "superset.databases.ssh_tunnel.commands.delete.is_feature_enabled", + "superset.commands.database.ssh_tunnel.delete.is_feature_enabled", return_value=True, ) DeleteSSHTunnelCommand(1).run() diff --git a/tests/unit_tests/databases/ssh_tunnel/commands/update_test.py b/tests/unit_tests/databases/ssh_tunnel/commands/update_test.py index d4a5faba8..5c3907b01 100644 --- a/tests/unit_tests/databases/ssh_tunnel/commands/update_test.py +++ b/tests/unit_tests/databases/ssh_tunnel/commands/update_test.py @@ -20,7 +20,7 @@ from collections.abc import Iterator import pytest from sqlalchemy.orm.session import Session -from superset.databases.ssh_tunnel.commands.exceptions import SSHTunnelInvalidError +from superset.commands.database.ssh_tunnel.exceptions import SSHTunnelInvalidError @pytest.fixture @@ -50,8 +50,8 @@ def session_with_data(session: Session) -> Iterator[Session]: def test_update_shh_tunnel_command(session_with_data: Session) -> None: + from superset.commands.database.ssh_tunnel.update import UpdateSSHTunnelCommand from superset.daos.database import DatabaseDAO - from superset.databases.ssh_tunnel.commands.update import UpdateSSHTunnelCommand from superset.databases.ssh_tunnel.models import SSHTunnel result = DatabaseDAO.get_ssh_tunnel(1) @@ -72,8 +72,8 @@ def test_update_shh_tunnel_command(session_with_data: Session) -> None: def test_update_shh_tunnel_invalid_params(session_with_data: Session) -> None: + from superset.commands.database.ssh_tunnel.update import UpdateSSHTunnelCommand from superset.daos.database import DatabaseDAO - from superset.databases.ssh_tunnel.commands.update import UpdateSSHTunnelCommand from superset.databases.ssh_tunnel.models import SSHTunnel result = DatabaseDAO.get_ssh_tunnel(1) diff --git a/tests/unit_tests/datasets/commands/export_test.py b/tests/unit_tests/datasets/commands/export_test.py index be6a637f8..20565da5b 100644 --- a/tests/unit_tests/datasets/commands/export_test.py +++ b/tests/unit_tests/datasets/commands/export_test.py @@ -25,8 +25,8 @@ def test_export(session: Session) -> None: """ Test exporting a dataset. """ + from superset.commands.dataset.export import ExportDatasetsCommand from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn - from superset.datasets.commands.export import ExportDatasetsCommand from superset.models.core import Database engine = session.get_bind() diff --git a/tests/unit_tests/datasets/commands/importers/v1/import_test.py b/tests/unit_tests/datasets/commands/importers/v1/import_test.py index e8e8c8e7c..5089838e6 100644 --- a/tests/unit_tests/datasets/commands/importers/v1/import_test.py +++ b/tests/unit_tests/datasets/commands/importers/v1/import_test.py @@ -28,11 +28,11 @@ from flask import current_app from pytest_mock import MockFixture from sqlalchemy.orm.session import Session -from superset.datasets.commands.exceptions import ( +from superset.commands.dataset.exceptions import ( DatasetForbiddenDataURI, ImportFailedError, ) -from superset.datasets.commands.importers.v1.utils import validate_data_uri +from superset.commands.dataset.importers.v1.utils import validate_data_uri def test_import_dataset(mocker: MockFixture, session: Session) -> None: @@ -40,8 +40,8 @@ def test_import_dataset(mocker: MockFixture, session: Session) -> None: Test importing a dataset. """ from superset import security_manager + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.models.core import Database mocker.patch.object(security_manager, "can_access", return_value=True) @@ -156,8 +156,8 @@ def test_import_dataset_duplicate_column(mocker: MockFixture, session: Session) """ from superset import security_manager from superset.columns.models import Column as NewColumn + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable, TableColumn - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.models.core import Database mocker.patch.object(security_manager, "can_access", return_value=True) @@ -281,8 +281,8 @@ def test_import_column_extra_is_string(mocker: MockFixture, session: Session) -> Test importing a dataset when the column extra is a string. """ from superset import security_manager + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.core import Database @@ -366,8 +366,8 @@ def test_import_dataset_extra_empty_string( Test importing a dataset when the extra field is an empty string. """ from superset import security_manager + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.core import Database @@ -422,7 +422,7 @@ def test_import_dataset_extra_empty_string( assert sqla_table.extra == None -@patch("superset.datasets.commands.importers.v1.utils.request") +@patch("superset.commands.dataset.importers.v1.utils.request") def test_import_column_allowed_data_url( request: Mock, mocker: MockFixture, @@ -434,8 +434,8 @@ def test_import_column_allowed_data_url( import io from superset import security_manager + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.datasets.schemas import ImportV1DatasetSchema from superset.models.core import Database @@ -510,8 +510,8 @@ def test_import_dataset_managed_externally( Test importing a dataset that is managed externally. """ from superset import security_manager + from superset.commands.dataset.importers.v1.utils import import_dataset from superset.connectors.sqla.models import SqlaTable - from superset.datasets.commands.importers.v1.utils import import_dataset from superset.models.core import Database from tests.integration_tests.fixtures.importexport import dataset_config diff --git a/tests/unit_tests/explore/utils_test.py b/tests/unit_tests/explore/utils_test.py index de39187ec..fa99091f0 100644 --- a/tests/unit_tests/explore/utils_test.py +++ b/tests/unit_tests/explore/utils_test.py @@ -18,20 +18,20 @@ from flask_appbuilder.security.sqla.models import User from pytest import raises from pytest_mock import MockFixture -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( ChartAccessDeniedError, ChartNotFoundError, ) +from superset.commands.dataset.exceptions import ( + DatasetAccessDeniedError, + DatasetNotFoundError, +) from superset.commands.exceptions import ( DatasourceNotFoundValidationError, DatasourceTypeInvalidError, OwnersNotFoundValidationError, QueryNotFoundValidationError, ) -from superset.datasets.commands.exceptions import ( - DatasetAccessDeniedError, - DatasetNotFoundError, -) from superset.exceptions import SupersetSecurityException from superset.utils.core import DatasourceType, override_user diff --git a/tests/unit_tests/jinja_context_test.py b/tests/unit_tests/jinja_context_test.py index 114f04630..e2a5e8cd4 100644 --- a/tests/unit_tests/jinja_context_test.py +++ b/tests/unit_tests/jinja_context_test.py @@ -22,7 +22,7 @@ import pytest from pytest_mock import MockFixture from sqlalchemy.dialects import mysql -from superset.datasets.commands.exceptions import DatasetNotFoundError +from superset.commands.dataset.exceptions import DatasetNotFoundError from superset.jinja_context import dataset_macro, WhereInMacro diff --git a/tests/unit_tests/tags/commands/create_test.py b/tests/unit_tests/tags/commands/create_test.py index 39f0e3c4e..ca31e4456 100644 --- a/tests/unit_tests/tags/commands/create_test.py +++ b/tests/unit_tests/tags/commands/create_test.py @@ -49,12 +49,12 @@ def session_with_data(session: Session): def test_create_command_success(session_with_data: Session, mocker: MockFixture): + from superset.commands.tag.create import CreateCustomTagWithRelationshipsCommand from superset.connectors.sqla.models import SqlaTable from superset.daos.tag import TagDAO from superset.models.dashboard import Dashboard from superset.models.slice import Slice from superset.models.sql_lab import Query, SavedQuery - from superset.tags.commands.create import CreateCustomTagWithRelationshipsCommand from superset.tags.models import ObjectType, TaggedObject # Define a list of objects to tag @@ -92,12 +92,12 @@ def test_create_command_success(session_with_data: Session, mocker: MockFixture) def test_create_command_success_clear(session_with_data: Session, mocker: MockFixture): + from superset.commands.tag.create import CreateCustomTagWithRelationshipsCommand from superset.connectors.sqla.models import SqlaTable from superset.daos.tag import TagDAO from superset.models.dashboard import Dashboard from superset.models.slice import Slice from superset.models.sql_lab import Query, SavedQuery - from superset.tags.commands.create import CreateCustomTagWithRelationshipsCommand from superset.tags.models import ObjectType, TaggedObject # Define a list of objects to tag diff --git a/tests/unit_tests/tags/commands/update_test.py b/tests/unit_tests/tags/commands/update_test.py index 6d0a99b67..47ef16e4e 100644 --- a/tests/unit_tests/tags/commands/update_test.py +++ b/tests/unit_tests/tags/commands/update_test.py @@ -58,9 +58,9 @@ def session_with_data(session: Session): def test_update_command_success(session_with_data: Session, mocker: MockFixture): + from superset.commands.tag.update import UpdateTagCommand from superset.daos.tag import TagDAO from superset.models.dashboard import Dashboard - from superset.tags.commands.update import UpdateTagCommand from superset.tags.models import ObjectType, TaggedObject dashboard = session_with_data.query(Dashboard).first() @@ -94,11 +94,11 @@ def test_update_command_success(session_with_data: Session, mocker: MockFixture) def test_update_command_success_duplicates( session_with_data: Session, mocker: MockFixture ): + from superset.commands.tag.create import CreateCustomTagWithRelationshipsCommand + from superset.commands.tag.update import UpdateTagCommand from superset.daos.tag import TagDAO from superset.models.dashboard import Dashboard from superset.models.slice import Slice - from superset.tags.commands.create import CreateCustomTagWithRelationshipsCommand - from superset.tags.commands.update import UpdateTagCommand from superset.tags.models import ObjectType, TaggedObject dashboard = session_with_data.query(Dashboard).first() @@ -144,12 +144,12 @@ def test_update_command_success_duplicates( def test_update_command_failed_validation( session_with_data: Session, mocker: MockFixture ): + from superset.commands.tag.create import CreateCustomTagWithRelationshipsCommand + from superset.commands.tag.exceptions import TagInvalidError + from superset.commands.tag.update import UpdateTagCommand from superset.daos.tag import TagDAO from superset.models.dashboard import Dashboard from superset.models.slice import Slice - from superset.tags.commands.create import CreateCustomTagWithRelationshipsCommand - from superset.tags.commands.exceptions import TagInvalidError - from superset.tags.commands.update import UpdateTagCommand from superset.tags.models import ObjectType dashboard = session_with_data.query(Dashboard).first() diff --git a/tests/unit_tests/tasks/test_async_queries.py b/tests/unit_tests/tasks/test_async_queries.py index 5787bbdc8..1e14d742d 100644 --- a/tests/unit_tests/tasks/test_async_queries.py +++ b/tests/unit_tests/tasks/test_async_queries.py @@ -3,7 +3,7 @@ from unittest import mock import pytest from flask_babel import lazy_gettext as _ -from superset.charts.commands.exceptions import ChartDataQueryFailedError +from superset.commands.chart.exceptions import ChartDataQueryFailedError @mock.patch("superset.tasks.async_queries.security_manager") diff --git a/tests/unit_tests/utils/date_parser_tests.py b/tests/unit_tests/utils/date_parser_tests.py index a2ec20901..031137723 100644 --- a/tests/unit_tests/utils/date_parser_tests.py +++ b/tests/unit_tests/utils/date_parser_tests.py @@ -22,7 +22,7 @@ from unittest.mock import Mock, patch import pytest from dateutil.relativedelta import relativedelta -from superset.charts.commands.exceptions import ( +from superset.commands.chart.exceptions import ( TimeRangeAmbiguousError, TimeRangeParseFailError, )