bugfix: represent unicode literals in html report

This commit is contained in:
debugtalk
2018-03-27 17:29:05 +08:00
parent 7d15096974
commit a1357834b4
3 changed files with 11 additions and 6 deletions

View File

@@ -113,12 +113,16 @@ class HttpSession(requests.Session):
self.meta_data["request_body"] = response.request.body
self.meta_data["status_code"] = response.status_code
self.meta_data["response_headers"] = response.headers
self.meta_data["response_content"] = response.content
try:
self.meta_data["response_body"] = response.json()
except ValueError:
self.meta_data["response_body"] = response.content
msg = "response details:\n"
msg += "> status_code: {}\n".format(self.meta_data["status_code"])
msg += "> headers: {}\n".format(self.meta_data["response_headers"])
msg += "> content: {}".format(self.meta_data["response_content"])
msg += "> body: {}".format(self.meta_data["response_body"])
logger.log_debug(msg)
# get the length of the content, but if the argument stream is set to True, we take

View File

@@ -5,11 +5,12 @@ import os
import platform
import time
import unittest
from collections import Iterable
from datetime import datetime
from httprunner import logger
from httprunner.__about__ import __version__
from httprunner.compat import basestring, bytes, numeric_types
from httprunner.compat import basestring, bytes, json, numeric_types
from jinja2 import Template
from requests.structures import CaseInsensitiveDict
@@ -62,13 +63,13 @@ def make_json_serializable(raw_json):
value = value.decode("utf-8")
elif isinstance(value, CaseInsensitiveDict):
value = dict(value)
elif not isinstance(value, (basestring, numeric_types)):
elif not isinstance(value, (basestring, numeric_types, Iterable)):
# class instance, e.g. MultipartEncoder()
value = repr(value)
serializable_json[key] = value
return serializable_json
return json.dumps(serializable_json, indent=2, ensure_ascii=False)
class HtmlTestResult(unittest.TextTestResult):

View File

@@ -188,7 +188,7 @@
<div class="popup">
<h2>Request and Response data</h2>
<a class="close" href="#">&times;</a>
<div class="content"><pre>{{ record.meta_data | tojson(indent=2) | safe }}</pre></div>
<div class="content"><pre>{{ record.meta_data | safe }}</pre></div>
</div>
</div>