Beispiel #1
0
 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
Beispiel #2
0
    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
Beispiel #3
0
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}
Beispiel #4
0
 def test_deep_group_schema(self):
     data = {'':
             {'':
              {'foo100':
               {'':
                {'':
                 {'':
                  {'foo': 'sdfsdf'}
                  }
                 }
                }
               }
              },
             }
     form = ZigguratForm(group_schema)
     form.set_data(data)
     self.validate(form)
Beispiel #5
0
    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}
Beispiel #6
0
    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
Beispiel #7
0
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}
Beispiel #8
0
 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)
Beispiel #9
0
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}
Beispiel #10
0
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}
Beispiel #11
0
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)
Beispiel #12
0
def user_register_form(request):
    form = ZigguratForm(UserRegisterSchema)
    if request.method == 'POST':
        form.set_data(request.POST)
        form.validate()
    return {"form": form}
Beispiel #13
0
def user_login_form(request):
    form = ZigguratForm(UserLoginSchema)
    if request.method == 'POST':
        form.set_data(request.POST)
        form.validate()
    return {"form": form}
Beispiel #14
0
def user_register_form(request):
    form = ZigguratForm(UserRegisterSchema)
    if request.method == 'POST':
        form.set_data(request.POST)
        form.validate()
    return {"form": form}
Beispiel #15
0
def user_login_form(request):
    form = ZigguratForm(UserLoginSchema)
    if request.method == 'POST':
        form.set_data(request.POST)
        form.validate()
    return {"form": form}
Beispiel #16
0
 def test_userlogin_schema(self):
     data = {"username": "******", "password": "******"}
     form = ZigguratForm(UserLoginSchema())
     form.set_data(data)
     self.validate(form)