Exemple #1
0
    def input_query(
        self,
        schema: typing.Any,
        processor: Processor = None,
        context: ContextInterface = None,
        error_http_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
        default_http_code: HTTPStatus = HTTPStatus.OK,
        as_list: typing.List[str] = None,
    ) -> typing.Callable[[typing.Callable[..., typing.Any]], typing.Any]:
        processor_factory = self._get_processor_factory(schema, processor)
        context = context or self._context_getter

        if self._async:
            decoration = AsyncInputQueryControllerWrapper(
                context=context,
                processor_factory=processor_factory,
                error_http_code=error_http_code,
                default_http_code=default_http_code,
                as_list=as_list,
            )
        else:
            decoration = InputQueryControllerWrapper(
                context=context,
                processor_factory=processor_factory,
                error_http_code=error_http_code,
                default_http_code=default_http_code,
                as_list=as_list,
            )

        def decorator(func):
            self._buffer.input_query = InputQueryDescription(decoration)
            return decoration.get_wrapper(func)

        return decorator
Exemple #2
0
    def test_unit__multi_query_param_values__ok__without_as_list(self):
        context = AgnosticContext(
            app=None, query_parameters=MultiDict((("user_id", "abc"), ("user_id", "def")))
        )
        processor = MySimpleProcessor()
        wrapper = InputQueryControllerWrapper(context, lambda: processor)

        @wrapper.get_wrapper
        def func(hapic_data=None):
            assert hapic_data
            assert isinstance(hapic_data, HapicData)
            # see MyControllerWrapper#before_wrapped_func
            assert "abc" == hapic_data.query.get("user_id")
            return hapic_data.query.get("user_id")

        result = func()
        assert result == "abc"
Exemple #3
0
    def input_query(
        self,
        schema: typing.Any,
        processor: ProcessorInterface = None,
        context: ContextInterface = None,
        error_http_code: HTTPStatus = HTTPStatus.BAD_REQUEST,
        default_http_code: HTTPStatus = HTTPStatus.OK,
    ) -> typing.Callable[[typing.Callable[..., typing.Any]], typing.Any]:
        processor = processor or MarshmallowInputProcessor()
        processor.schema = schema
        context = context or self._context_getter

        decoration = InputQueryControllerWrapper(
            context=context,
            processor=processor,
            error_http_code=error_http_code,
            default_http_code=default_http_code,
        )

        def decorator(func):
            self._buffer.input_query = InputQueryDescription(decoration)
            return decoration.get_wrapper(func)
        return decorator