mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
prepare_kwargs: reference kwargs do not need to return
This commit is contained in:
+2
-4
@@ -12,15 +12,13 @@ from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
|
|||||||
absolute_http_url_regexp = re.compile(r"^https?://", re.I)
|
absolute_http_url_regexp = re.compile(r"^https?://", re.I)
|
||||||
|
|
||||||
|
|
||||||
def process_kwargs(method, **kwargs):
|
def prepare_kwargs(method, kwargs):
|
||||||
if method == "POST":
|
if method == "POST":
|
||||||
# if request content-type is application/json, request data should be dumped
|
# if request content-type is application/json, request data should be dumped
|
||||||
content_type = kwargs.get("headers", {}).get("content-type", "")
|
content_type = kwargs.get("headers", {}).get("content-type", "")
|
||||||
if content_type.startswith("application/json") and "data" in kwargs:
|
if content_type.startswith("application/json") and "data" in kwargs:
|
||||||
kwargs["data"] = json.dumps(kwargs["data"])
|
kwargs["data"] = json.dumps(kwargs["data"])
|
||||||
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
|
|
||||||
class ApiResponse(Response):
|
class ApiResponse(Response):
|
||||||
|
|
||||||
@@ -152,7 +150,7 @@ class HttpSession(requests.Session):
|
|||||||
Safe mode has been removed from requests 1.x.
|
Safe mode has been removed from requests 1.x.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
kwargs = process_kwargs(method, **kwargs)
|
prepare_kwargs(method, kwargs)
|
||||||
return requests.Session.request(self, method, url, **kwargs)
|
return requests.Session.request(self, method, url, **kwargs)
|
||||||
except (MissingSchema, InvalidSchema, InvalidURL):
|
except (MissingSchema, InvalidSchema, InvalidURL):
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from ate.client import HttpSession, process_kwargs
|
from ate.client import HttpSession, prepare_kwargs
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
class TestHttpClient(ApiServerUnittest):
|
class TestHttpClient(ApiServerUnittest):
|
||||||
@@ -36,7 +36,7 @@ class TestHttpClient(ApiServerUnittest):
|
|||||||
self.assertEqual(201, resp.status_code)
|
self.assertEqual(201, resp.status_code)
|
||||||
self.assertEqual(True, resp.json()['success'])
|
self.assertEqual(True, resp.json()['success'])
|
||||||
|
|
||||||
def test_process_kwargs(self):
|
def test_prepare_kwargs(self):
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"headers": {
|
"headers": {
|
||||||
"content-type": "application/json; charset=utf-8"
|
"content-type": "application/json; charset=utf-8"
|
||||||
@@ -46,6 +46,6 @@ class TestHttpClient(ApiServerUnittest):
|
|||||||
"b": 2
|
"b": 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kwargs = process_kwargs("POST", **kwargs)
|
prepare_kwargs("POST", kwargs)
|
||||||
self.assertIn('"a": 1', kwargs["data"])
|
self.assertIn('"a": 1', kwargs["data"])
|
||||||
self.assertIn('"b": 2', kwargs["data"])
|
self.assertIn('"b": 2', kwargs["data"])
|
||||||
|
|||||||
Reference in New Issue
Block a user