MCPcopy Index your code
hub / github.com/webpy/webpy / test_form_validators

Function test_form_validators

tests/test_form_validators.py:4–19  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3
4def test_form_validators():
5 field_validator_name = "field should not be empty"
6 field_validator = Validator(field_validator_name, lambda x: len(x) > 0)
7 field = Input("field", field_validator)
8
9 res = field.validate("")
10 assert not res, "empty field should not validate"
11 assert field.note == field_validator_name, "failing field should be in note"
12
13 form_validator = Validator("form field should not be empty", lambda x: True)
14 form = Form(field, validators=[form_validator])
15 res = form.validates(source={"field": ""})
16 assert not res, "form should not validate with empty field"
17 assert (
18 form.note == field_validator_name
19 ), "failing field note should propagate to form note"

Callers

nothing calls this directly

Calls 5

validateMethod · 0.95
validatesMethod · 0.95
ValidatorClass · 0.90
InputClass · 0.90
FormClass · 0.90

Tested by

no test coverage detected