Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

245 lines
8.2 KiB
Python

"""
Tests for checkbox settings save behavior.
Verifies that checkbox settings (booleans) can be correctly saved as both
true and false values, and that the value persists correctly.
"""
from tests.test_utils import add_src_to_path
add_src_to_path()
class TestCheckboxBooleanSave:
"""Test that boolean settings can be saved as true and false."""
def test_parse_boolean_false_string(self):
"""parse_boolean should return False for 'false' string."""
from local_deep_research.settings.manager import parse_boolean
assert parse_boolean("false") is False
assert parse_boolean("False") is False
assert parse_boolean("FALSE") is False
def test_parse_boolean_true_string(self):
"""parse_boolean should return True for 'true' string."""
from local_deep_research.settings.manager import parse_boolean
assert parse_boolean("true") is True
assert parse_boolean("True") is True
assert parse_boolean("TRUE") is True
def test_parse_boolean_actual_booleans(self):
"""parse_boolean should handle actual boolean values."""
from local_deep_research.settings.manager import parse_boolean
assert parse_boolean(True) is True
assert parse_boolean(False) is False
def test_get_typed_setting_value_checkbox_false(self):
"""get_typed_setting_value should convert 'false' to False for checkbox."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Test with string "false" (as sent by hidden input)
result = get_typed_setting_value(
key="app.allow_registrations",
value="false",
ui_element="checkbox",
default=True,
check_env=False,
)
assert result is False, (
f"Expected False, got {result} (type: {type(result)})"
)
def test_get_typed_setting_value_checkbox_true(self):
"""get_typed_setting_value should convert 'true' to True for checkbox."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Test with string "true" (as sent by checkbox)
result = get_typed_setting_value(
key="app.allow_registrations",
value="true",
ui_element="checkbox",
default=False,
check_env=False,
)
assert result is True, (
f"Expected True, got {result} (type: {type(result)})"
)
def test_get_typed_setting_value_checkbox_boolean_false(self):
"""get_typed_setting_value should preserve False boolean for checkbox."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Test with actual False boolean (as sent by AJAX)
result = get_typed_setting_value(
key="app.allow_registrations",
value=False,
ui_element="checkbox",
default=True,
check_env=False,
)
assert result is False, (
f"Expected False, got {result} (type: {type(result)})"
)
def test_get_typed_setting_value_checkbox_boolean_true(self):
"""get_typed_setting_value should preserve True boolean for checkbox."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Test with actual True boolean (as sent by AJAX)
result = get_typed_setting_value(
key="app.allow_registrations",
value=True,
ui_element="checkbox",
default=False,
check_env=False,
)
assert result is True, (
f"Expected True, got {result} (type: {type(result)})"
)
class TestCheckboxFormDataHandling:
"""Test how form data is processed for checkbox settings."""
def test_form_data_false_string_is_converted(self):
"""Form data with 'false' string should be converted to False boolean."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Simulate what happens when hidden fallback sends "false"
form_value = "false" # This is what the hidden input sends
result = get_typed_setting_value(
key="app.debug",
value=form_value,
ui_element="checkbox",
default=True,
check_env=False,
)
assert result is False
assert isinstance(result, bool)
def test_ajax_json_false_is_preserved(self):
"""AJAX JSON with false boolean should be preserved as False."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Simulate what happens when AJAX sends JSON with false
json_value = False # This is what checkbox.checked returns
result = get_typed_setting_value(
key="app.debug",
value=json_value,
ui_element="checkbox",
default=True,
check_env=False,
)
assert result is False
assert isinstance(result, bool)
class TestCheckboxMissingValue:
"""Test handling of missing checkbox values (key not in form data)."""
def test_missing_checkbox_value_none_returns_default(self):
"""When checkbox value is None, default value is returned."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# When value is None, get_typed_setting_value returns the default
# This is correct for settings that weren't included in form data
result = get_typed_setting_value(
key="app.debug",
value=None,
ui_element="checkbox",
default=True,
check_env=False,
)
# With value=None, the function returns the default
assert result is True
def test_parse_boolean_none_is_false(self):
"""parse_boolean treats None as False (HTML semantics)."""
from local_deep_research.settings.manager import parse_boolean
# parse_boolean directly returns False for None
assert parse_boolean(None) is False
def test_empty_string_is_false(self):
"""Empty string checkbox value should be treated as False."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
result = get_typed_setting_value(
key="app.debug",
value="",
ui_element="checkbox",
default=True,
check_env=False,
)
assert result is False
class TestAllowRegistrationsSetting:
"""Specific tests for the app.allow_registrations setting."""
def test_allow_registrations_default_value(self):
"""app.allow_registrations should have correct default in settings."""
import json
from pathlib import Path
# Read the default settings file
defaults_path = (
Path(__file__).parent.parent.parent
/ "src"
/ "local_deep_research"
/ "defaults"
/ "default_settings.json"
)
if defaults_path.exists():
with open(defaults_path) as f:
defaults = json.load(f)
setting = defaults.get("app.allow_registrations", {})
assert setting.get("ui_element") == "checkbox"
assert setting.get("value") is True # Default should be True
def test_allow_registrations_can_be_set_false(self):
"""app.allow_registrations should be able to be set to False."""
from local_deep_research.settings.manager import (
get_typed_setting_value,
)
# Test setting to false via AJAX (boolean)
result_ajax = get_typed_setting_value(
key="app.allow_registrations",
value=False,
ui_element="checkbox",
default=True,
check_env=False,
)
assert result_ajax is False
# Test setting to false via POST (string)
result_post = get_typed_setting_value(
key="app.allow_registrations",
value="false",
ui_element="checkbox",
default=True,
check_env=False,
)
assert result_post is False