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:
leigh-mil
2019-11-07 11:25:18 -05:00
parent 045e06abee
commit ab9b62f54b
7 changed files with 60 additions and 20 deletions

View File

@@ -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)