Beispiel #1
0
 def spec(self, info, paths, servers):
     spec = {
         "info": info,
         "servers": servers,
         "paths": paths,
     }
     return SpecPath.from_spec(spec)
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
 def spec(self, info, paths, servers):
     spec = {
         'info': info,
         'servers': servers,
         'paths': paths,
     }
     return SpecPath.from_spec(spec)
Beispiel #7
0
    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)
Beispiel #8
0
    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)
Beispiel #9
0
    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)
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    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)
Beispiel #15
0
    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)
Beispiel #16
0
    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)
Beispiel #17
0
    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
Beispiel #18
0
    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
Beispiel #19
0
    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)
Beispiel #20
0
    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)
Beispiel #21
0
    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)
Beispiel #22
0
    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)
Beispiel #23
0
    def test_defaults(self, location, expected):
        spec = {
            'name': 'default',
            'in': location,
        }
        param = SpecPath.from_spec(spec)
        result = get_style(param)

        assert result == expected
Beispiel #24
0
    def test_defaults(self, location, expected):
        spec = {
            "name": "default",
            "in": location,
        }
        param = SpecPath.from_spec(spec)
        result = get_style(param)

        assert result == expected
Beispiel #25
0
    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)
Beispiel #26
0
    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)
Beispiel #27
0
    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)
Beispiel #28
0
    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)
Beispiel #29
0
    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)
Beispiel #30
0
    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)