Skip to content

Commit

Permalink
Merge pull request #62 from fescobar/beta
Browse files Browse the repository at this point in the history
 #60 - Add endpoint to export report data (zip)
  • Loading branch information
fescobar authored Feb 13, 2020
2 parents 005f7ef + cb8546e commit 7d5ba6d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Table of contents
* [Updating seconds to check Allure Results](#updating-seconds-to-check-allure-results)
* [Keep History and Trends](#keep-history-and-trends)
* [Override User Container](#override-user-container)
* [Export Native Full Report](#export-native-full-report)
* [Customize Emailable Report](#customize-emailable-report)
* [Override CSS](#override-css)
* [Override title](#override-title)
Expand Down Expand Up @@ -266,6 +267,8 @@ Available endpoints:

`'GET' /emailable-report/export`

`'GET' /report/export`

Access to http://localhost:5050 to see Swagger documentation with examples

[![](images/allure-api.png)](images/allure-api.png)
Expand Down Expand Up @@ -362,10 +365,20 @@ Docker Compose example:
```
Note: Don't use `root` user.


#### Export Native Full Report
`Available from Allure Docker Service version 2.13.1`

You can export the native full report using the endpoint `/report/export` [Allure API](#allure-api).

[![](images/native-full-report.png)](images/native-full-report.png)



#### Customize Emailable Report
`Available from Allure Docker Service version 2.12.1`

You can render and export the emailable report using the [Allure API](#allure-api).
You can render and export the emailable report using the endpoints `/emailable-report/render` and `​/emailable-report​/export` [Allure API](#allure-api).

[![](images/emailable-report.png)](images/emailable-report.png)

Expand Down
41 changes: 39 additions & 2 deletions allure-docker-api/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Flask, jsonify, render_template, send_file, request
from flask_swagger_ui import get_swaggerui_blueprint
from subprocess import call
import os, uuid, glob, json, base64
import os, uuid, glob, json, base64, zipfile, io
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

Expand All @@ -11,8 +11,9 @@
CLEAN_RESULTS_PROCESS = os.environ['ROOT'] + '/cleanAllureResults.sh'
RENDER_EMAIL_REPORT_PROCESS = os.environ['ROOT'] + '/renderEmailableReport.sh'
RESULTS_DIRECTORY = os.environ['RESULTS_DIRECTORY']
REPORT_DIRECTORY = os.environ['REPORT_DIRECTORY']
ALLURE_VERSION = os.environ['ALLURE_VERSION']
TEST_CASES_DIRECTORY = os.environ['REPORT_DIRECTORY'] + '/data/test-cases/*.json'
TEST_CASES_DIRECTORY = REPORT_DIRECTORY + '/data/test-cases/*.json'
EMAILABLE_REPORT_HTML = os.environ['EMAILABLE_REPORT_HTML']
DEFAULT_TEMPLATE = 'default.html'
CSS = "https://stackpath.bootstrapcdn.com/bootswatch/4.3.1/cosmo/bootstrap.css"
Expand Down Expand Up @@ -333,6 +334,42 @@ def emailable_report_export():
else:
return report

@app.route("/report/export")
def report_export():
try:
check_process(GENERATE_REPORT_PROCESS)

data = io.BytesIO()
with zipfile.ZipFile(data, 'w', zipfile.ZIP_DEFLATED) as zipf:
rootDir = os.path.basename(REPORT_DIRECTORY)
for dirpath, dirnames, files in os.walk(REPORT_DIRECTORY):
for file in files:
filePath = os.path.join(dirpath, file)
parentPath = os.path.relpath(filePath, REPORT_DIRECTORY)
arcname = os.path.join(rootDir, parentPath)
zipf.write(filePath, arcname)
data.seek(0)

report = send_file(
data,
mimetype='application/zip',
as_attachment=True,
attachment_filename='allure-docker-service-report.zip'
)
except Exception as ex:
message = str(ex)

body = {
'meta_data': {
'message' : message
}
}
resp = jsonify(body)
resp.status_code = 400
return resp
else:
return report

def check_process(process_file):
tmp = os.popen('ps -Af').read()
proccount = tmp.count(process_file)
Expand Down
22 changes: 22 additions & 0 deletions allure-docker-api/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@
}
}
}
},
"/report/export": {
"get": {
"tags": [
"Actions"
],
"summary": "Export Allure report (from version 2.13.1)",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/components/schemas/response"
}
},
"400": {
"description": "BAD_REQUEST",
"schema": {
"$ref": "#/components/schemas/response"
}
}
}
}
}
},
"components": {
Expand Down
Binary file added images/native-full-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d5ba6d

Please sign in to comment.