mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 08:49:37 +08:00
fix #191: request data dumps
This commit is contained in:
@@ -137,7 +137,7 @@ def setup_hook_prepare_kwargs(method, url, kwargs):
|
|||||||
content_type = kwargs.get("headers", {}).get("content-type")
|
content_type = kwargs.get("headers", {}).get("content-type")
|
||||||
if content_type and "data" in kwargs:
|
if content_type and "data" in kwargs:
|
||||||
# if request content-type is application/json, request data should be dumped
|
# if request content-type is application/json, request data should be dumped
|
||||||
if content_type.startswith("application/json"):
|
if content_type.startswith("application/json") and isinstance(kwargs["data"], (dict, list)):
|
||||||
kwargs["data"] = json.dumps(kwargs["data"])
|
kwargs["data"] = json.dumps(kwargs["data"])
|
||||||
|
|
||||||
if isinstance(kwargs["data"], str):
|
if isinstance(kwargs["data"], str):
|
||||||
|
|||||||
@@ -106,3 +106,36 @@ class TestHttpRunner(ApiServerUnittest):
|
|||||||
self.assertTrue(summary["success"])
|
self.assertTrue(summary["success"])
|
||||||
self.assertEqual(summary["stat"]["testsRun"], 1)
|
self.assertEqual(summary["stat"]["testsRun"], 1)
|
||||||
self.assertIn("records", summary)
|
self.assertIn("records", summary)
|
||||||
|
|
||||||
|
def test_run_post_data(self):
|
||||||
|
testsets = [
|
||||||
|
{
|
||||||
|
"name": "post data",
|
||||||
|
"config": {
|
||||||
|
"path": ""
|
||||||
|
},
|
||||||
|
|
||||||
|
"testcases": [
|
||||||
|
{
|
||||||
|
"name": "post data",
|
||||||
|
"request": {
|
||||||
|
"url": "https://httpbin.org/post",
|
||||||
|
"method": "POST",
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
"data": "abc"
|
||||||
|
},
|
||||||
|
"validate": [
|
||||||
|
{"eq": ["status_code", 200]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
runner = HttpRunner().run(testsets)
|
||||||
|
summary = runner.summary
|
||||||
|
self.assertTrue(summary["success"])
|
||||||
|
self.assertEqual(summary["stat"]["testsRun"], 1)
|
||||||
|
self.assertEqual(summary["records"][0]["meta_data"]["response_body"]["data"], "abc")
|
||||||
|
|||||||
Reference in New Issue
Block a user