Skip to content

Commit e02aaa9

Browse files
author
Sakari Rautiainen
authored
Merge pull request #106 from bitbar/devel
v2.61.0
2 parents 470731e + 9faadad commit e02aaa9

File tree

4 files changed

+98
-14
lines changed

4 files changed

+98
-14
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.61.0
2+
* Fix error with double slash for some API calls
3+
* Added new test methods
14
2.60.0
25
* Added Build API functions
36
2.43.0

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.60.0'
6+
version = '2.61.0'
77

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

testdroid/__init__.py

Lines changed: 47 additions & 8 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.60.0'
14+
__version__ = '2.61.0'
1515

1616
FORMAT = "%(message)s"
1717
logging.basicConfig(format=FORMAT)
@@ -417,7 +417,7 @@ def upload_test_file(self, project_id, filename):
417417
"""
418418
def delete_project_parameters(self, project_id, parameter_id):
419419
me = self.get_me()
420-
path = "/users/%s/projects/%s/config/parameters/%s" % ( me['id'], project_id, parameter_id )
420+
path = "users/%s/projects/%s/config/parameters/%s" % ( me['id'], project_id, parameter_id )
421421
return self.delete(path=path)
422422

423423
""" Get project parameters
@@ -438,7 +438,7 @@ def upload_data_file(self, project_id, filename):
438438
def set_project_parameters(self, project_id, parameters):
439439
#set key value pair for project. e.g. : {'key' : 'my_key', 'value':'my_value'}
440440
me = self.get_me()
441-
path = "/users/%s/projects/%s/config/parameters" % ( me['id'], project_id )
441+
path = "users/%s/projects/%s/config/parameters" % ( me['id'], project_id )
442442
return self.post(path=path, payload=parameters)
443443

444444
""" Get project config
@@ -455,7 +455,7 @@ def set_project_config(self, project_id, payload):
455455
if isinstance(payload, str):
456456
payload=json.loads(payload)
457457
me = self.get_me()
458-
path = "/users/%s/projects/%s/config" % ( me['id'], project_id )
458+
path = "users/%s/projects/%s/config" % ( me['id'], project_id )
459459
return self.post(path=path, payload=payload)
460460

461461
"""Set project framework based on a framework integer id
@@ -514,7 +514,7 @@ def start_test_run(self, project_id, device_group_id=None, device_model_ids=None
514514

515515
# actually start the test run
516516
me = self.get_me()
517-
path = "/users/%s/projects/%s/runs" % (me['id'], project_id)
517+
path = "users/%s/projects/%s/runs" % (me['id'], project_id)
518518
test_run = self.post(path=path, payload=payload)
519519
print("Test run id: %s" % test_run['id'])
520520
print("Name: %s" % test_run['displayName'])
@@ -676,8 +676,6 @@ def get_jobs(self, limit=0):
676676
"""
677677
def create_job(self, job_name, content, job_type="BUILD"):
678678
job = self.post(path="me/jobs", payload={"name": job_name, "content": content, "type": job_type})
679-
print(job)
680-
681679
logger.info("Job %s: %s (%s) created" % (job['id'], job['name'], job['type'] ))
682680
return job
683681

@@ -747,6 +745,34 @@ def download_build_output_files(self, job_id, build_id, results_folder="results"
747745
logger.info("No files to download")
748746
logger.info("")
749747

748+
""" Awaits completion of the given test run
749+
"""
750+
def wait_build(self, job_id, build_id):
751+
if job_id and build_id:
752+
print("Awaiting completion of build with id {}. Will wait forever polling every {}.".format(
753+
build_id,
754+
'{} minutes'.format(self.polling_interval_mins) if self.polling_interval_mins != 1 else 'minute'))
755+
756+
while True:
757+
time.sleep(self.polling_interval_mins * 6)
758+
if not self.api_key:
759+
self.access_token = None
760+
self.get_token()
761+
buildStatus = self.get_build(job_id, build_id)
762+
if buildStatus and 'state' in buildStatus:
763+
if buildStatus['state'] == "FINISHED":
764+
print("The build with id: %s has FINISHED with status: %s" % (build_id, buildStatus['status']))
765+
break
766+
elif buildStatus['state'] == "CREATED":
767+
print("[%s] The build with id: %s is awaiting to be scheduled" % (time.strftime("%H:%M:%S"), build_id))
768+
continue
769+
elif buildStatus['state'] == "BUILDING":
770+
print("[%s] The build with id: %s is running" % (time.strftime("%H:%M:%S"), build_id))
771+
continue
772+
773+
print("Couldn't establish the state of the build with id: %s. Aborting" % build_id)
774+
print(buildStatus)
775+
sys.exit(1)
750776

751777
""" Downloads test run files to a directory hierarchy
752778
"""
@@ -879,6 +905,18 @@ def format_epilog(self, formatter):
879905
Download test run screenshots. Screenshots will be downloaded to
880906
current directory in a structure:
881907
[test-run-id]/[device-run-id]-[device-name]/screenshots/...
908+
jobs Get list of your jobs
909+
builds <job-id> Get list of your builds
910+
create-job <job-name> <job-configuration> Create a new job. Job configuration in Jenkins pipeline format
911+
See the sample of Jenkisfile in http://docs.bitbar.com/build-service/guide.html
912+
update-job <job-id> <job-name> <job-configuration>
913+
Update existing job
914+
create-build <job-id> <build-configuration> Create a new build job. See https://cloud.testdroid.com/cloud/swagger-ui.html
915+
for details of build configuration
916+
delete-job <job-id> Delete job and all the builds in it
917+
delete-build <job-id> <build-id> Delete build by id
918+
download-builds-files <job-id> <build-id> Download all the results of the specific build
919+
wait-build <job-id> <build-id> Await completion (polling) of the build
882920
883921
"""
884922
parser = MyParser(usage=usage, description=description, epilog=epilog, version="%s %s" % ("%prog", __version__))
@@ -929,7 +967,8 @@ def get_commands(self):
929967
"create-build": self.create_build,
930968
"delete-job": self.delete_job,
931969
"delete-build": self.delete_build,
932-
"download-builds-files": self.download_build_output_files
970+
"download-builds-files": self.download_build_output_files,
971+
"wait-build": self.wait_build
933972

934973
}
935974
return commands

testdroid/tests/test_all.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@
66
import testdroid
77
import responses
88

9-
URL_BASE = 'https://cloud.bitbar.com'
10-
URL_API = '{}/api/v2'.format(URL_BASE)
11-
URL_API_ME = '{}/me'.format(URL_API)
12-
URL_USERS = '{}/users'.format(URL_BASE)
139
JSON = {'k': 'v'}
1410
PROJECT_ID = 2
1511
TEST_RUN_ID = 3
1612
DEVICE_RUN_ID = 4
1713
DEVICE_SESSION_ID = 5
14+
DEVICE_GROUP_ID = 6
15+
USER_ID = 7
16+
PARAM_ID = 8
1817
TAGS = 'tags'
1918
LIMIT = 0
2019

20+
21+
URL_BASE = 'https://cloud.bitbar.com'
22+
URL_API = '{}/api/v2'.format(URL_BASE)
23+
URL_API_ME = '{}/me'.format(URL_API)
24+
URL_USERS = '{}/users/{}'.format(URL_API,USER_ID)
25+
2126
t = testdroid.Testdroid()
2227

2328

@@ -167,7 +172,7 @@ def test_get_device_run_files_without_tags(self):
167172

168173
@responses.activate
169174
def test_get_device_run_files_with_tags(self):
170-
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]?={}'.format(
175+
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]={}'.format(
171176
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)
172177
responses.add(responses.GET, url, json=JSON, status=200)
173178
response = t.get_device_run_files(PROJECT_ID, TEST_RUN_ID,
@@ -180,3 +185,40 @@ def test_get_input_files(self):
180185
URL_API_ME, LIMIT)
181186
responses.add(responses.GET, url, json=JSON, status=200)
182187
self.assertEqual(t.get_input_files(LIMIT), JSON)
188+
189+
@responses.activate
190+
def test_start_test_run(self):
191+
url = '{}/projects/2'.format(
192+
URL_API_ME)
193+
json = {
194+
'id': USER_ID,
195+
'name': 'Sample project',
196+
}
197+
responses.add(responses.GET, url, json=json, status=200)
198+
199+
responses.add(responses.GET, URL_API_ME, json=json, status=200)
200+
url = '{}/projects/{}/runs'.format(
201+
URL_USERS, PROJECT_ID)
202+
json = {
203+
'id': 12,
204+
'displayName': "My test run"
205+
}
206+
207+
208+
responses.add(responses.POST, url, json=json, status=201)
209+
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])
210+
211+
@responses.activate
212+
def test_delete_project_parameters(self):
213+
path = 'projects/{}/config/parameters/{}'.format(PROJECT_ID, PARAM_ID)
214+
url = '{}/{}'.format(URL_USERS, path)
215+
216+
json = {
217+
'id': USER_ID
218+
}
219+
responses.add(responses.GET, URL_API_ME, json=json, status=200)
220+
responses.add(responses.DELETE, url, json=JSON, status=204)
221+
response = t.delete_project_parameters(PROJECT_ID, PARAM_ID)
222+
self.assertEqual(response.status_code, 204)
223+
224+

0 commit comments

Comments
 (0)