Exemplo n.º 1
0
def test_pattern_with_invalid_regex():
    with pytest.raises(ValidationError) as err:
        schema_validator({'pattern': '(arrst'})

    assert_message_in_errors(
        MESSAGES['pattern']['invalid_regex'],
        err.value.detail,
        'pattern',
    )
Exemplo n.º 2
0
def test_title_for_valid_title():
    try:
        schema_validator({'title': 'uuid'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('title', errors)
Exemplo n.º 3
0
def test_properties_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('properties', errors)
Exemplo n.º 4
0
def test_required_with_invalid_sub_types():
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': ['field-A', True, 'Field-B']})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
Exemplo n.º 5
0
def test_properties_with_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'properties': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'properties.type',
    )
Exemplo n.º 6
0
def test_pattern_for_valid_regex():
    try:
        schema_validator({'pattern': '^test$'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('pattern', errors)
Exemplo n.º 7
0
def test_unique_items_with_valid_value():
    try:
        schema_validator({'uniqueItems': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('uniqueItems', errors)
Exemplo n.º 8
0
def test_format_for_valid_unregistered_format():
    try:
        schema_validator({'format': 'not-a-registered-format'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('format', errors)
Exemplo n.º 9
0
def test_type_with_invalid_single_type():
    with pytest.raises(ValidationError) as err:
        schema_validator({'type': 'not-a-valid-type'})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'type.enum',
    )
Exemplo n.º 10
0
def test_multiple_of_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'multipleOf': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'multipleOf.type',
    )
Exemplo n.º 11
0
def test_multiple_of_invalid_for_negative_numbers(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'multipleOf': value})

    assert_message_in_errors(
        MESSAGES['minimum']['invalid'],
        err.value.detail,
        'multipleOf.minimum',
    )
Exemplo n.º 12
0
def test_multiple_for_valid_values(value):
    try:
        schema_validator({'multipleOf': value})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('multipleOf', errors)
Exemplo n.º 13
0
def test_multiple_of_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('multipleOf', errors)
Exemplo n.º 14
0
def test_schema_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator(value)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'type',
    )
Exemplo n.º 15
0
def test_read_only_with_valid_value():
    try:
        schema_validator({'readOnly': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('readOnly', errors)
Exemplo n.º 16
0
def test_read_only_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('readOnly', errors)
Exemplo n.º 17
0
def test_title_for_valid_title():
    try:
        schema_validator({'title': 'uuid'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('title', errors)
Exemplo n.º 18
0
def test_unique_items_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('uniqueItems', errors)
Exemplo n.º 19
0
def test_type_with_invalid_single_type():
    with pytest.raises(ValidationError) as err:
        schema_validator({'type': 'not-a-valid-type'})

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'type.enum',
    )
Exemplo n.º 20
0
def test_unique_items_with_valid_value():
    try:
        schema_validator({'uniqueItems': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('uniqueItems', errors)
Exemplo n.º 21
0
def test_required_with_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
Exemplo n.º 22
0
def test_unique_items_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('uniqueItems', errors)
Exemplo n.º 23
0
def test_required_for_valid_required():
    try:
        schema_validator({'required': ['field-A', 'field-B']})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('required', errors)
Exemplo n.º 24
0
def test_required_with_invalid_sub_types():
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': ['field-A', True, 'Field-B']})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
Exemplo n.º 25
0
def test_required_with_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'required': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'required.type',
    )
Exemplo n.º 26
0
def test_read_only_with_valid_value():
    try:
        schema_validator({'readOnly': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('readOnly', errors)
Exemplo n.º 27
0
def test_schema_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator(value)

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'type',
    )
Exemplo n.º 28
0
def test_pattern_for_valid_regex():
    try:
        schema_validator({'pattern': '^test$'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('pattern', errors)
Exemplo n.º 29
0
def test_properties_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('properties', errors)
Exemplo n.º 30
0
def test_required_for_valid_required():
    try:
        schema_validator({'required': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('required', errors)
Exemplo n.º 31
0
def test_type_validation_for_multiple_of_for_valid_types(type_):
    try:
        schema_validator({"multipleOf": 5, "type": type_})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("type", errors)
Exemplo n.º 32
0
def test_multiple_for_valid_values(value):
    try:
        schema_validator({"multipleOf": value})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("multipleOf", errors)
Exemplo n.º 33
0
def test_enum_with_empty_array_is_invalid():
    try:
        schema_validator({'enum': [1, 2, 3]})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('enum', errors)
Exemplo n.º 34
0
def test_multiple_of_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("multipleOf", errors)
Exemplo n.º 35
0
def test_read_only_is_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('readOnly', errors)
Exemplo n.º 36
0
def test_enum_with_empty_array_is_invalid():
    with pytest.raises(ValidationError) as err:
        schema_validator({'enum': []})

    assert_message_in_errors(
        MESSAGES['min_items']['invalid'],
        err.value.detail,
        'enum.minItems',
    )
Exemplo n.º 37
0
def test_format_for_valid_unregistered_format():
    try:
        schema_validator({'format': 'not-a-registered-format'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('format', errors)
Exemplo n.º 38
0
def test_min_length_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'minLength': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'minLength.type',
    )
Exemplo n.º 39
0
def test_properties_with_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({'properties': value})

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'properties.type',
    )
Exemplo n.º 40
0
def test_pattern_with_invalid_regex():
    with pytest.raises(ValidationError) as err:
        schema_validator({'pattern': '(arrst'})

    assert_message_in_errors(
        MESSAGES['pattern']['invalid_regex'],
        err.value.detail,
        'pattern',
    )
Exemplo n.º 41
0
def test_min_and_max_length_with_valid_values():
    try:
        schema_validator({"minLength": 8, "maxLength": 10})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("minLength", errors)
    assert_path_not_in_errors("maxLength", errors)
Exemplo n.º 42
0
def test_min_and_max_properties_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('minProperties', errors)
    assert_path_not_in_errors('maxProperties', errors)
def test_exclusive_minimum_and_maximum_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('exclusiveMinimum', errors)
    assert_path_not_in_errors('exclusiveMaximum', errors)
Exemplo n.º 44
0
def test_min_and_max_properties_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('minProperties', errors)
    assert_path_not_in_errors('maxProperties', errors)
def test_exclusive_minimum_and_maximum_for_valid_values():
    try:
        schema_validator({'exclusiveMinimum': True, 'exclusiveMaximum': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('exclusiveMinimum', errors)
    assert_path_not_in_errors('exclusiveMaximum', errors)
def test_exclusive_minimum_and_maximum_for_valid_values():
    try:
        schema_validator({'exclusiveMinimum': True, 'exclusiveMaximum': True})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('exclusiveMinimum', errors)
    assert_path_not_in_errors('exclusiveMaximum', errors)
def test_exclusive_minimum_and_maximum_are_not_required():
    try:
        schema_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('exclusiveMinimum', errors)
    assert_path_not_in_errors('exclusiveMaximum', errors)
Exemplo n.º 48
0
def test_type_as_valid_array_of_types():
    try:
        schema_validator({
            'type': [STRING, INTEGER, BOOLEAN],
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Exemplo n.º 49
0
def test_type_with_invalid_multiple_types():
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'type': [STRING, 'not-a-valid-type', INTEGER, BOOLEAN],
        })

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'type.enum',
    )
def test_exclusive_maximum_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'exclusiveMaximum': value,
        })

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'exclusiveMaximum.type',
    )
Exemplo n.º 51
0
def test_references_are_deferred():
    context = {"deferred_references": set()}
    try:
        schema_validator({"$ref": "TestReference"}, context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("$ref", errors)
    assert "TestReference" in context["deferred_references"]
Exemplo n.º 52
0
def test_type_as_valid_singular_type():
    try:
        schema_validator({
            'type': BOOLEAN,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
def test_exclusive_maximum_for_invalid_types(value):
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'exclusiveMaximum': value,
        })

    assert_message_in_errors(
        MESSAGES['type']['invalid'],
        err.value.detail,
        'exclusiveMaximum.type',
    )
Exemplo n.º 54
0
def test_min_length_must_be_positive():
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'minLength': -1,
        })

    assert_message_in_errors(
        MESSAGES['minimum']['invalid'],
        err.value.detail,
        'minLength.minimum',
    )
Exemplo n.º 55
0
def test_type_as_valid_array_of_types():
    try:
        schema_validator({
            'type': [STRING, INTEGER, BOOLEAN],
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Exemplo n.º 56
0
def test_type_with_invalid_multiple_types():
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'type': [STRING, 'not-a-valid-type', INTEGER, BOOLEAN],
        })

    assert_message_in_errors(
        MESSAGES['enum']['invalid'],
        err.value.detail,
        'type.enum',
    )
Exemplo n.º 57
0
def test_type_as_valid_singular_type():
    try:
        schema_validator({
            'type': BOOLEAN,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Exemplo n.º 58
0
def test_max_length_must_be_greater_than_0():
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'maxLength': 0,
        })

    assert_message_in_errors(
        MESSAGES['minimum']['invalid'],
        err.value.detail,
        'maxLength.minimum',
    )
def test_no_correct_type_for_minimum(types):
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'minimum': 7,
            'type': types,
        })

    assert_message_in_errors(
        MESSAGES['type']['invalid_type_for_minimum'],
        err.value.detail,
        'type',
    )
def test_no_correct_type_for_minimum(types):
    with pytest.raises(ValidationError) as err:
        schema_validator({
            'minimum': 7,
            'type': types,
        })

    assert_message_in_errors(
        MESSAGES['type']['invalid_type_for_minimum'],
        err.value.detail,
        'type',
    )