Esempio n. 1
0
 def try_commit(self, parsing, params, commit, **extra):
     required = (next(provided_chain(parsing, self.request)), )
     validation = get_validation(self.request, required, name=nameof(self.Model))
     validation.extra["session"] = self.session
     if validation:
         params = validation.validate(params, **extra)
     return commit(params)
Esempio n. 2
0
    def test_boundary(self):
        from block.form.validation import get_validation
        from block.form.validation import ValidationError

        request = testing.DummyRequest(registry=self.config.registry)
        boundary = get_validation(request, UserSchema())

        DB = {"*inserted name*"}
        with self.assertRaises(ValidationError) as e:
            e.expected_regex = re.compile("conflict")
            boundary.validate({"name": "*inserted name*"}, db=DB)
Esempio n. 3
0
    def test_boundary__add_validation_runtime(self):
        from block.form.validation import get_validation
        from block.form.validation import ValidationError

        request = testing.DummyRequest(registry=self.config.registry)
        boundary = get_validation(request, UserSchema())
        class InvalidStatus(Exception):
            pass
        def new_validation(data):
            if not "token" in data:
                raise InvalidStatus("oops")
        boundary.add("token", new_validation)

        DB = {"*inserted name*"}

        with self.assertRaises(ValidationError) as e:
            e.expected_regex = re.compile("oops")
            boundary.validate({"name": "*new name*"}, db=DB)