mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat(db): Adding DB_SQLA_URI_VALIDATOR (#27847)
This commit is contained in:
@@ -23,6 +23,7 @@ import pytest
|
||||
from pytest_mock import MockFixture
|
||||
from sqlalchemy import types
|
||||
from sqlalchemy.dialects import sqlite
|
||||
from sqlalchemy.engine.url import URL
|
||||
from sqlalchemy.sql import sqltypes
|
||||
|
||||
from superset.superset_typing import ResultSetColumnType, SQLAColumnType
|
||||
@@ -69,6 +70,25 @@ def test_parse_sql_multi_statement() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_validate_db_uri(mocker: MockFixture) -> None:
|
||||
"""
|
||||
Ensures that the `validate_database_uri` method invokes the validator correctly
|
||||
"""
|
||||
|
||||
def mock_validate(sqlalchemy_uri: URL) -> None:
|
||||
raise ValueError("Invalid URI")
|
||||
|
||||
mocker.patch(
|
||||
"superset.db_engine_specs.base.current_app.config",
|
||||
{"DB_SQLA_URI_VALIDATOR": mock_validate},
|
||||
)
|
||||
|
||||
from superset.db_engine_specs.base import BaseEngineSpec
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
BaseEngineSpec.validate_database_uri(URL.create("sqlite"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"original,expected",
|
||||
[
|
||||
|
||||
@@ -124,7 +124,7 @@ def test_superset_limit(mocker: MockFixture, app_context: None, table1: None) ->
|
||||
"""
|
||||
mocker.patch(
|
||||
"superset.extensions.metadb.current_app.config",
|
||||
{"SUPERSET_META_DB_LIMIT": 1},
|
||||
{"DB_SQLA_URI_VALIDATOR": None, "SUPERSET_META_DB_LIMIT": 1},
|
||||
)
|
||||
mocker.patch("superset.extensions.metadb.security_manager")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user