Skip to content

Commit

Permalink
#5 Added python script for generating HTML report
Browse files Browse the repository at this point in the history
  • Loading branch information
garlicsauce committed Jul 23, 2018
1 parent 4338cd5 commit d7f94e7
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ Of course you can use jar file generated during installation as well and deploy
* [Maven](https://maven.apache.org/) - Dependency Management
* [Docker](https://www.docker.com/) - Containerization engine

## Contributing
## Report generation

The result of running validations in Judge D is json containing data result. Reading json files is not very human
friendly so in assets/report-generator there is python script that generates nice HTML report. To use it you need installed
python and jinja2 libs. You can also use Dockerfile located in this directory.

### Contributing

Want to help? Have any problems or questions? Let us know!

* create an issue...
* ... or if it already exists comment on it
* for detailed informations about contributing read our [Contribution guide](../blob/master/CONTRIBUTING.md)
* for detailed informations about contributing read our [Contribution guide](../master/CONTRIBUTING.md)


## Versioning
Expand All @@ -93,7 +99,7 @@ TODO - Gitflow versioning in plans.
## Authors

* **Tomasz Krzyżak** - *Development* - [krzyzy](https://github.com/krzyzy)
* **Filip Łazarski** - *Development*
* **Filip Łazarski** - *Development* - [Felipe444](https://github.com/Felipe444)
* **Adrian Michalik** - *Development* - [garlicsauce](https://github.com/garlicsauce)

See also the list of [contributors](https://github.com/HLTech/judge-d/contributors) who participated in this project.
Expand Down
21 changes: 21 additions & 0 deletions assets/report-generator/generate_report.py
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''')
75 changes: 75 additions & 0 deletions assets/report-generator/report_template.html.jinja
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>

0 comments on commit d7f94e7

Please sign in to comment.