Пример #1
0
def test_schema_with_converters_and_validators():
    schema = schematec.schema.dictionary(
        a=validators.required & converters.string & validators.length(3))

    assert schema({'a': 123}) == {'a': '123'}
Пример #2
0
def test_schema_with_converters_and_validators_fail_on_length():
    schema = schematec.schema.dictionary(
        a=validators.required & converters.string & validators.length(3))

    with pytest.raises(exc.ValidationError):
        schema({'a': '1234'})
Пример #3
0
def test_bound_validator():
    schema = schematec.schema.dictionary(a=validators.length(3))
    assert schema({'a': '1'}) == {'a': '1'}
Пример #4
0
def test_bound_validator_error():
    schema = schematec.schema.dictionary(a=validators.length(3))
    with pytest.raises(exc.ValidationError):
        schema({'a': '1234'})
Пример #5
0
def test_schema_with_converters_and_validators_fail_on_convertation():
    schema = schematec.schema.array(converters.string & validators.length(3))

    with pytest.raises(exc.ConvertationError):
        schema([None])
Пример #6
0
def test_schema_with_converters_and_validators_fail_on_length_for_various_values():
    schema = schematec.schema.array(converters.string & validators.length(3))

    with pytest.raises(exc.ValidationError):
        schema(['123', '1234'])
Пример #7
0
def test_bound_validator_error():
    schema = schematec.schema.array(validators.length(3))
    with pytest.raises(exc.ValidationError):
        schema(['1234'])
Пример #8
0
def test_schema_with_converters_and_validators():
    schema = schematec.schema.array(converters.string & validators.length(3))

    assert schema([123]) == ['123']
Пример #9
0
def test_bound_validator_skipped():
    schema = schematec.schema.array(validators.length(3))
    assert schema([1]) == [1]
Пример #10
0
def test_bound_validator():
    schema = schematec.schema.array(validators.length(3))
    assert schema(['1']) == ['1']
Пример #11
0
def test_string():
    validators.length(1)('a')
Пример #12
0
def test_too_long_string():
    with pytest.raises(exc.ValidationError):
        validators.length(1)('aa')
Пример #13
0
def test_tuple():
    validators.length(1)(('1',))
Пример #14
0
def test_list():
    validators.length(1)(['1'])
Пример #15
0
def test_empty_list():
    validators.length(1)([])