Last active
October 18, 2017 00:09
-
-
Save kshade/a9a2e9ba514461bdbf02e17ce0ea4b1a to your computer and use it in GitHub Desktop.
wtforms-test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import wtforms | |
import wtforms_json | |
wtforms_json.init() | |
class TestSchemaJson(wtforms.Form): | |
name = wtforms.StringField('name', validators=[wtforms.validators.Optional(), | |
wtforms.validators.Length(2, 128)]) | |
potato = wtforms.StringField('potato', validators=[wtforms.validators.Optional(), | |
wtforms.validators.NoneOf([None, '']), | |
wtforms.validators.AnyOf(['maximum'])]) | |
jsons = [{}, | |
{'name': ''}, | |
{'name': 'a'}, | |
{'name': 'ab'}, | |
{'potato': None}, | |
{'potato': ''}, | |
{'potato': 'minimum'}, | |
{'potato': 'maximum'}] | |
print('WTForms-JSON version', wtforms_json.__version__) | |
print() | |
for json in jsons: | |
form = TestSchemaJson.from_json(json) | |
form.validate() | |
print('json', repr(json)) | |
print('errors', repr(form.errors)) | |
print('form.data', repr(form.data)) | |
print('form.patch_data', repr(form.patch_data)) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment