Merge pull request #334 from HttpRunner/bugfix

fix #330 #332
This commit is contained in:
debugtalk
2018-08-03 23:48:35 +08:00
committed by GitHub
3 changed files with 8 additions and 10 deletions
+3 -5
View File
@@ -120,9 +120,7 @@ def stringify_data(meta_data, request_or_response):
} }
""" """
headers = meta_data[request_or_response]["headers"] headers = meta_data[request_or_response]["headers"]
request_or_response_dict = meta_data[request_or_response] request_or_response_dict = meta_data[request_or_response]
response_content_type = meta_data["response"]["content_type"]
for key, value in request_or_response_dict.items(): for key, value in request_or_response_dict.items():
@@ -135,11 +133,11 @@ def stringify_data(meta_data, request_or_response):
if not encoding or encoding == "None": if not encoding or encoding == "None":
encoding = "utf-8" encoding = "utf-8"
if request_or_response == "response" and key == "content" and "image" in response_content_type: if request_or_response == "response" and key == "content" \
and "image" in meta_data["response"]["content_type"]:
# display image # display image
meta_data["response"]["content_type"] = "image"
value = "data:{};base64,{}".format( value = "data:{};base64,{}".format(
response_content_type, meta_data["response"]["content_type"],
b64encode(value).decode(encoding) b64encode(value).decode(encoding)
) )
else: else:
+4 -4
View File
@@ -272,20 +272,20 @@
<div style="overflow: auto"> <div style="overflow: auto">
<table> <table>
{% for key, value in record.meta_data.response.items() %} {% for key, value in record.meta_data.response.items() %}
{% if key in ["content", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type"] %} {% if key in ["text", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type"] %}
{% continue %} {% continue %}
{% endif %} {% endif %}
<tr> <tr>
<th>{{key}}</th> <th>{{key}}</th>
<td> <td>
{% if key == "headers" %} {% if key == "headers" %}
{% for header_key, header_value in record.meta_data.request.headers.items() %} {% for header_key, header_value in record.meta_data.response.headers.items() %}
<div> <div>
<strong>{{ header_key }}</strong>: {{ header_value }} <strong>{{ header_key }}</strong>: {{ header_value }}
</div> </div>
{% endfor %} {% endfor %}
{% elif key == "text" %} {% elif key == "content" %}
{% if value == "image" %} {% if "image" in record.meta_data.response.content_type %}
<img src="{{ record.meta_data.response.content }}" /> <img src="{{ record.meta_data.response.content }}" />
{% else %} {% else %}
<pre>{{ record.meta_data.response.text | e }}</pre> <pre>{{ record.meta_data.response.text | e }}</pre>
+1 -1
View File
@@ -135,7 +135,7 @@ class TestResponse(ApiServerUnittest):
] ]
extract_binds_dict = resp_obj.extract_response(extract_binds_list) extract_binds_dict = resp_obj.extract_response(extract_binds_list)
self.assertGreater(extract_binds_dict["resp_elapsed_microseconds"], 1000) self.assertGreater(extract_binds_dict["resp_elapsed_microseconds"], 1000)
self.assertEqual(extract_binds_dict["resp_elapsed_seconds"], 0) self.assertLess(extract_binds_dict["resp_elapsed_seconds"], 3)
self.assertEqual(extract_binds_dict["resp_elapsed_days"], 0) self.assertEqual(extract_binds_dict["resp_elapsed_days"], 0)
self.assertGreater(extract_binds_dict["resp_elapsed_total_seconds"], 0) self.assertGreater(extract_binds_dict["resp_elapsed_total_seconds"], 0)