mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: log multiple errors (#14064)
* log all errors from db create * return unique set of errors * sort set for exceptions list * run black
This commit is contained in:
committed by
GitHub
parent
d539fc217a
commit
c143b37128
@@ -26,7 +26,9 @@ 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 (
|
||||
DatabaseInvalidError,
|
||||
DatabaseNotFoundError,
|
||||
DatabaseSecurityUnsafeError,
|
||||
DatabaseTestConnectionDriverError,
|
||||
@@ -64,6 +66,43 @@ from tests.integration_tests.fixtures.importexport import (
|
||||
)
|
||||
|
||||
|
||||
class TestCreateDatabaseCommand(SupersetTestCase):
|
||||
@mock.patch(
|
||||
"superset.databases.commands.test_connection.event_logger.log_with_context"
|
||||
)
|
||||
def test_create_duplicate_error(self, mock_logger):
|
||||
example_db = get_example_database()
|
||||
command = CreateDatabaseCommand(
|
||||
security_manager.find_user("admin"),
|
||||
{"database_name": example_db.database_name},
|
||||
)
|
||||
with pytest.raises(DatabaseInvalidError) as excinfo:
|
||||
command.run()
|
||||
assert str(excinfo.value) == ("Database parameters are invalid.")
|
||||
# logger should list classnames of all errors
|
||||
mock_logger.assert_called_with(
|
||||
action="db_connection_failed."
|
||||
"DatabaseInvalidError."
|
||||
"DatabaseExistsValidationError."
|
||||
"DatabaseRequiredFieldValidationError"
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"superset.databases.commands.test_connection.event_logger.log_with_context"
|
||||
)
|
||||
def test_multiple_error_logging(self, mock_logger):
|
||||
command = CreateDatabaseCommand(security_manager.find_user("admin"), {})
|
||||
with pytest.raises(DatabaseInvalidError) as excinfo:
|
||||
command.run()
|
||||
assert str(excinfo.value) == ("Database parameters are invalid.")
|
||||
# logger should list a unique set of errors with no duplicates
|
||||
mock_logger.assert_called_with(
|
||||
action="db_connection_failed."
|
||||
"DatabaseInvalidError."
|
||||
"DatabaseRequiredFieldValidationError"
|
||||
)
|
||||
|
||||
|
||||
class TestExportDatabasesCommand(SupersetTestCase):
|
||||
@skip("Flaky")
|
||||
@patch("superset.security.manager.g")
|
||||
|
||||
Reference in New Issue
Block a user