Update validators and filter to remove strings that contain only
whitespace The validator ListItemRequired() was only checking for None and an empty string, not for strings that were multiple whitespace characters. This fixes this issue by checking each item with regex to make sure it contains non whitespace characters The filter remove_empty_string() also was not checking for strings that were multiple whitespace characters. This was also fixed by using regex tomake sure that the string contains non whitespace characters, and also clips any trailing whitespace.
This commit is contained in:
@@ -85,3 +85,20 @@ class TestFileLength:
|
||||
|
||||
dummy_field.data = "random string"
|
||||
assert validator(dummy_form, dummy_field)
|
||||
|
||||
|
||||
class TestListItemRequired:
|
||||
@pytest.mark.parametrize("valid", [[" a", ""], ["a ", ""], ["a", ""]])
|
||||
def test_ListItemRequired(self, valid, dummy_form, dummy_field):
|
||||
validator = ListItemRequired()
|
||||
dummy_field.data = valid
|
||||
validator(dummy_form, dummy_field)
|
||||
|
||||
@pytest.mark.parametrize("invalid", [[""], [" "], [None], []])
|
||||
def test_ListItemRequired_rejects_blank_names(
|
||||
self, invalid, dummy_form, dummy_field
|
||||
):
|
||||
validator = ListItemRequired()
|
||||
dummy_field.data = invalid
|
||||
with pytest.raises(ValidationError):
|
||||
validator(dummy_form, dummy_field)
|
||||
|
Reference in New Issue
Block a user