Esempio n. 1
0
def test_field_declared_as_required_with_field_present_is_valid():
    schema = {
        'type': OBJECT,
        'required': [
            'field-A',
            # 'field-B',
        ],
    }
    validator = generate_validator_from_schema(schema)

    try:
        validator({'field-A': 'present'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'required.field-A',
        errors,
    )
    assert_path_not_in_errors(
        'required.field-B',
        errors,
    )
Esempio n. 2
0
def test_field_declared_as_required_with_field_present_is_valid():
    schema = {
        'type': OBJECT,
        'required': [
            'field-A',
            # 'field-B',
        ],
    }
    validator = generate_validator_from_schema(schema)

    try:
        validator({'field-A': 'present'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'required.field-A',
        errors,
    )
    assert_path_not_in_errors(
        'required.field-B',
        errors,
    )
Esempio n. 3
0
def test_collection_format_with_valid_values():
    try:
        single_parameter_validator({"collectionFormat": CSV})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("collectionFormat", errors)
Esempio n. 4
0
def test_collection_format_is_not_required():
    try:
        single_parameter_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors("collectionFormat", errors)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio 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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
0
def test_type_is_not_required():
    try:
        single_parameter_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 19
0
def test_headers_validation_with_valid_type():
    try:
        single_response_validator({'headers': {}})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('headers', errors)
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
0
def test_headers_is_not_required():
    try:
        single_response_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('headers', errors)
Esempio n. 23
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)
Esempio n. 24
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)
Esempio n. 25
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)
Esempio n. 26
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)
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
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)
Esempio n. 30
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)
Esempio n. 31
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)
Esempio n. 32
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)
Esempio n. 33
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)
Esempio n. 34
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)
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)
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)
Esempio n. 39
0
def test_swagger_field_with_valid_version():
    raw_schema = RawSchemaFactory(swagger='2.0')

    try:
        swagger_schema_validator(raw_schema)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('swagger', errors)
Esempio n. 40
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)
Esempio n. 41
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"]
Esempio n. 42
0
def test_type_as_valid_singular_type():
    try:
        single_parameter_validator({
            'type': BOOLEAN,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 43
0
def test_type_as_valid_array_of_types():
    try:
        single_parameter_validator({
            'type': [STRING, INTEGER, BOOLEAN],
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 44
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)
Esempio n. 45
0
def test_parameter_validation_with_default_present():
    context = {'deferred_references': set()}
    parameter = ParameterFactory(default='0')
    assert 'default' in parameter
    try:
        single_parameter_validator(parameter, context=context)
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('default', errors)
Esempio n. 46
0
def test_in_with_valid_values(value):
    try:
        single_parameter_validator({'in': value})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'in.enum',
        errors,
    )
Esempio n. 47
0
def test_collection_format_is_not_required():
    try:
        single_parameter_validator({})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'collectionFormat',
        errors,
    )
Esempio n. 48
0
def test_collection_format_with_valid_values():
    try:
        single_parameter_validator({'collectionFormat': CSV})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'collectionFormat',
        errors,
    )
Esempio n. 49
0
def test_type_validation_for_unique_items_with_valid_types(type_):
    try:
        schema_validator({
            'uniqueItems': True,
            'type': type_,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 50
0
def test_in_with_valid_values():
    try:
        single_parameter_validator({'description': 'The description'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'description',
        errors,
    )
Esempio n. 51
0
def test_type_validation_for_min_properties_for_valid_types(type_):
    try:
        schema_validator({
            'minProperties': 5,
            'type': type_,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 52
0
def test_name_with_valid_values():
    try:
        single_parameter_validator({'name': 'page_size'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'name',
        errors,
    )
Esempio n. 53
0
def test_in_with_valid_values():
    try:
        single_parameter_validator({'description': 'The description'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'description',
        errors,
    )
Esempio n. 54
0
def test_name_with_valid_values():
    try:
        single_parameter_validator({'name': 'page_size'})
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors(
        'name',
        errors,
    )
Esempio n. 55
0
def test_type_validations_for_max_items_with_valid_types(type_):
    try:
        schema_validator({
            'maxItems': 5,
            'type': type_,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)
Esempio n. 56
0
def test_type_validation_for_min_properties_for_valid_types(type_):
    try:
        schema_validator({
            'minProperties': 5,
            'type': type_,
        })
    except ValidationError as err:
        errors = err.detail
    else:
        errors = {}

    assert_path_not_in_errors('type', errors)