35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
from django.test import override_settings
|
|
|
|
from infrasynth.shared.settings_utils import get_setting
|
|
|
|
|
|
class TestGetSetting:
|
|
def test_returns_value_when_key_exists(self):
|
|
with override_settings(INFRASYNTH_TEST={"MY_KEY": "hello"}):
|
|
result = get_setting("INFRASYNTH_TEST", "MY_KEY")
|
|
assert result == "hello"
|
|
|
|
def test_returns_default_when_prefix_missing(self):
|
|
result = get_setting("NONEXISTENT_PREFIX", "SOME_KEY", 42)
|
|
assert result == 42
|
|
|
|
def test_returns_default_when_key_missing(self):
|
|
with override_settings(INFRASYNTH_TEST={"EXISTING": "val"}):
|
|
result = get_setting("INFRASYNTH_TEST", "MISSING_KEY", "fallback")
|
|
assert result == "fallback"
|
|
|
|
def test_returns_none_when_no_default(self):
|
|
with override_settings(INFRASYNTH_TEST={}):
|
|
result = get_setting("INFRASYNTH_TEST", "MISSING_KEY")
|
|
assert result is None
|
|
|
|
def test_works_with_nested_dict(self):
|
|
config = {"NESTED": {"key": "deep"}}
|
|
with override_settings(INFRASYNTH_TEST=config):
|
|
result = get_setting("INFRASYNTH_TEST", "NESTED")
|
|
assert result == {"key": "deep"}
|
|
|
|
def test_with_real_infrasynth_setting(self):
|
|
result = get_setting("INFRASYNTH_SECURITY", "COOKIE_SECURE")
|
|
assert result is not None
|
|
assert isinstance(result, bool)
|