Skip to content

Commit 1eafa93

Browse files
author
Sakari Rautiainen
committed
Build API functions II
2 parents 23be33e + 4329507 commit 1eafa93

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var/
2121
*.egg-info/
2222
.installed.cfg
2323
*.egg
24+
.idea
2425

2526
# PyInstaller
2627
# Usually these files are written by a python script from a template

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.43.0
2+
* Add function for restarting test runs and device runs
3+
* Travis builds
4+
* Fix TypeError on Windows OS
15
2.42.1
26
* Use imghdr to verify downloaded images instead of pillow
37
* Make the polling interval of test runs customizable

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys, os
44

55

6-
version = '2.42.1'
6+
version = '2.43.1'
77

88
setup(name='testdroid',
99
version=version,

testdroid/__init__.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from optparse import OptionParser
1212
from datetime import datetime
1313

14-
__version__ = '2.42.1'
14+
__version__ = '2.43.1'
1515

1616
FORMAT = "%(message)s"
1717
logging.basicConfig(format=FORMAT)
@@ -80,7 +80,7 @@ def update(self, pos, total):
8080
else:
8181
self.prog_bar += ' '
8282
if sys.platform.lower().startswith('win'):
83-
print(self +'\r')
83+
print(str(self) + '\r')
8484
else:
8585
print(str(self) + chr(27) + '[A')
8686

@@ -240,7 +240,6 @@ def upload(self, path=None, filename=None):
240240
res = requests.post(url, files=files, headers=self._build_headers())
241241
if res.status_code not in list(range(200, 300)):
242242
raise RequestResponseError(res.text, res.status_code)
243-
print(res)
244243
return res
245244

246245
""" GET from API resource
@@ -399,6 +398,14 @@ def upload_application_file(self, project_id, filename):
399398
path = "users/%s/projects/%s/files/application" % (me['id'], project_id)
400399
self.upload(path=path, filename=filename)
401400

401+
""" Upload application file to project
402+
"""
403+
def upload_file(self, filename):
404+
me = self.get_me()
405+
path = "users/%s/files" % (me['id'])
406+
res = self.upload(path=path, filename=filename).json()
407+
print("ID:%s Name:%s Size:%s" % (str(res['id']).ljust(10), res['name'].ljust(15), res['size']))
408+
402409
""" Upload test file to project
403410
"""
404411
def upload_test_file(self, project_id, filename):
@@ -591,6 +598,14 @@ def print_project_test_runs(self, project_id, limit=0):
591598
def get_test_run(self, project_id, test_run_id):
592599
return self.get("me/projects/%s/runs/%s" % (project_id, test_run_id))
593600

601+
""" Re-run an already-existing test run. Specify individual device run IDs to only re-run those devices.
602+
"""
603+
def retry_test_run(self, project_id, test_run_id, device_run_ids=[]):
604+
endpoint = "me/projects/%s/runs/%s/retry" % (project_id, test_run_id)
605+
if device_run_ids:
606+
endpoint += "?deviceRunIds[]=" + "&deviceRunIds[]=".join(str(device_id) for device_id in device_run_ids)
607+
return self.post(endpoint)
608+
594609
"""Abort a test run
595610
"""
596611
def abort_test_run(self, project_id, test_run_id):
@@ -667,27 +682,45 @@ def create_job(self, job_name, content, job_type="BUILD"):
667682
return job
668683

669684
""" Create a build
670-
"""
671-
def create_build(self, job_id, file_id=None):
672-
build = self.post(path="me/jobs/{}/builds".format(job_id), payload={"fileId": file_id})
673-
print(build)
674-
685+
build_config:
686+
fileId: int
687+
executorId: int
688+
configuration: String
689+
resultsConfig: [resultsConfig]
690+
691+
resultsConfig:
692+
sourceName
693+
destinationName
694+
isDirectory
695+
fileUrlEnvVariable
696+
697+
usage: client.create_build(job_id, json.dumps({"fileId":123213...))
698+
"""
699+
def create_build(self, job_id, build_config={}):
700+
build = self.post(path="me/jobs/{}/builds".format(job_id), payload=build_config, headers={'Content-type': 'application/json', 'Accept': 'application/json'})
675701
logger.info("build %s: %s (%s) " % (build['id'], build['buildNumber'], build['state'] ))
676702
return build
677703

704+
""" Update job
705+
"""
706+
def upload_job(self, job_id,job_name, content):
707+
job = self.post(path="me/jobs/{}".format(job_id), payload={"name": job_name, "content": content})
708+
709+
logger.info("Job %s: %s (%s) created" % (job['id'], job['name'], job['type'] ))
710+
return job
711+
678712
""" Update job
679713
"""
680714
def update_job(self, job_id,job_name, content):
681715
job = self.post(path="me/jobs/{}".format(job_id), payload={"name": job_name, "content": content})
682-
print(job)
683716

684717
logger.info("Job %s: %s (%s) created" % (job['id'], job['name'], job['type'] ))
685718
return job
686719

687720
""" Delete job
688721
"""
689722
def delete_job(self, job_id):
690-
return self.delete("me/jobs/{}".format(limit))
723+
return self.delete("me/jobs/{}".format(job_id))
691724

692725
""" Delete build
693726
"""
@@ -824,6 +857,7 @@ def format_epilog(self, formatter):
824857
upload-application <project-id> <filename> Upload application to project
825858
upload-test <project-id> <filename> Upload test file to project
826859
upload-data <project-id> <filename> Upload additional data file to project
860+
upload-file <filename> Upload to "Files"
827861
set-project-config <project-id> <config-json>
828862
Change the project config parameters as facilitated by the API:
829863
http://docs.testdroid.com/_pages/client.html#project-config
@@ -876,6 +910,7 @@ def get_commands(self):
876910
"upload-application": self.upload_application_file,
877911
"upload-test": self.upload_test_file,
878912
"upload-data": self.upload_data_file,
913+
"upload-file": self.upload_file,
879914
"set-project-config": self.set_project_config,
880915
"start-test-run": self.start_test_run,
881916
"start-test-run-using-config": self.start_test_run_using_config,

testdroid/tests/test_all.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
from unittest import TestCase
4-
import io
5-
import sys
64
import os
75

86
import testdroid

0 commit comments

Comments
 (0)