Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def argument_mock(mocker):
return mocker.Mock(spec=arguments.ArgumentAnnotation)
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):
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"}
def test_add_annotation_with_no_missing_arguments(self, argument_mock):
def dummy():
pass
builder = arguments.ArgumentAnnotationHandlerBuilder(dummy, [], False)
with pytest.raises(arguments.ExhaustedArguments):
builder.add_annotation(argument_mock)
def test_modify_request(self, request_builder):
arguments.Context("key").modify_request(request_builder, "value")
assert request_builder.context["key"] == "value"
def test_encode_none(self, request_builder):
arguments.Query("name", encode_none="null").modify_request(
request_builder, None
)
assert request_builder.info["params"] == {"name": "null"}
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):
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"}
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}
)
def test_modify_request(self, request_builder):
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")