Esempio n. 1
0
def test_function_raises_exception_on_path_missing():
    @transmute_core.describe(paths=[])
    def func():
        pass

    with pytest.raises(transmute_core.InvalidTransmuteDefinition):
        TransmuteFunction(func)
def test_with_framework_arg():
    """ """
    tf = TransmuteFunction(with_framework_arg)
    extractor = ParamExtractorMock()
    args, kwargs = extractor.extract_params(default_context, tf,
                                            "application/json")
    assert args == ["framework_arg"]
    assert kwargs == {}
def test_extract_params_positional_args():
    """ if no arguments are passed, use the defaults """
    tf = TransmuteFunction(pos_type)
    extractor = ParamExtractorMock()
    args, kwargs = extractor.extract_params(default_context, tf,
                                            "application/json")
    assert args == ["query"]
    assert kwargs == {}
Esempio n. 4
0
    def add_transmute_route(self, *args):
        """
        two formats are accepted, for transmute routes. One allows
        for a more traditional aiohttp syntax, while the other
        allows for a flask-like variant.

        .. code-block:: python

            # if the path and method are not added in describe.
            add_transmute_route("GET", "/route", fn)

            # if the path and method are already added in describe
            add_transmute_route(fn)
        """
        if len(args) == 1:
            fn = args[0]
        elif len(args) == 3:
            methods, paths, fn = args
            describe(methods=methods, paths=paths)(fn)
        else:
            raise ValueError(
                "expected one or three arguments for add_transmute_route!"
            )
        transmute_func = TransmuteFunction(
            fn,
            args_not_from_request=["request"]
        )
        handler = create_handler(
            transmute_func, context=self._transmute_context
        )
        swagger_path = transmute_func.get_swagger_path(self._transmute_context)
        for p in transmute_func.paths:
            # add to swagger
            if p not in self._swagger:
                self._swagger[p] = swagger_path
            else:
                for method, definition in swagger_path.items():
                    setattr(self._swagger[p], method, definition)

            # add to aiohttp
            aiohttp_path = self._convert_to_aiohttp_path(p)
            resource = self.add_resource(aiohttp_path)
            for method in transmute_func.methods:
                resource.add_route(method, handler)
def test_extract_params_honor_as_non_list(typ):
    @describe(paths=["/"], query_parameters=["query"])
    @annotate({"query": typ})
    def f(query=1):
        pass

    tf = TransmuteFunction(f)
    extractor = ParamExtractorMock()
    args, kwargs = extractor.extract_params(default_context, tf, None)
    assert kwargs["query"] == "query"
def all_param_type_transmute_func():
    """ ensure retrieval of all parameter types is honored. """
    return TransmuteFunction(all_param_type)
Esempio n. 7
0
def func():
    return TransmuteFunction(raw_func)