chore(command): Organize Commands according to SIP-92 (#25850)

This commit is contained in:
John Bodley
2023-11-22 11:55:54 -08:00
committed by GitHub
parent 984c278c4c
commit 07bcfa9b5f
265 changed files with 786 additions and 808 deletions

View File

@@ -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 = {