def spec(self, info, paths, servers): spec = { "info": info, "servers": servers, "paths": paths, } return SpecPath.from_spec(spec)
def test_schema_any_all_of_invalid_properties( self, value, unmarshaller_factory): spec = { 'allOf': [ { 'type': 'object', 'required': ['somestr'], 'properties': { 'somestr': { 'type': 'string', }, }, }, { 'type': 'object', 'required': ['someint'], 'properties': { 'someint': { 'type': 'integer', }, }, } ], 'additionalProperties': False, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_object_no_one_of(self, value, validator_factory): one_of = [ { 'type': 'object', 'required': [ 'test1', ], 'properties': { 'test1': { 'type': 'string', }, }, }, { 'type': 'object', 'required': [ 'test2', ], 'properties': { 'test2': { 'type': 'string', }, }, }, ] spec = { 'type': 'object', 'oneOf': one_of, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_object_no_one_of(self, value, validator_factory): one_of = [ { "type": "object", "required": [ "test1", ], "properties": { "test1": { "type": "string", }, }, }, { "type": "object", "required": [ "test2", ], "properties": { "test2": { "type": "string", }, }, }, ] spec = { "type": "object", "oneOf": one_of, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_schema_any_all_of_invalid_properties( self, value, unmarshaller_factory ): spec = { "allOf": [ { "type": "object", "required": ["somestr"], "properties": { "somestr": { "type": "string", }, }, }, { "type": "object", "required": ["someint"], "properties": { "someint": { "type": "integer", }, }, }, ], "additionalProperties": False, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def spec(self, info, paths, servers): spec = { 'info': info, 'servers': servers, 'paths': paths, } return SpecPath.from_spec(spec)
def test_array_no_schema(self, value, validator_factory): spec = { 'type': 'array', } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_string_invalid(self, value, validator_factory): spec = { "type": "string", } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_boolean_invalid(self, value, validator_factory): spec = { 'type': 'boolean', } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_object_not_an_object(self, value, validator_factory): spec = { 'type': 'object', } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_string_pattern_invalid(self, value, validator_factory): spec = { 'type': 'string', 'pattern': 'baz', } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_string_max_length_invalid(self, value, validator_factory): spec = { 'type': 'string', 'maxLength': 1, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_string_format_byte_invalid(self, value, validator_factory): spec = { 'type': 'string', 'format': 'byte', } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_null(self, schema_type, validator_factory): spec = { 'type': schema_type, } schema = SpecPath.from_spec(spec) value = None with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_number_multiple_of_invalid(self, value, validator_factory): spec = { 'type': 'number', 'multipleOf': 3, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_schema_type_invalid(self, unmarshaller_factory): spec = { "type": "integer", } schema = SpecPath.from_spec(spec) value = "test" with pytest.raises(InvalidSchemaFormatValue): unmarshaller_factory(schema).unmarshal(value)
def test_object_additional_properties(self, value, validator_factory): spec = { 'type': 'object', } schema = SpecPath.from_spec(spec) result = validator_factory(schema).validate(value) assert result is None
def test_boolean(self, value, validator_factory): spec = { 'type': 'boolean', } schema = SpecPath.from_spec(spec) result = validator_factory(schema).validate(value) assert result is None
def test_boolean_string_invalid(self, unmarshaller_factory): spec = { 'type': 'boolean', } schema = SpecPath.from_spec(spec) value = 'True' with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_schema_type_invalid(self, unmarshaller_factory): spec = { 'type': 'integer', } schema = SpecPath.from_spec(spec) value = 'test' with pytest.raises(InvalidSchemaFormatValue): unmarshaller_factory(schema).unmarshal(value)
def test_integer_invalid(self, unmarshaller_factory): spec = { 'type': 'integer', } schema = SpecPath.from_spec(spec) value = 'abc' with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_string_float_invalid(self, unmarshaller_factory): spec = { 'type': 'string', } schema = SpecPath.from_spec(spec) value = 1.23 with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_defaults(self, location, expected): spec = { 'name': 'default', 'in': location, } param = SpecPath.from_spec(spec) result = get_style(param) assert result == expected
def test_defaults(self, location, expected): spec = { "name": "default", "in": location, } param = SpecPath.from_spec(spec) result = get_style(param) assert result == expected
def test_integer_invalid(self, unmarshaller_factory): spec = { "type": "integer", } schema = SpecPath.from_spec(spec) value = "abc" with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_boolean_string_invalid(self, unmarshaller_factory): spec = { "type": "boolean", } schema = SpecPath.from_spec(spec) value = "True" with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_non_string_empty_value(self, schema_type, unmarshaller_factory): spec = { 'type': schema_type, } schema = SpecPath.from_spec(spec) value = '' with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_integer_maximum_invalid(self, value, validator_factory): spec = { 'type': 'integer', 'maximum': 3, } schema = SpecPath.from_spec(spec) with pytest.raises(InvalidSchemaValue): validator_factory(schema).validate(value)
def test_number_string_invalid(self, unmarshaller_factory): spec = { 'type': 'number', } schema = SpecPath.from_spec(spec) value = '1.23' with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)
def test_number_string_invalid(self, unmarshaller_factory): spec = { "type": "number", } schema = SpecPath.from_spec(spec) value = "1.23" with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value)