mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +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
@@ -21,6 +21,7 @@ from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from flask import current_app
|
||||
from flask_appbuilder.security.sqla.models import Role
|
||||
from freezegun import freeze_time
|
||||
from jinja2 import DebugUndefined
|
||||
@@ -29,7 +30,6 @@ from pytest_mock import MockerFixture
|
||||
from sqlalchemy.dialects import mysql
|
||||
from sqlalchemy.dialects.postgresql import dialect
|
||||
|
||||
from superset import app
|
||||
from superset.commands.dataset.exceptions import DatasetNotFoundError
|
||||
from superset.connectors.sqla.models import (
|
||||
RowLevelSecurityFilter,
|
||||
@@ -58,7 +58,7 @@ def test_filter_values_adhoc_filters() -> None:
|
||||
"""
|
||||
Test the ``filter_values`` macro with ``adhoc_filters``.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -79,7 +79,7 @@ def test_filter_values_adhoc_filters() -> None:
|
||||
assert cache.filter_values("name") == ["foo"]
|
||||
assert cache.applied_filters == ["name"]
|
||||
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -105,7 +105,7 @@ def test_filter_values_extra_filters() -> None:
|
||||
"""
|
||||
Test the ``filter_values`` macro with ``extra_filters``.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{"extra_filters": [{"col": "name", "op": "in", "val": "foo"}]}
|
||||
@@ -147,7 +147,7 @@ def test_get_filters_adhoc_filters() -> None:
|
||||
"""
|
||||
Test the ``get_filters`` macro.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -172,7 +172,7 @@ def test_get_filters_adhoc_filters() -> None:
|
||||
assert cache.removed_filters == []
|
||||
assert cache.applied_filters == ["name"]
|
||||
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -195,7 +195,7 @@ def test_get_filters_adhoc_filters() -> None:
|
||||
]
|
||||
assert cache.removed_filters == []
|
||||
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -225,7 +225,7 @@ def test_get_filters_is_null_operator() -> None:
|
||||
Test the ``get_filters`` macro with a IS_NULL operator,
|
||||
which doesn't have a comparator
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -263,7 +263,7 @@ def test_url_param_query() -> None:
|
||||
"""
|
||||
Test the ``url_param`` macro.
|
||||
"""
|
||||
with app.test_request_context(query_string={"foo": "bar"}):
|
||||
with current_app.test_request_context(query_string={"foo": "bar"}):
|
||||
cache = ExtraCache()
|
||||
assert cache.url_param("foo") == "bar"
|
||||
|
||||
@@ -272,7 +272,7 @@ def test_url_param_default() -> None:
|
||||
"""
|
||||
Test the ``url_param`` macro with a default value.
|
||||
"""
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
cache = ExtraCache()
|
||||
assert cache.url_param("foo", "bar") == "bar"
|
||||
|
||||
@@ -281,7 +281,7 @@ def test_url_param_no_default() -> None:
|
||||
"""
|
||||
Test the ``url_param`` macro without a match.
|
||||
"""
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
cache = ExtraCache()
|
||||
assert cache.url_param("foo") is None
|
||||
|
||||
@@ -290,7 +290,7 @@ def test_url_param_form_data() -> None:
|
||||
"""
|
||||
Test the ``url_param`` with ``url_params`` in ``form_data``.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
query_string={"form_data": json.dumps({"url_params": {"foo": "bar"}})}
|
||||
):
|
||||
cache = ExtraCache()
|
||||
@@ -302,7 +302,7 @@ def test_url_param_escaped_form_data() -> None:
|
||||
Test the ``url_param`` with ``url_params`` in ``form_data`` returning
|
||||
an escaped value with a quote.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})}
|
||||
):
|
||||
cache = ExtraCache(dialect=dialect())
|
||||
@@ -313,7 +313,7 @@ def test_url_param_escaped_default_form_data() -> None:
|
||||
"""
|
||||
Test the ``url_param`` with default value containing an escaped quote.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})}
|
||||
):
|
||||
cache = ExtraCache(dialect=dialect())
|
||||
@@ -325,7 +325,7 @@ def test_url_param_unescaped_form_data() -> None:
|
||||
Test the ``url_param`` with ``url_params`` in ``form_data`` returning
|
||||
an un-escaped value with a quote.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})}
|
||||
):
|
||||
cache = ExtraCache(dialect=dialect())
|
||||
@@ -336,7 +336,7 @@ def test_url_param_unescaped_default_form_data() -> None:
|
||||
"""
|
||||
Test the ``url_param`` with default value containing an un-escaped quote.
|
||||
"""
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
query_string={"form_data": json.dumps({"url_params": {"foo": "O'Brien"}})}
|
||||
):
|
||||
cache = ExtraCache(dialect=dialect())
|
||||
@@ -895,7 +895,7 @@ def test_metric_macro_no_dataset_id_no_context(mocker: MockerFixture) -> None:
|
||||
mock_g = mocker.patch("superset.jinja_context.g")
|
||||
mock_g.form_data = {}
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
with pytest.raises(SupersetTemplateException) as excinfo:
|
||||
metric_macro(env, {}, "macro_key")
|
||||
assert str(excinfo.value) == (
|
||||
@@ -916,7 +916,7 @@ def test_metric_macro_no_dataset_id_with_context_missing_info(
|
||||
mock_g.form_data = {"queries": []}
|
||||
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -963,7 +963,7 @@ def test_metric_macro_no_dataset_id_with_context_datasource_id(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -990,7 +990,7 @@ def test_metric_macro_no_dataset_id_with_context_datasource_id(
|
||||
}
|
||||
],
|
||||
}
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
assert metric_macro(env, {}, "macro_key") == "COUNT(*)"
|
||||
|
||||
|
||||
@@ -1006,7 +1006,7 @@ def test_metric_macro_no_dataset_id_with_context_datasource_id_none(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -1037,7 +1037,7 @@ def test_metric_macro_no_dataset_id_with_context_datasource_id_none(
|
||||
}
|
||||
],
|
||||
}
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
with pytest.raises(SupersetTemplateException) as excinfo:
|
||||
metric_macro(env, {}, "macro_key")
|
||||
assert str(excinfo.value) == (
|
||||
@@ -1072,7 +1072,7 @@ def test_metric_macro_no_dataset_id_with_context_chart_id(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -1099,7 +1099,7 @@ def test_metric_macro_no_dataset_id_with_context_chart_id(
|
||||
}
|
||||
],
|
||||
}
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
assert metric_macro(env, {}, "macro_key") == "COUNT(*)"
|
||||
|
||||
|
||||
@@ -1115,7 +1115,7 @@ def test_metric_macro_no_dataset_id_with_context_slice_id_none(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -1146,7 +1146,7 @@ def test_metric_macro_no_dataset_id_with_context_slice_id_none(
|
||||
}
|
||||
],
|
||||
}
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
with pytest.raises(SupersetTemplateException) as excinfo:
|
||||
metric_macro(env, {}, "macro_key")
|
||||
assert str(excinfo.value) == (
|
||||
@@ -1168,7 +1168,7 @@ def test_metric_macro_no_dataset_id_with_context_deleted_chart(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -1199,7 +1199,7 @@ def test_metric_macro_no_dataset_id_with_context_deleted_chart(
|
||||
}
|
||||
],
|
||||
}
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
with pytest.raises(SupersetTemplateException) as excinfo:
|
||||
metric_macro(env, {}, "macro_key")
|
||||
assert str(excinfo.value) == (
|
||||
@@ -1230,7 +1230,7 @@ def test_metric_macro_no_dataset_id_available_in_request_form_data(
|
||||
|
||||
# Getting the data from the request context
|
||||
env = SandboxedEnvironment(undefined=DebugUndefined)
|
||||
with app.test_request_context(
|
||||
with current_app.test_request_context(
|
||||
data={
|
||||
"form_data": json.dumps(
|
||||
{
|
||||
@@ -1248,7 +1248,7 @@ def test_metric_macro_no_dataset_id_available_in_request_form_data(
|
||||
"datasource": "1__table",
|
||||
}
|
||||
|
||||
with app.test_request_context():
|
||||
with current_app.test_request_context():
|
||||
assert metric_macro(env, {}, "macro_key") == "COUNT(*)"
|
||||
|
||||
|
||||
@@ -1423,7 +1423,7 @@ def test_get_time_filter(
|
||||
|
||||
with (
|
||||
freeze_time("2024-09-03"),
|
||||
app.test_request_context(
|
||||
current_app.test_request_context(
|
||||
json={"queries": queries},
|
||||
),
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user