mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
Merge pull request #795 from httprunner/leo_dev
2.4.3 (2019-12-16) **Added** - feat: load api content on demand **Changed** - refactor: use poetry>=1.0.0 - test: migrate from travis CI to github actions - test: migrate from coveralls to codecov - test: run matrix tests on linux/macos/~~windows~~ and Python 2.7/3.5/3.6/3.7/3.8
This commit is contained in:
@@ -2,9 +2,15 @@
|
||||
|
||||
## 2.4.4 (2019-12-17)
|
||||
|
||||
**Added**
|
||||
|
||||
- feat: add keyword `body` to reference response body
|
||||
|
||||
**Changed**
|
||||
|
||||
- refactor: dumps request and response headers/body, display indented json in report
|
||||
- refactor: dumps request/response headers, display indented json in html report
|
||||
- refactor: dumps request/response body if it is in json format, display indented json in html report
|
||||
- change: unify response field(content/json/text) to `body` in html report
|
||||
|
||||
## 2.4.3 (2019-12-16)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__version__ = "2.4.3"
|
||||
__version__ = "2.4.4"
|
||||
__description__ = "One-stop solution for HTTP(S) testing."
|
||||
|
||||
__all__ = ["__version__", "__description__"]
|
||||
|
||||
@@ -111,18 +111,18 @@ class HttpSession(requests.Session):
|
||||
|
||||
if "image" in content_type:
|
||||
# response is image type, record bytes content only
|
||||
req_resp_dict["response"]["content"] = resp_obj.content
|
||||
req_resp_dict["response"]["body"] = resp_obj.content
|
||||
else:
|
||||
try:
|
||||
# try to record json data
|
||||
if isinstance(resp_obj, response.ResponseObject):
|
||||
req_resp_dict["response"]["json"] = resp_obj.json
|
||||
req_resp_dict["response"]["body"] = resp_obj.json
|
||||
else:
|
||||
req_resp_dict["response"]["json"] = resp_obj.json()
|
||||
req_resp_dict["response"]["body"] = resp_obj.json()
|
||||
except ValueError:
|
||||
# only record at most 512 text charactors
|
||||
resp_text = resp_obj.text
|
||||
req_resp_dict["response"]["text"] = omit_long_data(resp_text)
|
||||
req_resp_dict["response"]["body"] = omit_long_data(resp_text)
|
||||
|
||||
# log response details in debug mode
|
||||
log_print(req_resp_dict, "response")
|
||||
|
||||
@@ -11,7 +11,7 @@ from jinja2 import Template, escape
|
||||
from requests.cookies import RequestsCookieJar
|
||||
|
||||
from httprunner import __version__, logger
|
||||
from httprunner.compat import basestring, bytes, json, numeric_types
|
||||
from httprunner.compat import basestring, bytes, json, numeric_types, JSONDecodeError
|
||||
|
||||
|
||||
def get_platform():
|
||||
@@ -163,6 +163,13 @@ def __stringify_request(request_data):
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
if key == "body":
|
||||
try:
|
||||
# request body is in json format
|
||||
value = json.loads(value)
|
||||
except JSONDecodeError:
|
||||
pass
|
||||
|
||||
elif not isinstance(value, (basestring, numeric_types, Iterable)):
|
||||
# class instance, e.g. MultipartEncoder()
|
||||
value = repr(value)
|
||||
@@ -211,7 +218,7 @@ def __stringify_response(response_data):
|
||||
if not encoding or encoding == "None":
|
||||
encoding = "utf-8"
|
||||
|
||||
if key == "content" and "image" in response_data["content_type"]:
|
||||
if key == "body" and "image" in response_data["content_type"]:
|
||||
# display image
|
||||
value = "data:{};base64,{}".format(
|
||||
response_data["content_type"],
|
||||
|
||||
@@ -175,7 +175,7 @@ class ResponseObject(object):
|
||||
raise exceptions.ExtractFailure(err_msg)
|
||||
|
||||
# response body
|
||||
elif top_query in ["content", "text", "json"]:
|
||||
elif top_query in ["body", "content", "text", "json"]:
|
||||
try:
|
||||
body = self.json
|
||||
except exceptions.JSONDecodeError:
|
||||
|
||||
@@ -250,14 +250,14 @@
|
||||
<tr>
|
||||
<th>{{key}}</th>
|
||||
<td>
|
||||
{% if key == "content" %}
|
||||
{% if key == "headers" %}
|
||||
<pre>{{ value | e }}</pre>
|
||||
{% elif key == "body" %}
|
||||
{% if "image" in req_resp.response.content_type %}
|
||||
<img src="{{ req_resp.response.content }}" />
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
{% elif key in ["headers", "text", "json"] %}
|
||||
<pre>{{ value | e }}</pre>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "httprunner"
|
||||
version = "2.4.3"
|
||||
version = "2.4.4"
|
||||
description = "One-stop solution for HTTP(S) testing."
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
||||
@@ -268,7 +268,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["stat"]["testcases"]["total"], 1)
|
||||
self.assertEqual(summary["stat"]["teststeps"]["total"], 1)
|
||||
resp_json = json.loads(summary["details"][0]["records"][0]["meta_datas"]["data"][0]["response"]["json"])
|
||||
resp_json = json.loads(summary["details"][0]["records"][0]["meta_datas"]["data"][0]["response"]["body"])
|
||||
self.assertEqual(
|
||||
resp_json["data"],
|
||||
"abc"
|
||||
|
||||
Reference in New Issue
Block a user