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_headers_no_content_type_change(self, req, includes, extra_headers):
"""Sending a file doesn't set the content type as json"""
del req["data"]
req["files"] = ["abc"]
args = get_request_args(req, includes)
assert "content-type" not in [i.lower() for i in args["headers"].keys()]
def test_nested_params_encoded(self, req, includes):
req["params"] = {"a": {"b": {"c": "d"}}}
args = get_request_args(req, includes)
assert args["params"]["a"] == "%7B%22b%22%3A+%7B%22c%22%3A+%22d%22%7D%7D"
def test_array_substitution(self, req, includes):
args = get_request_args(req, includes)
assert args["data"]["array"] == ["def456", "def456"]
def test_file_and_json_fails(self, req, includes):
"""Can't send json and files at once"""
req["files"] = ["abc"]
req["json"] = {"key": "value"}
with pytest.raises(exceptions.BadSchemaError):
get_request_args(req, includes)
def test_file_and_data_succeeds(self, req, includes):
"""Can send form data and files at once"""
req["files"] = ["abc"]
get_request_args(req, includes)
def test_no_override_method(self, req, includes):
req["method"] = "POST"
args = get_request_args(req, includes)
assert args["method"] == "POST"
def test_default_method_raises_with_body(self, req, includes, body_key):
del req["method"]
del req["data"]
req[body_key] = {"a": "b"}
with pytest.warns(RuntimeWarning):
get_request_args(req, includes)
def test_no_default_content_type(self, req, includes, extra):
del req["headers"]["Content-Type"]
req.pop("json", {})
req.pop("data", {})
req.update(**extra)
args = get_request_args(req, includes)
# Requests will automatically set content type headers for json/form encoded data so we don't need to
with pytest.raises(KeyError):
assert args["headers"]["content-type"]
def test_no_override_content_type_case_insensitive(self, req, includes):
del req["headers"]["Content-Type"]
req["headers"]["content-type"] = "application/x-www-form-urlencoded"
args = get_request_args(req, includes)
assert args["headers"]["content-type"] == "application/x-www-form-urlencoded"
def test_no_set_content_type(self, req, includes):
del req["headers"]["Content-Type"]
args = get_request_args(req, includes)
with pytest.raises(KeyError):
assert args["headers"]["content-type"]