Exemplo n.º 1
0
def test_weak_schema_success():
    schema = schematec.dictionary(
        a=converters.string,
        b=converters.string,
    )

    assert schema({'a': 1234}, weak=True) == {'a': '1234'}
Exemplo n.º 2
0
def test_weak_schema_missed_value_success():
    schema = schematec.dictionary(
        a=converters.string,
        b=converters.string & validators.required,
    )

    assert schema({'a': 1234}, weak=True) == {'a': '1234'}
Exemplo n.º 3
0
def test_weak_schema_recursive_list_success():
    schema = schematec.dictionary(a=schematec.array(
        schematec.dictionary(
            b=converters.integer,
            c=converters.integer & validators.required,
        )))

    assert (schema({'a': [{
        'b': 1,
        'c': 1
    }, {
        'b': 1
    }]}, weak=True) == {
        'a': [{
            'b': 1,
            'c': 1
        }, {
            'b': 1
        }]
    })
Exemplo n.º 4
0
def test_empty_schema_with_non_empty_value():
    schema = schematec.schema.dictionary()
    assert schema({'a': 1}) == {'a': 1}
Exemplo n.º 5
0
def test_dict_in_list():
    schema = schematec.schema.array(
        schematec.schema.dictionary(a=converters.string, ))
    assert schema([{'a': 1}, {'a': 2}]) == [{'a': '1'}, {'a': '2'}]
Exemplo n.º 6
0
def test_unbound_validator_required_without_converter():
    schema = schematec.schema.dictionary(a=validators.required)
    assert schema({'a': 1}) == {'a': 1}
Exemplo n.º 7
0
def test_schema_with_missed_keys():
    schema = schematec.schema.array(converters.string)
    assert schema([1]) == ['1']
Exemplo n.º 8
0
def test_schema_with_missed_keys():
    schema = schematec.schema.dictionary(a=converters.string)
    assert schema({'b': 1}) == {}
Exemplo n.º 9
0
def test_integer_to_integer_converter():
    schema = schematec.schema.dictionary(a=converters.integer)
    assert schema({'a': 1}) == {'a': 1}
Exemplo n.º 10
0
def test_schema_with_converters_and_validators():
    schema = schematec.schema.array(converters.string & validators.length(3))

    assert schema([123]) == ['123']
Exemplo n.º 11
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])
Exemplo n.º 12
0
def test_bound_validator():
    schema = schematec.schema.array(validators.length(3))
    assert schema(['1']) == ['1']
Exemplo n.º 13
0
def test_bound_validator_error():
    schema = schematec.schema.array(validators.length(3))
    with pytest.raises(exc.ValidationError):
        schema(['1234'])
Exemplo n.º 14
0
def test_bound_validator_skipped():
    schema = schematec.schema.array(validators.length(3))
    assert schema([1]) == [1]
Exemplo n.º 15
0
def test_integer_to_integer_converter():
    schema = schematec.schema.array(converters.integer)
    assert schema([1]) == [1]
Exemplo n.º 16
0
def test_integer_to_string_converter():
    schema = schematec.schema.array(converters.string)
    assert schema([1]) == ['1']
Exemplo n.º 17
0
def test_sugar_descriptors_fail():
    schema = schematec.dictionary(a=schematec.string & schematec.required, )

    with pytest.raises(exc.ValidationError):
        schema({})
Exemplo n.º 18
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'])
Exemplo n.º 19
0
def test_sugar_descriptors_success():
    schema = schematec.dictionary(a=schematec.string & schematec.required, )

    assert schema({'a': 1}) == {'a': '1'}
Exemplo n.º 20
0
def test_schema_with_only_one_descriptor():
    schema = schematec.schema.dictionary(a=converters.string, )

    assert schema({'a': 1234}) == {'a': '1234'}
Exemplo n.º 21
0
def test_integer_to_string_converter():
    schema = schematec.schema.dictionary(a=converters.string)
    assert schema({'a': 1}) == {'a': '1'}
Exemplo n.º 22
0
def test_bound_validator():
    schema = schematec.schema.dictionary(a=validators.length(3))
    assert schema({'a': '1'}) == {'a': '1'}
Exemplo n.º 23
0
def test_unbound_validator_required():
    schema = schematec.schema.dictionary(a=validators.required
                                         & converters.integer)
    assert schema({'a': '1'}) == {'a': 1}
Exemplo n.º 24
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'}
Exemplo n.º 25
0
def test_unbound_validator_required_for_missed_without_converter():
    schema = schematec.schema.dictionary(a=validators.required)
    with pytest.raises(exc.ValidationError):
        schema({})
Exemplo n.º 26
0
def test_empty_schema_with_non_empty_value():
    schema = schematec.schema.array()
    assert schema([1]) == [1]
Exemplo n.º 27
0
def test_bound_validator_error():
    schema = schematec.schema.dictionary(a=validators.length(3))
    with pytest.raises(exc.ValidationError):
        schema({'a': '1234'})
Exemplo n.º 28
0
def test_weak_schema_recursive_success():
    schema = schematec.dictionary(
        a=schematec.dictionary(b=converters.string & validators.required, ))

    assert schema({'a': {}}, weak=True) == {'a': {}}
Exemplo n.º 29
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'})
Exemplo n.º 30
0
def test_dict_in_dict_required():
    schema = schematec.schema.dictionary(a=schematec.schema.dictionary(
        b=converters.string & validators.required, ), )
    with pytest.raises(exc.ValidationError):
        schema({'a': {'c': 1}})