mirror of
https://github.com/KevinMidboe/knowit_julekalender-2017.git
synced 2025-10-29 17:50:18 +00:00
Changed travis config to run our custome script to upload a image to dropbox based on how many tests passed.
This commit is contained in:
@@ -4,6 +4,7 @@ python:
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
script:
|
||||
- coverage run -m pytest
|
||||
- pytest --junitxml=result.xml
|
||||
- badge.py
|
||||
after_success:
|
||||
- coveralls
|
||||
|
||||
63
badge.py
Executable file
63
badge.py
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3.6
|
||||
import os, dropbox, requests
|
||||
import xml.etree.ElementTree as ET
|
||||
from dropbox.files import WriteMode
|
||||
|
||||
from colour import Color
|
||||
|
||||
def get_xml_test_results():
|
||||
tree = ET.parse('result.xml')
|
||||
root = tree.getroot()
|
||||
failures = int(root.attrib['failures'])
|
||||
total = int(root.attrib['tests'])
|
||||
return [failures, total]
|
||||
|
||||
def getPicture():
|
||||
with open("progress.svg", "rb") as imageFile:
|
||||
return imageFile.read()
|
||||
|
||||
def download_image(image_url):
|
||||
session = requests.Session()
|
||||
session.headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36"}
|
||||
|
||||
r = session.get(image_url, stream=True, verify=False)
|
||||
with open('progress.svg', 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
f.write(chunk)
|
||||
|
||||
def getColor(value):
|
||||
start = Color('red')
|
||||
end = Color('yellowgreen')
|
||||
colors = list(start.range_to(Color(end), 10))
|
||||
hexList = []
|
||||
for color in colors:
|
||||
if not str(color)[:1] is '#':
|
||||
hexList.append(color.hex[1:])
|
||||
else:
|
||||
hexList.append(str(color)[1:])
|
||||
|
||||
if (len(hexList[-1]) <= 4):
|
||||
hexList[-1] = hexList[-1] + '000'
|
||||
|
||||
return hexList[int(float(value)/10)]
|
||||
|
||||
def uploadToDropbox(progress):
|
||||
dbx = dropbox.Dropbox(os.environ.get('DROPBOX_ACCESS_TOKEN'))
|
||||
print(dbx.users_get_current_account())
|
||||
|
||||
response = dbx.files_upload(getPicture(), '/knowit/progress.svg', mode=WriteMode('overwrite', None))
|
||||
print('response:', response)
|
||||
|
||||
def main():
|
||||
failures, total = get_xml_test_results()
|
||||
progress = "{0:.1f}".format((total-failures)/total * 100)
|
||||
color = getColor(progress)
|
||||
|
||||
path = 'https://img.shields.io/badge/Progress-{}-{}.svg'.format(progress, color)
|
||||
download_image(path)
|
||||
|
||||
print(progress)
|
||||
uploadToDropbox(progress)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,3 +1,4 @@
|
||||
pytest>=3.3.1
|
||||
coveralls>=1.2.0
|
||||
coverage>=4.4.2
|
||||
dropbox>=8.5.0
|
||||
|
||||
Reference in New Issue
Block a user