How to use the uplink.converters.keys.Map 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
def test_converter_key_with_encoded(self):
        query = arguments.QueryMap(encoded=True)
        assert query.converter_key == keys.Map(keys.CONVERT_TO_STRING)
github prkumar / uplink / tests / unit / test_converters.py View on Github external
def test_convert(self):
        # Setup
        registry = converters.ConverterFactoryRegistry(
            (converters.StandardConverter(),)
        )
        key = converters.keys.Map(converters.keys.CONVERT_TO_STRING)

        # Run
        converter = registry[key](None)
        value = converter({"hello": 1})

        # Verify
        assert value == {"hello": "1"}
github prkumar / uplink / tests / unit / test_arguments.py View on Github external
class TestHeader(ArgumentTestCase, FuncDecoratorTestCase):
    type_cls = arguments.Header
    expected_converter_key = keys.CONVERT_TO_STRING

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

    def test_skip_none(self, request_builder):
        arguments.Header("hello").modify_request(request_builder, None)
        assert request_builder.info["headers"] == {}


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"
github prkumar / uplink / tests / unit / test_arguments.py View on Github external
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):
        arguments.FieldMap().modify_request(request_builder, {"hello": "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.FieldMap.FieldMapUpdateFailed):
            arguments.FieldMap().modify_request(request_builder, {})


class TestPart(ArgumentTestCase):
    type_cls = arguments.Part
    expected_converter_key = keys.CONVERT_TO_REQUEST_BODY

    def test_modify_request(self, request_builder):
github prkumar / uplink / tests / unit / test_arguments.py View on Github external
request_builder, None
        )
        assert request_builder.info["params"] == {"name": "null"}

    def test_converter_key_with_encoded(self):
        query = arguments.Query("name", encoded=True)
        assert query.converter_key == keys.CONVERT_TO_STRING

    def test_converter_type(self):
        query = arguments.Query("name", encoded=False)
        assert query.converter_key == keys.Sequence(keys.CONVERT_TO_STRING)


class TestQueryMap(ArgumentTestCase, FuncDecoratorTestCase):
    type_cls = arguments.QueryMap
    expected_converter_key = keys.Map(TestQuery.expected_converter_key)

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

    def test_modify_request_with_encoded(self, request_builder):
        arguments.QueryMap(encoded=True).modify_request(
            request_builder, {"name": "value"}
        )
        assert request_builder.info["params"] == "name=value"

    def test_converter_key_with_encoded(self):
        query = arguments.QueryMap(encoded=True)
        assert query.converter_key == keys.Map(keys.CONVERT_TO_STRING)

    def test_converter_type(self):
github prkumar / uplink / tests / unit / test_converters.py View on Github external
def test_eq(self):
        assert converters.keys.Map(0) == converters.keys.Map(0)
        assert not (converters.keys.Map(1) == converters.keys.Map(0))
        assert not (converters.keys.Map(1) == 1)
github prkumar / uplink / tests / unit / test_arguments.py View on Github external
with pytest.raises(arguments.FieldMap.FieldMapUpdateFailed):
            arguments.FieldMap().modify_request(request_builder, {})


class TestPart(ArgumentTestCase):
    type_cls = arguments.Part
    expected_converter_key = keys.CONVERT_TO_REQUEST_BODY

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


class TestPartMap(ArgumentTestCase):
    type_cls = arguments.PartMap
    expected_converter_key = keys.Map(TestPart.expected_converter_key)

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


class TestBody(ArgumentTestCase):
    type_cls = arguments.Body
    expected_converter_key = keys.CONVERT_TO_REQUEST_BODY

    def test_modify_request(self, request_builder):
        # Verify with dict
        arguments.Body().modify_request(request_builder, {"hello": "world"})
        assert request_builder.info["data"] == {"hello": "world"}

        # Verify with non-mapping
github prkumar / uplink / uplink / arguments.py View on Github external
def converter_key(self):
        """Converts type to request body."""
        return keys.Map(keys.CONVERT_TO_REQUEST_BODY)