Пример #1
0
def test_doc_generation():
    schema = Integer(description="Test description", minimum=10)

    assert schema.to_doc() == {
        "description": "Test description",
        "minimum": 10,
        "type": "integer",
    }
Пример #2
0
def test_nullable():
    assert Integer(nullable=True).validate(None) is None
Пример #3
0
def test_can_instantiate():
    test_integer = Integer()
    assert test_integer.validate(10)
Пример #4
0
def test_pass_range(min, max, value):
    assert Integer(minimum=min, maximum=max).validate(value) is value
Пример #5
0
def test_fail_range(min, max, value):
    with pytest.raises(ValidationError):
        Integer(minimum=min, maximum=max).validate(value)
Пример #6
0
def test_fail_multiple_of(multiplication, value):
    with pytest.raises(ValidationError):
        Integer(multiple_of=multiplication).validate(value)
Пример #7
0
def test_pass_multiple_of(multiplication, value):
    assert Integer(multiple_of=multiplication).validate(value) is value
Пример #8
0
def test_validation_pass(value):
    assert Integer().validate(value) is value
Пример #9
0
def test_validation_fail(value):
    with pytest.raises(ValidationError):
        Integer().validate(value)
Пример #10
0
    assert validate(value, type_definition) is None


@pytest.mark.parametrize(
    "value,type_definition",
    [
        [[], Sequence],
        [(1, ), Sequence],
        [[1], Sequence[int]],
        [("a", "b", None), Sequence[Optional[str]]],
        [[1, 2, 3], Sequence[int]],
    ],
)
def test_validate_sequence_type_definitions(value, type_definition):
    assert validate(value, type_definition) is None


@pytest.mark.parametrize(
    "value,type_definition",
    [[(1, ), Tuple], [("a", "b", None), Tuple[Optional[str]]],
     [(1, 2, 3), Tuple[int]]],
)
def test_validate_tuple_type_definitions(value, type_definition):
    assert validate(value, type_definition) is None


@pytest.mark.parametrize("value,type_definition",
                         [([1, 2, 3], Array(Integer(minimum=0, maximum=5)))])
def test_validate_schema_types(value, type_definition):
    assert validate(value, type_definition) is None