2018-04-25 15:48:01 +01:00
|
|
|
import pytest
|
|
|
|
|
from wtforms import Form, StringField
|
|
|
|
|
|
|
|
|
|
from app.main.forms import StripWhitespaceForm, StripWhitespaceStringField
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleForm(StripWhitespaceForm):
|
|
|
|
|
foo = StringField('Foo')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleFormSpecialField(Form):
|
|
|
|
|
foo = StripWhitespaceStringField('foo')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('submitted_data', [
|
|
|
|
|
'bar',
|
|
|
|
|
' bar ',
|
|
|
|
|
"""
|
|
|
|
|
\t bar
|
|
|
|
|
""",
|
|
|
|
|
' \u180E\u200B \u200C bar \u200D \u2060\uFEFF ',
|
|
|
|
|
])
|
|
|
|
|
@pytest.mark.parametrize('form', [
|
|
|
|
|
ExampleForm,
|
|
|
|
|
ExampleFormSpecialField,
|
|
|
|
|
])
|
|
|
|
|
def test_form_strips_all_whitespace(
|
2021-05-12 14:57:21 +01:00
|
|
|
notify_admin,
|
2018-04-25 15:48:01 +01:00
|
|
|
form,
|
|
|
|
|
submitted_data,
|
|
|
|
|
):
|
|
|
|
|
assert form(foo=submitted_data).foo.data == 'bar'
|