mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
chore: proper current_app.config proxy usage (#34345)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
6c9cda758a
commit
cb27d5fe8d
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user