Skip to content

Commit 436671b

Browse files
author
Sakari Rautiainen
authored
Merge pull request #97 from bitbar/devel
v2.43.0
2 parents b3df0f2 + 3c3bf05 commit 436671b

File tree

8 files changed

+224
-9
lines changed

8 files changed

+224
-9
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

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
- "3.4"
5+
- "3.5"
6+
- "3.6"
7+
- "pypy3.5"
8+
install:
9+
- python setup.py clean
10+
- python setup.py sdist
11+
script:
12+
- python setup.py test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Build Status](https://travis-ci.org/bitbar/testdroid-api-client-python.svg?branch=devel)](https://travis-ci.org/bitbar/testdroid-api-client-python)
12

23
Python client for Testdroid Cloud APIv2
34
=======================================

setup.py

Lines changed: 5 additions & 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.0'
77

88
setup(name='testdroid',
99
version=version,
@@ -30,4 +30,8 @@
3030
'testdroid = testdroid:main',
3131
],
3232
},
33+
test_suite='testdroid.tests.test_all',
34+
tests_require=[
35+
'responses',
36+
],
3337
)

testdroid/__init__.py

Lines changed: 22 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.42.1'
14+
__version__ = '2.43.0'
1515

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

@@ -234,11 +234,14 @@ def download(self, path=None, filename=None, payload={}, callback=None):
234234
""" Upload file to API resource
235235
"""
236236
def upload(self, path=None, filename=None):
237-
url = "%s/api/v2/%s" % (self.cloud_url, path)
238-
files = {'file': open(filename, 'rb')}
239-
res = requests.post(url, files=files, headers=self._build_headers())
240-
if res.status_code not in list(range(200, 300)):
241-
raise RequestResponseError(res.text, res.status_code)
237+
# TOOD: where's the error handling?
238+
with open(filename, 'rb') as f:
239+
url = "%s/api/v2/%s" % (self.cloud_url, path)
240+
files = {'file': f}
241+
res = requests.post(url, files=files, headers=self._build_headers())
242+
if res.status_code not in list(range(200, 300)):
243+
raise RequestResponseError(res.text, res.status_code)
244+
return res
242245

243246
""" GET from API resource
244247
"""
@@ -588,6 +591,14 @@ def print_project_test_runs(self, project_id, limit=0):
588591
def get_test_run(self, project_id, test_run_id):
589592
return self.get("me/projects/%s/runs/%s" % (project_id, test_run_id))
590593

594+
""" Re-run an already-existing test run. Specify individual device run IDs to only re-run those devices.
595+
"""
596+
def retry_test_run(self, project_id, test_run_id, device_run_ids=[]):
597+
endpoint = "me/projects/%s/runs/%s/retry" % (project_id, test_run_id)
598+
if device_run_ids:
599+
endpoint += "?deviceRunIds[]=" + "&deviceRunIds[]=".join(str(device_id) for device_id in device_run_ids)
600+
return self.post(endpoint)
601+
591602
"""Abort a test run
592603
"""
593604
def abort_test_run(self, project_id, test_run_id):
@@ -801,7 +812,10 @@ def cli(self, parser, commands):
801812

802813
if options.debug:
803814
logger.setLevel(logging.DEBUG)
804-
http.client.HTTPConnection.debuglevel = 1
815+
if sys.version_info[0] > 2:
816+
http.client.HTTPConnection.debuglevel = 1
817+
else:
818+
httplib.HTTPConnection.debuglevel = 1
805819
logging.getLogger().setLevel(logging.DEBUG)
806820
requests_log = logging.getLogger("requests.packages.urllib3")
807821
requests_log.setLevel(logging.DEBUG)

testdroid/tests/__init__.py

Whitespace-only changes.

testdroid/tests/test_all.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from unittest import TestCase
4+
import os
5+
6+
import testdroid
7+
import responses
8+
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)
13+
JSON = {'k': 'v'}
14+
PROJECT_ID = 2
15+
TEST_RUN_ID = 3
16+
DEVICE_RUN_ID = 4
17+
DEVICE_SESSION_ID = 5
18+
TAGS = 'tags'
19+
LIMIT = 0
20+
21+
t = testdroid.Testdroid()
22+
23+
24+
# check that API calls go where they should go
25+
class TestNetworking(TestCase):
26+
def setUp(self):
27+
# set up the token so gets, posts etc work
28+
url = '{}/oauth/token'.format(URL_BASE)
29+
json = {
30+
'access_token': 'token',
31+
'refresh_token': 'refresh',
32+
'expires_in': 65535
33+
}
34+
responses.add(responses.POST, url, json=json, status=200)
35+
36+
@responses.activate
37+
def test_get(self):
38+
path = 'get'
39+
url = '{}/{}'.format(URL_API, path)
40+
responses.add(responses.GET, url, json=JSON, status=200)
41+
response = t.get('get')
42+
self.assertEqual(response, JSON)
43+
44+
@responses.activate
45+
def test_get_post(self):
46+
path = 'post'
47+
url = '{}/{}'.format(URL_API, path)
48+
responses.add(responses.POST, url, json=JSON, status=200)
49+
response = t.post(path)
50+
self.assertEqual(response, JSON)
51+
52+
@responses.activate
53+
def test_delete(self):
54+
path = 'delete'
55+
url = '{}/{}'.format(URL_API, path)
56+
responses.add(responses.DELETE, url, json=JSON, status=200)
57+
response = t.delete(path)
58+
self.assertEqual(response.status_code, 200)
59+
60+
@responses.activate
61+
def test_upload(self):
62+
path = 'upload'
63+
file_path = '{}/testdroid/tests/upload.txt'.format(os.getcwd())
64+
url = '{}/{}'.format(URL_API, path)
65+
responses.add(responses.POST, url, json=JSON, status=200)
66+
response = t.upload(path, file_path)
67+
self.assertEqual(response.status_code, 200)
68+
69+
@responses.activate
70+
def test_get_me(self):
71+
url = URL_API_ME
72+
responses.add(responses.GET, url, json=JSON, status=200)
73+
self.assertEqual(t.get_me(), JSON)
74+
75+
@responses.activate
76+
def test_get_device_groups(self):
77+
url = '{}/device-groups'.format(URL_API_ME)
78+
responses.add(responses.GET, url, json=JSON, status=200)
79+
response = t.get_device_groups()
80+
self.assertEqual(response, JSON)
81+
82+
@responses.activate
83+
def test_get_frameworks(self):
84+
url = '{}/available-frameworks'.format(URL_API_ME)
85+
responses.add(responses.GET, url, json=JSON, status=200)
86+
response = t.get_frameworks()
87+
self.assertEqual(response, JSON)
88+
89+
@responses.activate
90+
def test_get_devices(self):
91+
url = '{}/devices'.format(URL_API)
92+
responses.add(responses.GET, url, json=JSON, status=200)
93+
response = t.get_devices()
94+
self.assertEqual(response, JSON)
95+
96+
@responses.activate
97+
def test_get_projects(self):
98+
url = '{}/projects'.format(URL_API_ME)
99+
responses.add(responses.GET, url, json=JSON, status=200)
100+
response = t.get_projects()
101+
self.assertEqual(response, JSON)
102+
103+
@responses.activate
104+
def test_get_project(self):
105+
PROJECT_ID = 2
106+
url = '{}/projects/{}'.format(URL_API_ME, PROJECT_ID)
107+
responses.add(responses.GET, url, json=JSON, status=200)
108+
response = t.get_project(PROJECT_ID)
109+
self.assertEqual(response, JSON)
110+
111+
@responses.activate
112+
def test_get_project_parameters(self):
113+
PROJECT_ID = 2
114+
url = '{}/projects/{}/config/parameters'.format(URL_API_ME, PROJECT_ID)
115+
responses.add(responses.GET, url, json=JSON, status=200)
116+
response = t.get_project_parameters(PROJECT_ID)
117+
self.assertEqual(response, JSON)
118+
119+
@responses.activate
120+
def test_get_project_config(self):
121+
PROJECT_ID = 2
122+
url = '{}/projects/{}/config'.format(URL_API_ME, PROJECT_ID)
123+
responses.add(responses.GET, url, json=JSON, status=200)
124+
response = t.get_project_config(PROJECT_ID)
125+
self.assertEqual(response, JSON)
126+
127+
@responses.activate
128+
def test_get_project_test_runs(self):
129+
url = '{}/projects/{}/runs'.format(URL_API_ME, PROJECT_ID)
130+
responses.add(responses.GET, url, json=JSON, status=200)
131+
response = t.get_project_test_runs(PROJECT_ID)
132+
self.assertEqual(response, JSON)
133+
134+
@responses.activate
135+
def test_get_test_run(self):
136+
url = '{}/projects/{}/runs/{}'.format(URL_API_ME, PROJECT_ID,
137+
TEST_RUN_ID)
138+
responses.add(responses.GET, url, json=JSON, status=200)
139+
response = t.get_test_run(PROJECT_ID, TEST_RUN_ID)
140+
self.assertEqual(response, JSON)
141+
142+
@responses.activate
143+
def test_get_device_runs(self):
144+
url = '{}/projects/{}/runs/{}/device-runs'.format(
145+
URL_API_ME, PROJECT_ID, TEST_RUN_ID)
146+
responses.add(responses.GET, url, json=JSON, status=200)
147+
response = t.get_device_runs(PROJECT_ID, TEST_RUN_ID)
148+
self.assertEqual(response, JSON)
149+
150+
@responses.activate
151+
def test_get_device_run_screenshots_list(self):
152+
url = '{}/projects/{}/runs/{}/device-runs/{}/screenshots'.format(
153+
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_RUN_ID)
154+
responses.add(responses.GET, url, json=JSON, status=200)
155+
response = t.get_device_run_screenshots_list(PROJECT_ID, TEST_RUN_ID,
156+
DEVICE_RUN_ID)
157+
self.assertEqual(response, JSON)
158+
159+
@responses.activate
160+
def test_get_device_run_files_without_tags(self):
161+
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files'.format(
162+
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID)
163+
responses.add(responses.GET, url, json=JSON, status=200)
164+
response = t.get_device_run_files(PROJECT_ID, TEST_RUN_ID,
165+
DEVICE_SESSION_ID)
166+
self.assertEqual(response, JSON)
167+
168+
@responses.activate
169+
def test_get_device_run_files_with_tags(self):
170+
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]?={}'.format(
171+
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)
172+
responses.add(responses.GET, url, json=JSON, status=200)
173+
response = t.get_device_run_files(PROJECT_ID, TEST_RUN_ID,
174+
DEVICE_SESSION_ID, TAGS)
175+
self.assertEqual(response, JSON)
176+
177+
@responses.activate
178+
def test_get_input_files(self):
179+
url = '{}/files?limit={}&filter=s_direction_eq_INPUT'.format(
180+
URL_API_ME, LIMIT)
181+
responses.add(responses.GET, url, json=JSON, status=200)
182+
self.assertEqual(t.get_input_files(LIMIT), JSON)

testdroid/tests/upload.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
upload this

0 commit comments

Comments
 (0)