| 2 | |
| 3 | |
| 4 | def 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" |