-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 Added python script for generating HTML report
- Loading branch information
1 parent
4338cd5
commit d7f94e7
Showing
3 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from jinja2 import Template | ||
import json | ||
import os | ||
import sys | ||
|
||
if len(sys.argv) > 2: | ||
dredd_response = json.load(open(sys.argv[1])) | ||
|
||
script_directory = os.path.dirname(os.path.realpath(__file__)) | ||
template_file_path = script_directory + "/report_template.html.jinja" | ||
with open(template_file_path) as template_file: | ||
template = Template(template_file.read()) | ||
|
||
with open(sys.argv[2], 'w') as result: | ||
result.write(template.render( | ||
validationResults = dredd_response["validationResults"] | ||
)) | ||
|
||
else: | ||
print('''Script requires two arguments - first is path to validation result json file, second is path to output html file - | ||
e.g. py generate_report.py validationResults.json generatedReport.html''') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Pact validation report</title> | ||
|
||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
|
||
<div class="container"> | ||
<h1>Pact validation result</h1> | ||
|
||
{% if (validationResults is defined) and validationResults %} | ||
<ul class="list-group list-group-flush"> | ||
{% for validation in validationResults %} | ||
<li class="list-group-item"> | ||
{% if validation.validationStatus == "FAILED_NO_SUCH_PROVIDER_ON_ENVIRONMENT" %} | ||
<h3> | ||
Interaction between consumer {{ validation.consumerName }} | ||
and provider {{ validation.providerName }} was <b>not</b> performed due | ||
to lack of provider on environment | ||
</h3> | ||
{% else %} | ||
<h3> | ||
Interaction between consumer {{ validation.consumerName }} | ||
and provider {{ validation.providerName }} | ||
</h3> | ||
<br/> | ||
Consumer version = {{ validation.consumerVersion }}<br/> | ||
Provider version = {{ validation.providerVersion }} | ||
<br/> | ||
<br/> | ||
<table class="table table-sm"> | ||
<caption>interactions</caption> | ||
<thead class="thead-dark"> | ||
<tr> | ||
<th scope="col">Interaction name</th> | ||
<th scope="col">Result</th> | ||
<th scope="col">Errors</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for interaction in validation.interactions %} | ||
{% if interaction.validationResult == "FAIL" %} | ||
{% set rowClass = "table-danger" %} | ||
{% else %} | ||
{% set rowClass = "table-success" %} | ||
{% endif %} | ||
<tr class={{ rowClass }}> | ||
<td>{{ interaction.interactionName }}</td> | ||
<td>{{ interaction.validationResult }}</td> | ||
<td> | ||
{% if (interaction.errors is defined) and interaction.errors %} | ||
{% for error in interaction.errors %} | ||
{{ error }} <br/> | ||
{% endfor %} | ||
{% else %} | ||
- | ||
{% endif %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
<tbody> | ||
</table> | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
There were no interactions | ||
{% endif %} | ||
</div> | ||
|
||
</body> | ||
</html> |