Skip to content

Commit

Permalink
Merge pull request #137 from fescobar/beta
Browse files Browse the repository at this point in the history
Updating Allure version to 2.13.6
Updating flask-swagger-ui to 3.36.0
#134 - Order of test cases in the Emailable Report
#135 - Create project if it doesn't already exist
  • Loading branch information
fescobar authored Dec 2, 2020
2 parents 537cfc4 + 59a3fc8 commit 351f028
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ language: bash

env:
global:
- ALLURE_RELEASE=2.13.5
- ALLURE_RELEASE=2.13.6
- TARGET=frankescobar/allure-docker-service
- QEMU_VERSION=v4.0.0
matrix:
Expand Down
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Table of contents
* [Send results through API](#send-results-through-api)
* [Content-Type - application/json](#content-type---applicationjson)
* [Content-Type - multipart/form-data](#content-type---multipartform-data)
* [Force Project Creation Option](#force-project-creation-option)
* [Customize Executors Configuration](#customize-executors-configuration)
* [API Response Less Verbose](#api-response-less-verbose)
* [Switching version](#switching-version)
Expand Down Expand Up @@ -92,9 +93,9 @@ The following table shows the provided Manifest Lists.

| **Tag** | **allure-docker-service Base Image** |
|----------------------------------------|---------------------------------------------------|
| latest, 2.13.5 | frankescobar/allure-docker-service:2.13.5-amd64 |
| | frankescobar/allure-docker-service:2.13.5-arm32v7 |
| | frankescobar/allure-docker-service:2.13.5-arm64v8 |
| latest, 2.13.6 | frankescobar/allure-docker-service:2.13.6-amd64 |
| | frankescobar/allure-docker-service:2.13.6-arm32v7 |
| | frankescobar/allure-docker-service:2.13.6-arm64v8 |

## USAGE
### Generate Allure Results
Expand All @@ -112,6 +113,7 @@ We have some examples projects:
- [allure-docker-python-behave-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-python-behave-example)
- [allure-docker-python-pytest-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-python-pytest-example)
- [AllureDockerCSharpExample](https://github.com/fescobar/allure-docker-service-examples/tree/master/AllureDockerCSharpExample)
- [AllureDockerCSharpSpecFlow3Example](https://github.com/fescobar/allure-docker-service-examples/tree/master/AllureDockerCSharpSpecFlow3Example)

In this case we are going to generate results using the java project [allure-docker-java-testng-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-java-testng-example) of this repository.

Expand Down Expand Up @@ -255,6 +257,10 @@ NOTE FOR WINDOWS USERS:

With this option you could generate multiple reports for multiple projects, you can create, delete and get projects using [Project Endpoints](#project-endpoints). You can use Swagger documentation to help you.

IMPORTANT NOTE:
- For multiple projects configuration you must use `CHECK_RESULTS_EVERY_SECONDS` with value `NONE`. Otherwise, your performance machine would be affected, it could consume high memory, processors and storage. Use the endpoint `GET /generate-report` on demand after sending the results `POST /send-results`.
- If you use automatic reports a daemom is created and it will be listening any change in the `results` directory it will generate a new report each time find a new file. The same will happen for every project. For that reason, it's convenient disable the automatic reports using the value `NONE` in `CHECK_RESULTS_EVERY_SECONDS`.

##### Multiple Project - Docker on Unix/Mac
```sh
docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=NONE -e KEEP_HISTORY=1 \
Expand Down Expand Up @@ -633,6 +639,11 @@ NOTE:

- If you want to clean the results use the endpoint `GET /clean-results` ([Allure API](#allure-api)).

##### Force Project Creation Option
`Available from Allure Docker Service version 2.13.6`
If you use the query parameter `force_project_creation` with value `true`, the project where you want to send the results will be created automatically in case doesn't exist.
`POST /send-results?project_id=any-unexistent-project&force_project_creation=true`
#### Customize Executors Configuration
`Available from Allure Docker Service version 2.13.3`
Expand Down Expand Up @@ -693,7 +704,7 @@ You can switch the version container using `frankescobar/allure-docker-service:$
Docker Compose example:
```sh
allure:
image: "frankescobar/allure-docker-service:2.13.5"
image: "frankescobar/allure-docker-service:2.13.6"
```
or using latest version:
Expand Down Expand Up @@ -1242,7 +1253,7 @@ If you want to use docker without sudo, read following links:

### Build image
```sh
docker build -t allure-release -f docker-custom/Dockerfile.bionic-custom --build-arg ALLURE_RELEASE=2.13.5 .
docker build -t allure-release -f docker-custom/Dockerfile.bionic-custom --build-arg ALLURE_RELEASE=2.13.6 .
```
### Run container
```sh
Expand Down Expand Up @@ -1293,5 +1304,5 @@ docker run -d -p 5050:5050 frankescobar/allure-docker-service
```
### Download specific tagged image registered (Example)
```sh
docker run -d -p 5050:5050 frankescobar/allure-docker-service:2.13.5
docker run -d -p 5050:5050 frankescobar/allure-docker-service:2.13.6
```
92 changes: 49 additions & 43 deletions allure-docker-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def latest_report_endpoint():
@app.route("/send-results", methods=['POST'], strict_slashes=False)
@app.route("/allure-docker-service/send-results", methods=['POST'], strict_slashes=False)
@jwt_required
def send_results_endpoint():
def send_results_endpoint(): #pylint: disable=too-many-branches
try:
content_type = str(request.content_type)
if content_type is None:
Expand All @@ -694,14 +694,17 @@ def send_results_endpoint():

project_id = resolve_project(request.args.get('project_id'))
if is_existent_project(project_id) is False:
body = {
'meta_data': {
'message' : "project_id '{}' not found".format(project_id)
if request.args.get('force_project_creation') == 'true':
project_id = create_project({ "id": project_id })
else:
body = {
'meta_data': {
'message' : "project_id '{}' not found".format(project_id)
}
}
}
resp = jsonify(body)
resp.status_code = 404
return resp
resp = jsonify(body)
resp.status_code = 404
return resp

validated_results = []
processed_files = []
Expand Down Expand Up @@ -956,6 +959,7 @@ def emailable_report_render_endpoint():
tcs_latest_report_project = "{}/reports/latest/data/test-cases/*.json".format(project_path)

files = glob.glob(tcs_latest_report_project)
files.sort(key=os.path.getmtime, reverse=True)
test_cases = []
for file_name in files:
with open(file_name) as file:
Expand Down Expand Up @@ -1089,41 +1093,7 @@ def create_project_endpoint():
if not request.is_json:
raise Exception("Header 'Content-Type' is not 'application/json'")

json_body = request.get_json()

if 'id' not in json_body:
raise Exception("'id' is required in the body")

if isinstance(json_body['id'], str) is False:
raise Exception("'id' should be string")

if not json_body['id'].strip():
raise Exception("'id' should not be empty")

if len(json_body['id']) > 100:
raise Exception("'id' should not contains more than 100 characters.")

project_id_pattern = re.compile('^[a-z\\d]([a-z\\d -]*[a-z\\d])?$')
match = project_id_pattern.match(json_body['id'])
if match is None:
raise Exception("'id' should contains alphanumeric lowercase characters or hyphens. For example: 'my-project-id'") #pylint: disable=line-too-long

project_id = json_body['id']
if is_existent_project(project_id) is True:
raise Exception("project_id '{}' is existent".format(project_id))

if project_id == 'default':
raise Exception("The id 'default' is not allowed. Try with another project_id")

project_path = get_project_path(project_id)
latest_report_project = '{}/reports/latest'.format(project_path)
results_project = '{}/results'.format(project_path)

if not os.path.exists(latest_report_project):
os.makedirs(latest_report_project)

if not os.path.exists(results_project):
os.makedirs(results_project)
project_id = create_project(request.get_json())
except Exception as ex:
body = {
'meta_data': {
Expand Down Expand Up @@ -1404,6 +1374,42 @@ def send_json_results(results_project, validated_results, processed_files, faile
if file is not None:
file.close()

def create_project(json_body):
if 'id' not in json_body:
raise Exception("'id' is required in the body")

if isinstance(json_body['id'], str) is False:
raise Exception("'id' should be string")

if not json_body['id'].strip():
raise Exception("'id' should not be empty")

if len(json_body['id']) > 100:
raise Exception("'id' should not contains more than 100 characters.")

project_id_pattern = re.compile('^[a-z\\d]([a-z\\d -]*[a-z\\d])?$')
match = project_id_pattern.match(json_body['id'])
if match is None:
raise Exception("'id' should contains alphanumeric lowercase characters or hyphens. For example: 'my-project-id'") #pylint: disable=line-too-long

project_id = json_body['id']
if is_existent_project(project_id) is True:
raise Exception("project_id '{}' is existent".format(project_id))

if project_id == 'default':
raise Exception("The id 'default' is not allowed. Try with another project_id")

project_path = get_project_path(project_id)
latest_report_project = '{}/reports/latest'.format(project_path)
results_project = '{}/results'.format(project_path)

if not os.path.exists(latest_report_project):
os.makedirs(latest_report_project)

if not os.path.exists(results_project):
os.makedirs(results_project)

return project_id

def is_existent_project(project_id):
if not project_id.strip():
Expand Down
8 changes: 8 additions & 0 deletions allure-docker-api/static/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@
"schema":{
"type":"string"
}
},
{
"in":"query",
"name":"force_project_creation",
"schema":{
"type":"string"
},
"value": "false"
}
],
"requestBody":{
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
context: ../allure-docker-service
dockerfile: docker-custom/Dockerfile.bionic-custom
args:
ALLURE_RELEASE: "2.13.5"
ALLURE_RELEASE: "2.13.6"
environment:
DEV_MODE: 0
CHECK_RESULTS_EVERY_SECONDS: NONE
Expand Down
8 changes: 4 additions & 4 deletions docker-custom/Dockerfile.bionic-custom
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG ARCH=amd64
ARG JDK=adoptopenjdk:11-jre-openj9-bionic
ARG BUILD_DATE
ARG BUILD_VERSION=2.13.5-custom
ARG BUILD_VERSION=2.13.6-custom
ARG BUILD_REF=na
ARG ALLURE_RELEASE=2.13.5
ARG ALLURE_RELEASE=2.13.6
ARG ALLURE_REPO=https://dl.bintray.com/qameta/maven/io/qameta/allure/allure-commandline
ARG UID=1000
ARG GID=1000
Expand All @@ -16,7 +16,7 @@ RUN apk add build-base
RUN pip install -U pylint && \
pip install -U flask-cors
RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0

ENV ROOT_DIR=/code
RUN mkdir -p $ROOT_DIR
Expand Down Expand Up @@ -59,7 +59,7 @@ RUN apt-get update && \
ln -s `which python3` /usr/bin/python && \
pip3 install --upgrade pip && \
pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 && \
pip install -U flask-cors && \
curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \
unzip -q /tmp/allure-commandline.zip -d / && \
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apk add build-base
RUN pip install -U pylint && \
pip install -U flask-cors
RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0

ENV ROOT_DIR=/code
RUN mkdir -p $ROOT_DIR
Expand Down Expand Up @@ -67,7 +67,7 @@ RUN apt-get update && \
ln -s `which python3` /usr/bin/python && \
pip3 install --upgrade pip && \
pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 && \
pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 && \
pip install -U flask-cors && \
curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \
unzip -q /tmp/allure-commandline.zip -d / && \
Expand Down

0 comments on commit 351f028

Please sign in to comment.