Respect explicitly cleared checkbox selections
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 49s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 49s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m46s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 24s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 32s
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 49s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 49s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Failing after 1m46s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 24s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 32s
This commit is contained in:
1 parent
e54f56d910
commit
c9826e9ccc
3 files changed
+64
No files matched your search
@@ -129,6 +129,12 @@ def validate_multi_choice(
|
||||
if field.required:
|
||||
return None, "Choose at least one option."
|
||||
return None, None
|
||||
# The form's hidden empty value distinguishes deselection from omission.
|
||||
raw_values = [value for value in raw_values if value != ""]
|
||||
if not raw_values:
|
||||
if field.required:
|
||||
return None, "Choose at least one option."
|
||||
return [], None
|
||||
allowed = {option.value for option in field.options}
|
||||
if any(value not in allowed for value in raw_values):
|
||||
return None, "Choose only from the available options."
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
{% elif field.type == "multi_choice" %}
|
||||
<fieldset>
|
||||
<legend>{{ field.label }}{% if field.required %} (required){% endif %}</legend>
|
||||
<input type="hidden" name="{{ field.name }}" value="">
|
||||
{% set selected = values.get(field.name, field.default or ()) %}
|
||||
{% for option in field.options %}
|
||||
<label>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from app.discovery import TaskCatalog
|
||||
from app.inputs import validate_inputs
|
||||
from app.web import create_app
|
||||
from .conftest import write_task
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def checkbox_task(settings):
|
||||
task = write_task(settings.task_root, "example", "inspect.py", 'print("done")\n')
|
||||
manifest = {"version": 1, "tasks": {task.name: {"inputs": [{
|
||||
"name": "operations", "label": "Operations", "type": "multi_choice",
|
||||
"default": ["link", "cleanup"], "options": ["link", "cleanup"],
|
||||
}]}}}
|
||||
(task.parent / "task-inputs.json").write_text(json.dumps(manifest))
|
||||
return TaskCatalog(settings.task_root).task("example/inspect.py")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("submitted,expected", [
|
||||
({}, ["link", "cleanup"]),
|
||||
({"operations": [""]}, []),
|
||||
({"operations": ["", "link"]}, ["link"]),
|
||||
({"operations": ["", "cleanup"]}, ["cleanup"]),
|
||||
({"operations": ["", "link", "cleanup"]}, ["link", "cleanup"]),
|
||||
])
|
||||
def test_empty_form_selection_is_not_replaced_with_defaults(checkbox_task, submitted, expected):
|
||||
values, errors = validate_inputs(checkbox_task.inputs, submitted)
|
||||
assert not errors
|
||||
assert values["operations"] == expected
|
||||
|
||||
|
||||
def test_required_empty_selection_is_rejected_even_with_defaults(checkbox_task):
|
||||
from dataclasses import replace
|
||||
field = replace(checkbox_task.inputs[0], required=True)
|
||||
values, errors = validate_inputs((field,), {"operations": [""]})
|
||||
assert values == {}
|
||||
assert errors == {"operations": "Choose at least one option."}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("selected", [["", "unknown"], ["", "link", "link"]])
|
||||
def test_hidden_marker_does_not_bypass_option_validation(checkbox_task, selected):
|
||||
_, errors = validate_inputs(checkbox_task.inputs, {"operations": selected})
|
||||
assert errors
|
||||
|
||||
|
||||
def test_form_contains_empty_marker_and_persists_explicit_empty_selection(settings, checkbox_task):
|
||||
app = create_app(settings)
|
||||
client = app.test_client()
|
||||
assert b'type="hidden" name="operations" value=""' in client.get("/").data
|
||||
response = client.post("/tasks/example/inspect.py/run", data={"operations": ""})
|
||||
assert response.status_code == 302
|
||||
run_id = int(response.headers["Location"].rsplit("/", 1)[1])
|
||||
run = app.extensions["run_store"].get(run_id)
|
||||
assert json.loads(run.input_json) == {"operations": []}
|
||||
Reference in new issue
Block a user