How to use the uplink.converters.keys 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_arguments.py View on Github external
arguments.Timeout().modify_request(request_builder, 10)
        assert request_builder.info["timeout"] == 10


class TestContext(ArgumentTestCase, FuncDecoratorTestCase):
    type_cls = arguments.Context
    expected_converter_key = keys.Identity()

    def test_modify_request(self, request_builder):
        arguments.Context("key").modify_request(request_builder, "value")
        assert request_builder.context["key"] == "value"


class TestContextMap(ArgumentTestCase, FuncDecoratorTestCase):
    type_cls = arguments.ContextMap
    expected_converter_key = keys.Identity()

    def test_modify_request(self, request_builder):
        arguments.ContextMap().modify_request(request_builder, {"key": "value"})
        assert request_builder.context == {"key": "value"}

    def test_modify_request_not_mapping(self, request_builder):
        with pytest.raises(TypeError):
            arguments.ContextMap().modify_request(request_builder, "value")
github prkumar / uplink / tests / unit / test_arguments.py View on Github external
class TestHeaderMap(ArgumentTestCase, FuncDecoratorTestCase):
    type_cls = arguments.HeaderMap
    expected_converter_key = keys.Map(TestHeader.expected_converter_key)

    def test_modify_request(self, request_builder):
        arguments.HeaderMap().modify_request(
            request_builder, {"hello": "world"}
        )
        assert request_builder.info["headers"] == {"hello": "world"}


class TestField(ArgumentTestCase):
    type_cls = arguments.Field
    expected_converter_key = keys.CONVERT_TO_REQUEST_BODY

    def test_modify_request(self, request_builder):
        arguments.Field("hello").modify_request(request_builder, "world")
        assert request_builder.info["data"]["hello"] == "world"

    def test_modify_request_failure(self, request_builder):
        request_builder.info["data"] = object()
        with pytest.raises(arguments.Field.FieldAssignmentFailed):
            arguments.Field("hello").modify_request(request_builder, "world")


class TestFieldMap(ArgumentTestCase):
    type_cls = arguments.FieldMap
    expected_converter_key = keys.Map(TestField.expected_converter_key)

    def test_modify_request(self, request_builder):
github prkumar / uplink / tests / unit / test_converters.py View on Github external
kwargs = {"arg3": "arg3"}
        converter_factory_mock.create_string_converter.return_value = (
            converter_mock
        )
        registry = converters.ConverterFactoryRegistry(
            (converter_factory_mock,), *args, **kwargs
        )
        return_value = registry[converters.keys.CONVERT_TO_STRING]()
        converter_factory_mock.create_string_converter.assert_called_with(
            *args, **kwargs
        )
        assert return_value is converter_mock

        # Test with type that can't be handled by registry
        converter_factory_mock.create_string_converter.return_value = None
        return_value = registry[converters.keys.CONVERT_TO_STRING]()
        assert return_value is None
github prkumar / uplink / uplink / converters / __init__.py View on Github external
@ConverterFactoryRegistry.register(keys.CONVERT_FROM_RESPONSE_BODY)
def make_response_body_converter(factory):
    return factory.make_response_body_converter
github prkumar / uplink / uplink / arguments.py View on Github external
def converter_key(self):
        """Converts query mapping to request body."""
        if self._encoded:
            return keys.Map(keys.CONVERT_TO_STRING)
        else:
            return keys.Map(keys.Sequence(keys.CONVERT_TO_STRING))
github prkumar / uplink / uplink / arguments.py View on Github external
def converter_key(self):
        """Converts each part to the request body."""
        return keys.Map(keys.CONVERT_TO_REQUEST_BODY)
github prkumar / uplink / uplink / converters / __init__.py View on Github external
@ConverterFactoryRegistry.register(keys.CONVERT_TO_STRING)
def make_string_converter(factory):
    return factory.make_string_converter
github prkumar / uplink / uplink / arguments.py View on Github external
def converter_key(self):
        """Do not convert passed argument."""
        return keys.Identity()