Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_converter_key_with_encoded(self):
query = arguments.QueryMap(encoded=True)
assert query.converter_key == keys.Map(keys.CONVERT_TO_STRING)
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"}
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"
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):
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):
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)
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
def converter_key(self):
"""Converts type to request body."""
return keys.Map(keys.CONVERT_TO_REQUEST_BODY)