Esempio n. 1
0
    def test_query_valid(self):
        param = Parameter('param', 'query')
        value = 'test'

        result = param.unmarshal(value)

        assert result == value
Esempio n. 2
0
    def test_query_schema_type_invalid(self):
        schema = Schema('integer', _source={'type': 'integer'})
        param = Parameter('param', 'query', schema=schema)
        value = 'test'

        with pytest.raises(InvalidParameterValue):
            param.unmarshal(value)
Esempio n. 3
0
    def test_query_allow_empty_value(self):
        param = Parameter('param', 'query', allow_empty_value=True)
        value = ''

        result = param.unmarshal(value)

        assert result == value
Esempio n. 4
0
    def test_deprecated(self):
        param = Parameter('param', 'query', deprecated=True)
        value = 'test'

        with pytest.warns(DeprecationWarning):
            result = param.cast(value)

        assert result == value
Esempio n. 5
0
    def create(self, parameter_spec, parameter_name=None):
        parameter_deref = self.dereferencer.dereference(parameter_spec)

        parameter_name = parameter_name or parameter_deref['name']
        parameter_in = parameter_deref.get('in', 'header')

        allow_empty_value = parameter_deref.get('allowEmptyValue')
        required = parameter_deref.get('required', False)

        style = parameter_deref.get('style')
        explode = parameter_deref.get('explode')

        schema_spec = parameter_deref.get('schema', None)
        schema = None
        if schema_spec:
            schema, _ = self.schemas_registry.get_or_create(schema_spec)

        content_spec = parameter_deref.get('content', None)
        content = None
        if content_spec:
            content = self.content_factory.create(content_spec)

        extensions = self.extensions_generator.generate(parameter_deref)

        return Parameter(
            parameter_name, parameter_in,
            schema=schema, required=required,
            allow_empty_value=allow_empty_value,
            style=style, explode=explode, content=content,
            extensions=extensions,
        )
Esempio n. 6
0
    def test_schema_type_invalid(self, unmarshaller_factory):
        schema = Schema('integer', _source={'type': 'integer'})
        param = Parameter('param', 'query', schema=schema)
        value = 'test'

        with pytest.raises(InvalidSchemaFormatValue):
            unmarshaller_factory(param.schema).unmarshal(value)
Esempio n. 7
0
    def test_query_valid(self, deserializer_factory):
        param = Parameter('param', 'query')
        value = 'test'

        result = deserializer_factory(param)(value)

        assert result == value
Esempio n. 8
0
    def create(self, parameter_spec, parameter_name=None):
        parameter_deref = self.dereferencer.dereference(parameter_spec)

        parameter_name = parameter_name or parameter_deref['name']
        parameter_in = parameter_deref.get('in', 'header')
        allow_empty_value = parameter_deref.get('allowEmptyValue')
        required = parameter_deref.get('required', False)

        style = parameter_deref.get('style')
        explode = parameter_deref.get('explode')

        schema_spec = parameter_deref.get('schema', None)
        example = parameter_deref.get('example', None)
        minimum = parameter_deref.get('minimum', None)
        maximum = parameter_deref.get('maximum', None)

        schema = None
        if schema_spec:
            schema, _ = self.schemas_registry.get_or_create(schema_spec)

        return Parameter(
            parameter_name,
            parameter_in,
            schema=schema,
            required=required,
            allow_empty_value=allow_empty_value,
            style=style,
            explode=explode,
            example=example,
            minimum=minimum,
            maximum=maximum,
        )
Esempio n. 9
0
    def test_schema_custom_format_invalid(self, unmarshaller_factory):
        class CustomFormatter(Formatter):
            def unmarshal(self, value):
                raise ValueError

        formatter = CustomFormatter()
        custom_format = 'custom'
        custom_formatters = {
            custom_format: formatter,
        }
        schema = Schema(
            'string',
            schema_format=custom_format,
            _source={
                'type': 'string',
                'format': 'custom'
            },
        )
        param = Parameter('param', 'query', schema=schema)
        value = 'test'

        with pytest.raises(InvalidSchemaFormatValue):
            unmarshaller_factory(
                param.schema,
                custom_formatters=custom_formatters,
            ).unmarshal(value)
Esempio n. 10
0
    def test_deprecated(self, deserializer_factory):
        param = Parameter('param', 'query', deprecated=True)
        value = 'test'

        with pytest.warns(DeprecationWarning):
            result = deserializer_factory(param)(value)

        assert result == value
Esempio n. 11
0
    def test_query_schema_custom_format_invalid(self):
        def custom_formatter(value):
            raise ValueError

        schema = Schema(
            'string',
            schema_format='custom',
            _source={
                'type': 'string',
                'format': 'custom'
            },
        )
        custom_formatters = {
            'custom': custom_formatter,
        }
        param = Parameter('param', 'query', schema=schema)
        value = 'test'

        with pytest.raises(InvalidParameterValue):
            param.unmarshal(value, custom_formatters=custom_formatters)
Esempio n. 12
0
 def parameter(self):
     return Parameter(self.path_parameter_name, 'path')
Esempio n. 13
0
    def test_query_empty(self, deserializer_factory):
        param = Parameter('param', 'query')
        value = ''

        with pytest.raises(EmptyParameterValue):
            deserializer_factory(param)(value)
Esempio n. 14
0
    def test_no_schema(self, unmarshaller_factory):
        param = Parameter('param', 'query')
        value = 'test'

        with pytest.raises(TypeError):
            unmarshaller_factory(param.schema).unmarshal(value)
Esempio n. 15
0
    def test_header(self):
        param = Parameter('param', 'header')

        assert param.allow_empty_value is False
        assert param.style == ParameterStyle.SIMPLE
        assert param.explode is False
Esempio n. 16
0
    def test_query_empty(self):
        param = Parameter('param', 'query')
        value = ''

        with pytest.raises(EmptyParameterValue):
            param.cast(value)
Esempio n. 17
0
    def test_cookie(self):
        param = Parameter('param', 'cookie')

        assert param.allow_empty_value is False
        assert param.style == ParameterStyle.FORM
        assert param.explode is True