7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
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
99 lines
3.7 KiB
Python
99 lines
3.7 KiB
Python
"""Tests for web/utils/request_helpers.py.
|
|
|
|
Locks in parse_bool_arg's behavior contract: it MUST behave identically to
|
|
the inline pattern ``request.args.get(name, "false_or_true").lower() == "true"``
|
|
that it replaces. In particular: no whitespace stripping, no widening of the
|
|
truthy set beyond the literal string ``"true"`` (case-insensitive).
|
|
"""
|
|
|
|
from flask import Flask
|
|
|
|
from local_deep_research.web.utils.request_helpers import parse_bool_arg
|
|
|
|
|
|
def _make_app():
|
|
"""Create a minimal Flask test app."""
|
|
app = Flask(__name__)
|
|
app.config["TESTING"] = True
|
|
return app
|
|
|
|
|
|
class TestParseBoolArg:
|
|
"""Tests for parse_bool_arg."""
|
|
|
|
def test_missing_param_returns_default_false(self):
|
|
"""Absent param returns the default (False)."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?other=value"):
|
|
assert parse_bool_arg("flag") is False
|
|
|
|
def test_missing_param_returns_default_true(self):
|
|
"""Absent param returns the default (True) when default=True."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?other=value"):
|
|
assert parse_bool_arg("flag", default=True) is True
|
|
|
|
def test_value_true_lowercase(self):
|
|
"""?flag=true returns True."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=true"):
|
|
assert parse_bool_arg("flag") is True
|
|
|
|
def test_value_true_uppercase(self):
|
|
"""?flag=TRUE returns True (case-insensitive)."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=TRUE"):
|
|
assert parse_bool_arg("flag") is True
|
|
|
|
def test_value_true_mixed_case(self):
|
|
"""?flag=True returns True (case-insensitive)."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=True"):
|
|
assert parse_bool_arg("flag") is True
|
|
|
|
def test_value_false(self):
|
|
"""?flag=false returns False."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=false"):
|
|
assert parse_bool_arg("flag", default=True) is False
|
|
|
|
def test_empty_value_returns_false(self):
|
|
"""?flag= (empty string) returns False, NOT the default.
|
|
|
|
This matches the inline pattern: ``request.args.get("flag", "false")``
|
|
returns the empty string when the param is present-but-empty, not the
|
|
default. The empty string lowercases to "" which != "true", so False.
|
|
"""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag="):
|
|
# Even with default=True, an empty value still returns False.
|
|
assert parse_bool_arg("flag", default=True) is False
|
|
|
|
def test_value_yes_returns_false(self):
|
|
"""?flag=yes returns False — only "true" is truthy."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=yes"):
|
|
assert parse_bool_arg("flag") is False
|
|
|
|
def test_value_one_returns_false(self):
|
|
"""?flag=1 returns False — only "true" is truthy."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=1"):
|
|
assert parse_bool_arg("flag") is False
|
|
|
|
def test_value_on_returns_false(self):
|
|
"""?flag=on returns False — only "true" is truthy."""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=on"):
|
|
assert parse_bool_arg("flag") is False
|
|
|
|
def test_whitespace_padded_true_returns_false(self):
|
|
"""?flag=%20true%20 returns False — whitespace is NOT stripped.
|
|
|
|
This locks in the no-strip behavior: a stripping helper would return
|
|
True here, which would diverge from the original inline pattern.
|
|
"""
|
|
app = _make_app()
|
|
with app.test_request_context("/?flag=%20true%20"):
|
|
assert parse_bool_arg("flag") is False
|