fix #315: display image in report; remove duplicate info

This commit is contained in:
debugtalk
2018-07-26 19:48:55 +08:00
parent 64656c1ab4
commit 20015ca10a
3 changed files with 44 additions and 30 deletions
+14 -4
View File
@@ -102,7 +102,10 @@ def render_html_report(summary, html_report_name=None, html_report_template=None
template_content = fp_r.read() template_content = fp_r.read()
report_path = os.path.join(report_dir_path, html_report_name) report_path = os.path.join(report_dir_path, html_report_name)
with io.open(report_path, 'w', encoding='utf-8') as fp_w: with io.open(report_path, 'w', encoding='utf-8') as fp_w:
rendered_content = Template(template_content).render(summary) rendered_content = Template(
template_content,
extensions=["jinja2.ext.loopcontrols"]
).render(summary)
fp_w.write(rendered_content) fp_w.write(rendered_content)
logger.log_info("Generated Html report: {}".format(report_path)) logger.log_info("Generated Html report: {}".format(report_path))
@@ -110,9 +113,16 @@ def render_html_report(summary, html_report_name=None, html_report_template=None
return report_path return report_path
def stringify_data(meta_data, request_or_response): def stringify_data(meta_data, request_or_response):
"""
meta_data = {
"request": {},
"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():
@@ -125,11 +135,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"
content_type = meta_data["response"]["content_type"] if request_or_response == "response" and key == "content" and "image" in response_content_type:
if "image" in content_type: # display image
meta_data["response"]["content_type"] = "image" meta_data["response"]["content_type"] = "image"
value = "data:{};base64,{}".format( value = "data:{};base64,{}".format(
content_type, response_content_type,
b64encode(value).decode(encoding) b64encode(value).decode(encoding)
) )
else: else:
@@ -272,6 +272,9 @@
<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"] %}
{% continue %}
{% endif %}
<tr> <tr>
<th>{{key}}</th> <th>{{key}}</th>
<td> <td>
@@ -281,11 +284,11 @@
<strong>{{ header_key }}</strong>: {{ header_value }} <strong>{{ header_key }}</strong>: {{ header_value }}
</div> </div>
{% endfor %} {% endfor %}
{% elif key == "content_type" %} {% elif key == "text" %}
{% if value == "image" %} {% if value == "image" %}
<img src="{{ record.meta_data.response.body }}" /> <img src="{{ record.meta_data.response.content }}" />
{% else %} {% else %}
<pre>{{ record.meta_data.response.body }}</pre> <pre>{{ record.meta_data.response.text }}</pre>
{% endif %} {% endif %}
{% else %} {% else %}
{{value}} {{value}}
@@ -327,30 +327,31 @@
{% endfor %} {% endfor %}
{% for key, value in record.meta_data.response.items() %} {% for key, value in record.meta_data.response.items() %}
{% if key != 'status_code' %} {% if key in ["content", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type", "status_code"] %}
<tr class='log' status='debug'> {% continue %}
<td class='status debug' title='debug' alt='debug'><i
class='material-icons'>low_priority</i></td>
<td class='timestamp'>{{ key }}</td>
<td class='step-details'>
{% if key == "headers" %}
{% for header_key, header_value in record.meta_data.request.headers.items() %}
<div>
<strong>{{ header_key }}</strong>: {{ header_value }}
</div>
{% endfor %}
{% elif key == "content_type" %}
{% if value == "image" %}
<img src="{{ record.meta_data.response.body }}"/>
{% else %}
<pre>{{ record.meta_data.response.body }}</pre>
{% endif %}
{% else %}
{{ value }}
{% endif %}
</td>
</tr>
{% endif %} {% endif %}
<tr class='log' status='debug'>
<td class='status debug' title='debug' alt='debug'><i
class='material-icons'>low_priority</i></td>
<td class='timestamp'>{{ key }}</td>
<td class='step-details'>
{% if key == "headers" %}
{% for header_key, header_value in record.meta_data.request.headers.items() %}
<div>
<strong>{{ header_key }}</strong>: {{ header_value }}
</div>
{% endfor %}
{% elif key == "text" %}
{% if value == "image" %}
<img src="{{ record.meta_data.response.content }}" />
{% else %}
<pre>{{ record.meta_data.response.text }}</pre>
{% endif %}
{% else %}
{{value}}
{% endif %}
</td>
</tr>
{% endfor %} {% endfor %}
<tr class='log' status='pass'> <tr class='log' status='pass'>