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

This commit is contained in:
debugtalk
2018-07-26 19:14:32 +08:00
parent 64656c1ab4
commit 20015ca10a
3 changed files with 44 additions and 30 deletions

View File

@@ -102,7 +102,10 @@ def render_html_report(summary, html_report_name=None, html_report_template=None
template_content = fp_r.read()
report_path = os.path.join(report_dir_path, html_report_name)
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)
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
def stringify_data(meta_data, request_or_response):
"""
meta_data = {
"request": {},
"response": {}
}
"""
headers = meta_data[request_or_response]["headers"]
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():
@@ -125,11 +135,11 @@ def stringify_data(meta_data, request_or_response):
if not encoding or encoding == "None":
encoding = "utf-8"
content_type = meta_data["response"]["content_type"]
if "image" in content_type:
if request_or_response == "response" and key == "content" and "image" in response_content_type:
# display image
meta_data["response"]["content_type"] = "image"
value = "data:{};base64,{}".format(
content_type,
response_content_type,
b64encode(value).decode(encoding)
)
else:

View File

@@ -272,6 +272,9 @@
<div style="overflow: auto">
<table>
{% 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>
<th>{{key}}</th>
<td>
@@ -281,11 +284,11 @@
<strong>{{ header_key }}</strong>: {{ header_value }}
</div>
{% endfor %}
{% elif key == "content_type" %}
{% elif key == "text" %}
{% if value == "image" %}
<img src="{{ record.meta_data.response.body }}" />
<img src="{{ record.meta_data.response.content }}" />
{% else %}
<pre>{{ record.meta_data.response.body }}</pre>
<pre>{{ record.meta_data.response.text }}</pre>
{% endif %}
{% else %}
{{value}}

View File

@@ -327,30 +327,31 @@
{% endfor %}
{% for key, value in record.meta_data.response.items() %}
{% if key != 'status_code' %}
<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 == "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>
{% if key in ["content", "json", "elapsed_ms", "response_time_ms", "content_size", "content_type", "status_code"] %}
{% continue %}
{% 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 %}
<tr class='log' status='pass'>