How to use the uplink.commands.URIDefinitionBuilder function in uplink

To help you get started, we’ve selected a few uplink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_is_dynamic_setter(self):
        uri = commands.URIDefinitionBuilder(None)
        assert not uri.is_dynamic
        uri.is_dynamic = True
        assert uri.is_dynamic
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_is_static(self):
        assert not commands.URIDefinitionBuilder(None).is_static
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_add_variable_raise_error_when_name_is_not_in_static_path(self):
        uri = commands.URIDefinitionBuilder("/static/path")
        with pytest.raises(ValueError):
            uri.add_variable("variable")
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_auto_fill_when_not_done(
        self, mocker, annotation_handler_builder_mock
    ):
        # Setup
        argument_handler_builder = mocker.Mock(
            stub=arguments.ArgumentAnnotationHandlerBuilder
        )
        method_handler_builder = annotation_handler_builder_mock
        uri_definition_builder = mocker.Mock(spec=commands.URIDefinitionBuilder)
        builder = commands.RequestDefinitionBuilder(
            "method",
            uri_definition_builder,
            argument_handler_builder,
            method_handler_builder,
        )

        # Setup success condition
        argument_handler_builder.is_done.return_value = False
        argument_handler_builder.missing_arguments = ["arg1"]
        uri_definition_builder.remaining_variables = ["arg1"]

        # Verify
        builder.build()
        argument_handler_builder.set_annotations.assert_called_with(
            {"arg1": arguments.Path}
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_build(self):
        uri = commands.URIDefinitionBuilder("/static/path")
        assert uri.build() == "/static/path"
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_remaining_variables(self):
        uri = commands.URIDefinitionBuilder("/path/with/{variable}")
        assert uri.remaining_variables == set(["variable"])
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_remaining_variables(self):
        uri = commands.URIDefinitionBuilder("/path/with/{variable}")
        assert uri.remaining_variables == set(["variable"])
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_add_variable(self):
        uri = commands.URIDefinitionBuilder("/path/with/{variable}")
        assert "variable" in uri.remaining_variables
        uri.add_variable("variable")
        assert "variable" not in uri.remaining_variables
github prkumar / uplink / tests / unit / test_commands.py View on Github external
def test_build(self):
        uri = commands.URIDefinitionBuilder("/static/path")
        assert uri.build() == "/static/path"
github prkumar / uplink / uplink / commands.py View on Github external
def __call__(
        self, func, request_definition_builder_factory=RequestDefinitionBuilder
    ):
        spec = utils.get_arg_spec(func)
        arg_handler = arguments.ArgumentAnnotationHandlerBuilder(
            func, spec.args
        )
        builder = request_definition_builder_factory(
            self._method,
            URIDefinitionBuilder(self._uri),
            arg_handler,
            decorators.MethodAnnotationHandlerBuilder(),
        )

        # Need to add the annotations after constructing the request
        # definition builder so it has a chance to attach its listener.
        arg_handler.set_annotations(spec.annotations)

        # Use return value type hint as expected return type
        if spec.return_annotation is not None:
            builder = returns.schema(spec.return_annotation)(builder)
        functools.update_wrapper(builder, func)
        builder = self._add_args(builder)
        return builder