Beispiel #1
0
    def test_call_with_args(self, mocker, annotation_mock):
        # Setup
        def func():
            pass

        args = mocker.patch("uplink.decorators.args")

        # Verify: using sequence
        http_method = commands.HttpMethod("METHOD",
                                          uri="/{hello}",
                                          args=(annotation_mock, ))
        http_method(func)
        args.assert_called_with(annotation_mock)

        # Verify: using mapping
        http_method = commands.HttpMethod("METHOD",
                                          uri="/{hello}",
                                          args={"arg1": "value"})
        http_method(func)
        args.assert_called_with(arg1="value")
Beispiel #2
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)
Beispiel #3
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