Files
docker-images/python-tools/tests/test_checkbox_inputs.py
T
ajp_anton c9826e9ccc
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
Respect explicitly cleared checkbox selections
2026-10-26 22:13:56 +00:00

58 lines
2.3 KiB
Python

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": []}