chore: proper current_app.config proxy usage (#34345)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Maxime Beauchemin
2025-07-31 19:27:42 -07:00
committed by GitHub
parent 6c9cda758a
commit cb27d5fe8d
144 changed files with 1428 additions and 1119 deletions

View File

@@ -47,6 +47,7 @@ from superset.utils.core import (
QuerySource,
remove_extra_adhoc_filters,
)
from tests.conftest import with_config
ADHOC_FILTER: QueryObjectFilterClause = {
"col": "foo",
@@ -622,19 +623,25 @@ def test_get_query_source_from_request(
assert get_query_source_from_request() == expected
def test_get_user_agent(mocker: MockerFixture) -> None:
@with_config({"USER_AGENT_FUNC": None})
def test_get_user_agent(mocker: MockerFixture, app_context: None) -> None:
database_mock = mocker.MagicMock()
database_mock.database_name = "mydb"
current_app_mock = mocker.patch("superset.utils.core.current_app")
current_app_mock.config = {"USER_AGENT_FUNC": None}
assert get_user_agent(database_mock, QuerySource.DASHBOARD) == "Apache Superset", (
"The default user agent should be returned"
)
current_app_mock.config["USER_AGENT_FUNC"] = (
lambda database, source: f"{database.database_name} {source.name}"
)
@with_config(
{
"USER_AGENT_FUNC": lambda database,
source: f"{database.database_name} {source.name}"
}
)
def test_get_user_agent_custom(mocker: MockerFixture, app_context: None) -> None:
database_mock = mocker.MagicMock()
database_mock.database_name = "mydb"
assert get_user_agent(database_mock, QuerySource.DASHBOARD) == "mydb DASHBOARD", (
"the custom user agent function result should have been returned"

View File

@@ -26,7 +26,6 @@ from unittest.mock import call, Mock, patch
import pytest
from pytest_mock import MockerFixture
from superset import app
from superset.utils import decorators
from superset.utils.backports import StrEnum
@@ -78,7 +77,7 @@ def test_statsd_gauge(
raise FileNotFoundError("Not found")
return "OK"
with patch.object(app.config["STATS_LOGGER"], "gauge") as mock:
with patch("superset.extensions.stats_logger_manager.instance.gauge") as mock:
cm = (
pytest.raises(expected_exception)
if isclass(expected_exception) and issubclass(expected_exception, Exception)