Esempio n. 1
0
    def test_integer_enum_string_invalid(self):
        schema = Schema('integer', enum=[1, 2, 3])
        value = '2'

        with pytest.raises(UnmarshalError):
            schema.unmarshal(value)
Esempio n. 2
0
    def test_number_multiple_of(self, value):
        schema = Schema('number', multiple_of=3)

        result = schema.validate(value)

        assert result is None
Esempio n. 3
0
    def test_string_invalid(self, value):
        schema = Schema('string')

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 4
0
    def test_number_maximum(self, value):
        schema = Schema('number', maximum=3)

        result = schema.validate(value)

        assert result is None
Esempio n. 5
0
    def test_number_exclusive_maximum(self, value):
        schema = Schema('number', maximum=3, exclusive_maximum=True)

        result = schema.validate(value)

        assert result is None
Esempio n. 6
0
    def test_integer_minimum(self, value):
        schema = Schema('integer', minimum=3)

        result = schema.validate(value)

        assert result is None
Esempio n. 7
0
    def test_number(self, value):
        schema = Schema('number')

        result = schema.validate(value)

        assert result is None
Esempio n. 8
0
    def test_number_format_float(self):
        schema = Schema('number', schema_format='float')
        value = 1.2
        result = schema.unmarshal(value)

        assert result == 1.2
Esempio n. 9
0
    def test_number_format_double(self):
        schema = Schema('number', schema_format='double')
        value = 1.2
        result = schema.unmarshal(value)

        assert result == 1.2
Esempio n. 10
0
    def test_boolean_string_invalid(self):
        schema = Schema('boolean')
        value = 'True'

        with pytest.raises(UnmarshallerStrictTypeError):
            schema.unmarshal(value)
Esempio n. 11
0
    def test_number_string_invalid(self):
        schema = Schema('number')
        value = '1.23'

        with pytest.raises(UnmarshallerStrictTypeError):
            schema.unmarshal(value)
Esempio n. 12
0
    def test_array_of_integer_string_invalid(self):
        schema = Schema('array', items=Schema('integer'))
        value = '123'

        with pytest.raises(UnmarshalValueError):
            schema.unmarshal(value)
Esempio n. 13
0
    def test_integer_invalid(self):
        schema = Schema('integer')
        value = 'abc'

        with pytest.raises(UnmarshallerStrictTypeError):
            schema.unmarshal(value)
Esempio n. 14
0
 def schema(self):
     properties = {
         'application/json': mock.sentinel.application_json,
         'text/csv': mock.sentinel.text_csv,
     }
     return Schema('object', properties=properties)
Esempio n. 15
0
    def test_array_invalid(self, value):
        schema = Schema('array')

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 16
0
 def test_schema_any_one_of(self):
     schema = Schema(one_of=[
         Schema('string'),
         Schema('array', items=Schema('string')),
     ])
     assert schema.unmarshal(['hello']) == ['hello']
Esempio n. 17
0
    def test_integer(self, value):
        schema = Schema('integer')

        result = schema.validate(value)

        assert result is None
Esempio n. 18
0
 def test_schema_any(self):
     schema = Schema()
     assert schema.unmarshal('string') == 'string'
Esempio n. 19
0
    def test_integer_maximum_invalid(self, value):
        schema = Schema('integer', maximum=3)

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 20
0
    def test_null(self, schema_type):
        schema = Schema(schema_type)
        value = None

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 21
0
    def test_number_minimum_invalid(self, value):
        schema = Schema('number', minimum=3)

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 22
0
    def test_boolean(self, value):
        schema = Schema('boolean')

        result = schema.validate(value)

        assert result is None
Esempio n. 23
0
    def test_number_exclusive_maximum_invalid(self, value):
        schema = Schema('number', maximum=3, exclusive_maximum=True)

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 24
0
    def test_boolean_invalid(self, value):
        schema = Schema('boolean')

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 25
0
    def test_number_multiple_of_invalid(self, value):
        schema = Schema('number', multiple_of=3)

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 26
0
    def test_array_no_schema(self, value):
        schema = Schema('array')

        with pytest.raises(OpenAPISchemaError):
            schema.validate(value)
Esempio n. 27
0
    def test_string(self, value):
        schema = Schema('string')

        result = schema.validate(value)

        assert result is None
Esempio n. 28
0
    def test_array(self, value):
        schema = Schema('array', items=Schema('integer'))

        result = schema.validate(value)

        assert result is None
Esempio n. 29
0
    def test_string_format_date_invalid(self, value):
        schema = Schema('string', schema_format='date')

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)
Esempio n. 30
0
    def test_object_additional_propetries_false(self, value):
        schema = Schema('object', additional_properties=False)

        with pytest.raises(InvalidSchemaValue):
            schema.validate(value)