コード例 #1
0
ファイル: resources.py プロジェクト: podhmo/block.komet
 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)
コード例 #2
0
ファイル: test_it.py プロジェクト: podhmo/block.form
    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)
コード例 #3
0
ファイル: test_it.py プロジェクト: podhmo/block.form
    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)