mirror of
https://github.com/apache/superset.git
synced 2026-04-11 20:37:16 +00:00
chore(command): Organize Commands according to SIP-92 (#25850)
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user