Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")
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):
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
@ConverterFactoryRegistry.register(keys.CONVERT_FROM_RESPONSE_BODY)
def make_response_body_converter(factory):
return factory.make_response_body_converter
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))
def converter_key(self):
"""Converts each part to the request body."""
return keys.Map(keys.CONVERT_TO_REQUEST_BODY)
@ConverterFactoryRegistry.register(keys.CONVERT_TO_STRING)
def make_string_converter(factory):
return factory.make_string_converter
def converter_key(self):
"""Do not convert passed argument."""
return keys.Identity()