Ejemplo n.º 1
0
    def test_call_with_return_annotation(self, mocker):
        # Setup
        def func():
            pass

        sig = utils.Signature(args=[],
                              annotations={},
                              return_annotation="return_annotation")
        mocker.patch("uplink.utils.get_arg_spec").return_value = sig
        returns = mocker.patch("uplink.returns.schema")
        http_method = commands.HttpMethod("METHOD", uri="/{hello}")
        http_method(func)

        # Verify: build is wrapped with decorators.returns
        returns.assert_called_with(sig.return_annotation)
Ejemplo n.º 2
0
    def test_call(self, mocker, annotation_mock):
        # Setup
        def func():
            pass

        sig = utils.Signature(args=["self", "arg1", "arg2"],
                              annotations={"arg1": annotation_mock},
                              return_annotation=None)
        mocker.patch("uplink.utils.get_arg_spec").return_value = sig

        http_method = commands.HttpMethod("METHOD", uri="/{hello}")
        builder = http_method(func)
        assert isinstance(builder, commands.RequestDefinitionBuilder)
        assert builder.__name__ == func.__name__
        assert builder.method == "METHOD"
        assert list(builder.uri.remaining_variables) == ["hello"]

        missing_arguments = builder.argument_handler_builder.missing_arguments
        expected_missing = set(sig.args[1:]) - set(sig.annotations.keys())
        assert set(missing_arguments) == expected_missing