Skip to content

Commit

Permalink
test that pattern shows up in the input field
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas loeffler committed Nov 13, 2022
1 parent fdfc1ab commit 4b91b87
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/validators/test_regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,29 @@ def test_regex_raises(re_pattern, re_flags, test_v, dummy_form, dummy_field):
validator(dummy_form, dummy_field)


def test_regexp_message_default(dummy_form, dummy_field, grab_error_message):
"""
Regexp validator should return default message
"""
validator = regexp("^a")
dummy_field.data = "f"
assert grab_error_message(validator, dummy_form, dummy_field) == "Invalid input."


def test_regexp_message(dummy_form, dummy_field, grab_error_message):
"""
Regexp validator should return given message
"""
validator = regexp("^a", message="foo")
dummy_field.data = "f"
assert grab_error_message(validator, dummy_form, dummy_field) == "foo"


def test_regexp_pattern_html(dummy_form, dummy_field):
"""
Regexp validator should return given message
"""
validator = regexp("^[a-zA-Z0-9]+$")
dummy_field.data = "foo bar"

assert validator.field_flags == {"pattern": '^[a-zA-Z0-9]+$'}

0 comments on commit 4b91b87

Please sign in to comment.