forked from fescobar/allure-docker-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend_results.py
51 lines (42 loc) · 1.64 KB
/
send_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os, requests, json, base64
# This directory is where you have all your results locally, generally named as `allure-results`
allureResultsDirectory = '/allure-results-example'
# This url is where the Allure container is deployed. We are using localhost as example
allureServer = 'http://localhost:5050'
currentDirectory = os.path.dirname(os.path.realpath(__file__))
resultsDirectory = currentDirectory + allureResultsDirectory
print('RESULTS DIRECTORY PATH: ' + resultsDirectory)
files = os.listdir(resultsDirectory)
print('FILES:')
results = []
for file in files:
result = {}
filePath = resultsDirectory + "/" + file
print(filePath)
if os.path.isfile(filePath):
try:
with open(filePath, "rb") as f:
content = f.read()
if content.strip():
b64Content = base64.b64encode(content)
result['file_name'] = file
result['content_base64'] = b64Content.decode('UTF-8')
results.append(result)
else:
print('Empty File skipped: '+ filePath)
finally :
f.close()
else:
print('Directory skipped: '+ filePath)
headers = {'Content-type': 'application/json'}
requestBody = {
"results": results
}
jsonRequestBody = json.dumps(requestBody)
response = requests.post(allureServer + '/send-results', headers=headers, data=jsonRequestBody)
print("RESPONSE:")
jsonResponseBody = json.loads(response.content)
jsonPrettierResponseBody = json.dumps(jsonResponseBody, indent=4, sort_keys=True)
print(jsonPrettierResponseBody)
print("STATUS CODE:")
print(response.status_code)