def test_api_check_default_succeed(property_spec): definitions = { 'injected_definition': { 'properties': { 'property': property_spec, }, }, } # Success if no exception are raised validate_definitions(definitions, lambda x: x)
def test_api_check_default_succeed(property_spec): definitions = { 'injected_definition': { 'properties': { 'property': property_spec, }, }, } # Success if no exception are raised validate_definitions(definitions, lambda x: x)
def test_multiple_types_fail(): definitions = { 'definition_1': { 'type': ['number', 'boolean'], }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert excinfo.value.args[0].startswith('type must be a string; lists are not allowed')
def test_type_array_without_items_succeed_fails(): definitions = { 'definition_1': { 'type': 'array', }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert str(excinfo.value) == 'Definition of type array must define `items` property (definition #/definitions/definition_1).'
def test_type_array_with_items_succeed_validation(): definitions = { 'definition_1': { 'type': 'array', 'items': { 'type': 'string', }, }, } # Success if no exception are raised validate_definitions(definitions, lambda x: x)
def test_type_array_with_items_succeed_validation(): definitions = { 'definition_1': { 'type': 'array', 'items': { 'type': 'string', }, }, } # Success if no exception are raised validate_definitions(definitions, lambda x: x)
def test_multiple_types_fail(): definitions = { 'definition_1': { 'type': ['number', 'boolean'], }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert excinfo.value.args[0].startswith( 'type must be a string; lists are not allowed')
def test_type_array_without_items_succeed_fails(): definitions = { 'definition_1': { 'type': 'array', }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert str( excinfo.value ) == 'Definition of type array must define `items` property (definition #/definitions/definition_1).'
def test_multiple_types_fail(): definitions = { 'definition_1': { 'type': ['number', 'boolean'], }, } with pytest.raises( SwaggerValidationError, match= r"In definition of .*, type must be a string; lists are not allowed \(.*\)", ) as excinfo: validate_definitions(definitions, lambda x: x) assert str(definitions['definition_1']['type']) in str(excinfo.value)
def test_api_check_default_fails(property_spec, validator, instance): definitions = { 'injected_definition': { 'properties': { 'property': property_spec, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) validation_error = excinfo.value.args[1] assert validation_error.instance == instance assert validation_error.validator == validator
def test_api_check_default_fails(property_spec, validator, instance): definitions = { 'injected_definition': { 'properties': { 'property': property_spec, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) validation_error = excinfo.value.args[1] assert validation_error.instance == instance assert validation_error.validator == validator
def test_inline_model_is_not_valid_validation_fails(): definitions = { 'definition_1': { 'properties': { 'property': { 'type': 'array', }, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert str(excinfo.value) == 'Definition of type array must define `items` property ' \ '(definition #/definitions/definition_1/properties/property).'
def test_inline_model_is_not_valid_validation_fails(): definitions = { 'definition_1': { 'properties': { 'property': { 'type': 'array', }, }, }, } with pytest.raises(SwaggerValidationError) as excinfo: validate_definitions(definitions, lambda x: x) assert str(excinfo.value) == 'Definition of type array must define `items` property ' \ '(definition #/definitions/definition_1/properties/property).'