def phones_form(request): form = ZigguratForm(PhonesSchema) data = { "prefix": 1, "aaaa": "bbbb", "phones": [{ 'number': '1', 'location': 'dadada' }, { 'y': 5 }, { 'number': 'abc' }, {}, { 'location': 'warsaw', 'number': 123 }], "suffix": "bla" } if request.method == 'POST': form.set_data(request.POST) form.validate() else: form.set_data(data) return {"form": form}
def test_default_value(self): form = ZigguratForm(FieldDefaultsSchema) form.set_data({}) music = form.widget.children[1] assert music.children[0].data == 'Grandaddy' assert music.children[1].data == 'Just Like the Fambly Cat' assert music.children[2].data == colander.null
def form_view(self, request, data): form = ZigguratForm(self.form) if request.method == 'POST': form.set_data(request.POST) form.validate() elif data: form.set_data(data) return {"form": form}
def test_bad_userlogin_schema(self): data = {"username": "******", "password": "******"} form = ZigguratForm(UserLoginSchema()) form.set_data(data) with pytest.raises(ValidationException): self.validate(form) # widget must have error assert any(form.widget_errors.values()) is True
def basic_form(request): data = {'password': '******', "phones": [{}], "subperson": {}, "user_name": "us"} form = ZigguratForm(UserSchema) if request.method == 'POST': form.set_data(request.POST) form.validate() else: form.set_data(data) return {"form": form}
def basic_form(request): data = { 'password': '******', "phones": [{}], "subperson": {}, "user_name": "us" } form = ZigguratForm(UserSchema) if request.method == 'POST': form.set_data(request.POST) form.validate() else: form.set_data(data) return {"form": form}
def test_deep_group_schema(self): data = {'': {'': {'foo100': {'': {'': {'': {'foo': 'sdfsdf'} } } } } }, } form = ZigguratForm(group_schema) form.set_data(data) self.validate(form)
def phones_form(request): form = ZigguratForm(PhonesSchema) data = { "prefix": 1, "aaaa": "bbbb", "phones": [{'number': '1', 'location': 'dadada'}, {'y': 5}, {'number': 'abc'}, {}, {'location': 'warsaw', 'number': 123}], "suffix": "bla" } if request.method == 'POST': form.set_data(request.POST) form.validate() else: form.set_data(data) return {"form": form}
def test_bad_deep_group_schema(self): data = {'': {'': {'foo100': {'': {'': {'': {'foo': ''} } } } } }, } form = ZigguratForm(group_schema) form.set_data(data) with pytest.raises(ValidationException): self.validate(form) # widget must have error assert any(form.schema_errors.values()) is True
def test_missing_value(self): data = { 'music': { 'artist': 'Alexey Efimov', 'album': 'Antona Valeka 15', 'song': 'foo', 'description': 'foo' } } form = ZigguratForm(FieldDefaultsSchema) form.set_data(data) assert form.non_validated_data == { 'title': 'missing title', 'music': { 'title': 'missing title', 'artist': 'Alexey Efimov', 'album': 'Antona Valeka 15', 'song': 'foo', 'description': 'foo' } } self.validate(form)
from ziggurat_form.test_schemas import UserSchema from ziggurat_form.form import ZigguratForm data = {'password':'******'} form = ZigguratForm(UserSchema) form.set_data(data) form.validate() def render_field(field): print('--------------') if field.widget: print('label:"{}", req:{}'.format(field.widget.label, field.widget.required)) if field.widget.errors: print('errors:', field.widget.errors) print(field.widget()) if field.children: print('peppercorn marker START') for subfield in field.children: render_field(subfield) print('peppercorn marker END') for field in form: render_field(field) print('FORM ERRORS:', form.errors)
def user_register_form(request): form = ZigguratForm(UserRegisterSchema) if request.method == 'POST': form.set_data(request.POST) form.validate() return {"form": form}
def user_login_form(request): form = ZigguratForm(UserLoginSchema) if request.method == 'POST': form.set_data(request.POST) form.validate() return {"form": form}
def test_userlogin_schema(self): data = {"username": "******", "password": "******"} form = ZigguratForm(UserLoginSchema()) form.set_data(data) self.validate(form)