mirror of
https://github.com/apache/superset.git
synced 2026-05-07 08:54:23 +00:00
chore: add talisman env var to config (#24774)
(cherry picked from commit d23b20ea75)
This commit is contained in:
committed by
Michael S. Molina
parent
b272814ff5
commit
e46f10a8a6
@@ -53,6 +53,7 @@ from superset.key_value.types import JsonKeyValueCodec
|
||||
from superset.stats_logger import DummyStatsLogger
|
||||
from superset.superset_typing import CacheConfig
|
||||
from superset.tasks.types import ExecutorType
|
||||
from superset.utils import core as utils
|
||||
from superset.utils.core import is_test, NO_TIME_RANGE, parse_boolean_string
|
||||
from superset.utils.encrypt import SQLAlchemyUtilsAdapter
|
||||
from superset.utils.log import DBEventLogger
|
||||
@@ -1381,7 +1382,8 @@ TEST_DATABASE_CONNECTION_TIMEOUT = timedelta(seconds=30)
|
||||
CONTENT_SECURITY_POLICY_WARNING = True
|
||||
|
||||
# Do you want Talisman enabled?
|
||||
TALISMAN_ENABLED = True
|
||||
TALISMAN_ENABLED = utils.cast_to_boolean(os.environ.get("TALISMAN_ENABLED", True))
|
||||
|
||||
# If you want Talisman, how do you want it configured??
|
||||
TALISMAN_CONFIG = {
|
||||
"content_security_policy": {
|
||||
|
||||
@@ -439,6 +439,8 @@ def cast_to_boolean(value: Any) -> bool | None:
|
||||
"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, (int, float)):
|
||||
return value != 0
|
||||
if isinstance(value, str):
|
||||
|
||||
@@ -20,6 +20,7 @@ from typing import Any, Optional
|
||||
import pytest
|
||||
|
||||
from superset.utils.core import (
|
||||
cast_to_boolean,
|
||||
is_test,
|
||||
parse_boolean_string,
|
||||
QueryObjectFilterClause,
|
||||
@@ -132,3 +133,41 @@ def test_is_test():
|
||||
)
|
||||
def test_parse_boolean_string(test_input: Optional[str], expected: bool):
|
||||
assert parse_boolean_string(test_input) == expected
|
||||
|
||||
|
||||
def test_int_values():
|
||||
assert cast_to_boolean(1) is True
|
||||
assert cast_to_boolean(0) is False
|
||||
assert cast_to_boolean(-1) is True
|
||||
assert cast_to_boolean(42) is True
|
||||
assert cast_to_boolean(0) is False
|
||||
|
||||
|
||||
def test_float_values():
|
||||
assert cast_to_boolean(0.5) is True
|
||||
assert cast_to_boolean(3.14) is True
|
||||
assert cast_to_boolean(-2.71) is True
|
||||
assert cast_to_boolean(0.0) is False
|
||||
|
||||
|
||||
def test_string_values():
|
||||
assert cast_to_boolean("true") is True
|
||||
assert cast_to_boolean("TruE") is True
|
||||
assert cast_to_boolean("false") is False
|
||||
assert cast_to_boolean("FaLsE") is False
|
||||
assert cast_to_boolean("") is False
|
||||
|
||||
|
||||
def test_none_value():
|
||||
assert cast_to_boolean(None) is None
|
||||
|
||||
|
||||
def test_boolean_values():
|
||||
assert cast_to_boolean(True) is True
|
||||
assert cast_to_boolean(False) is False
|
||||
|
||||
|
||||
def test_other_values():
|
||||
assert cast_to_boolean([]) is False
|
||||
assert cast_to_boolean({}) is False
|
||||
assert cast_to_boolean(object()) is False
|
||||
|
||||
Reference in New Issue
Block a user