Skip to content

Commit d20e00b

Browse files
author
Sakari Rautiainen
committed
2 parents 4ec2be7 + b425355 commit d20e00b

File tree

8 files changed

+213
-5
lines changed

8 files changed

+213
-5
lines changed

.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

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2.42.1
2+
* Use imghdr to verify downloaded images instead of pillow
3+
* Make the polling interval of test runs customizable
14
2.42.0
25
* Support for Python 3.x
36
* New method to launch test run using test run config (Requires: Testdroid v2.58 or higher)

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""

testdroid/tests/__init__.py

Whitespace-only changes.

testdroid/tests/test_all.py

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