Skip to content

Commit 4b149ba

Browse files
authored
Merge pull request #142 from szprutamich/devel
Version 3.0
2 parents 4f341bc + 00b44d6 commit 4b149ba

File tree

6 files changed

+9
-121
lines changed

6 files changed

+9
-121
lines changed

.whitesource

Lines changed: 0 additions & 15 deletions
This file was deleted.

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
3.0
2+
* Drop support for oauth grant type password
13
2.69.3
24
* Fixed chunked downloads
35
2.69.2

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Usage
2626

2727
`testdroid --help`
2828

29-
Note that you can set `TESTDROID_USERNAME`, `TESTDROID_PASSWORD` and `TESTDROID_URL` environment variables.
29+
Note that you can set `TESTDROID_APIKEY` and `TESTDROID_URL` environment variables.
3030

3131

3232
Module
3333
-----
3434

3535
You can use this class as a command line utility or import it to your own code.
3636

37-
There are two methods of authentication, email and password or api key. The prefered approach is using api key as in examle below.
37+
The example below is using api key as the authentication method.
3838

3939
Example:
4040

@@ -45,13 +45,6 @@ Example:
4545
{u'displayName': u'Test Run 1', u'logZipState': u'BLANK', u'screenshotZipState': u'BLANK', u'projectId': 12340, u'number': 1, u'successRatio': 0.814815, u'createTime': 1393595647000, u'executionRatio': 1.0, u'state': u'FINISHED', u'startedByDisplayName': u'John Doe', u'id': 10}
4646
```
4747

48-
Versions
49-
--------
50-
51-
0.1.9 works with Testdroid Cloud 2.4.
52-
53-
From Python API client 2.5 the versions match with Testdroid API versions.
54-
5548
Developing and testing
5649
----------------------
5750

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from setuptools import setup, find_packages
33

4-
version = '2.100.0'
4+
version = '3.0'
55

66
setup(name='testdroid',
77
version=version,

testdroid/__init__.py

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from optparse import OptionParser
1818
from datetime import datetime
1919

20-
__version__ = '2.100.0'
20+
__version__ = '3.0'
2121

2222
FORMAT = "%(message)s"
2323
logging.basicConfig(format=FORMAT)
@@ -109,12 +109,6 @@ class Testdroid:
109109
url = None
110110
# Api Key for authentication
111111
api_key = None
112-
# Oauth access token
113-
access_token = None
114-
# Oauth refresh token
115-
refresh_token = None
116-
# Unix timestamp (seconds) when token expires
117-
token_expiration_time = None
118112
# Buffer size used for downloads
119113
download_buffer_size = 65536
120114
# polling interval when awaiting for test run completion
@@ -126,20 +120,12 @@ def __init__(self, **kwargs):
126120
""" Constructor, defaults against cloud.bitbar.com """
127121

128122
self.api_key = kwargs.get('apikey')
129-
self.username = kwargs.get('username')
130-
self.password = kwargs.get('password')
131123
self.cloud_url = kwargs.get('url') or "https://cloud.bitbar.com"
132124
self.download_buffer_size = kwargs.get('download_buffer_size') or 65536
133125

134126
def set_apikey(self, apikey):
135127
self.api_key = apikey
136128

137-
def set_username(self, username):
138-
self.username = username
139-
140-
def set_password(self, password):
141-
self.password = password
142-
143129
def set_url(self, url):
144130
self.cloud_url = url
145131

@@ -149,56 +135,6 @@ def set_download_buffer_size(self, download_buffer_size):
149135
def set_polling_interval_mins(self, polling_interval_mins):
150136
self.polling_interval_mins = polling_interval_mins
151137

152-
def get_token(self):
153-
""" Get Oauth2 token """
154-
155-
if not self.access_token:
156-
# TODO: refresh
157-
url = "%s/oauth/token" % self.cloud_url
158-
payload = {
159-
"client_id": "testdroid-cloud-api",
160-
"grant_type": "password",
161-
"username": self.username,
162-
"password": self.password
163-
}
164-
res = requests.post(
165-
url,
166-
data=payload,
167-
headers={"Accept": "application/json"}
168-
)
169-
if res.status_code not in list(range(200, 300)):
170-
raise RequestResponseError(res.text, res.status_code)
171-
172-
reply = res.json()
173-
174-
self.access_token = reply['access_token']
175-
self.refresh_token = reply['refresh_token']
176-
self.token_expiration_time = time.time() + reply['expires_in']
177-
elif self.token_expiration_time < time.time():
178-
url = "%s/oauth/token" % self.cloud_url
179-
payload = {
180-
"client_id": "testdroid-cloud-api",
181-
"grant_type": "refresh_token",
182-
"refresh_token": self.refresh_token
183-
}
184-
res = requests.post(
185-
url,
186-
data=payload,
187-
headers={"Accept": "application/json"}
188-
)
189-
if res.status_code not in list(range(200, 300)):
190-
print("FAILED: Unable to get a new access token using refresh token")
191-
self.access_token = None
192-
return self.get_token()
193-
194-
reply = res.json()
195-
196-
self.access_token = reply['access_token']
197-
self.refresh_token = reply['refresh_token']
198-
self.token_expiration_time = time.time() + reply['expires_in']
199-
200-
return self.access_token
201-
202138
def __build_headers(self):
203139
""" Helper method for getting necessary headers to use for API calls, including authentication """
204140

@@ -208,7 +144,7 @@ def __build_headers(self):
208144
'Accept': 'application/json'}
209145
return apikey
210146
else:
211-
return {'Authorization': 'Bearer %s' % self.get_token(), 'Accept': 'application/json'}
147+
return {'Accept': 'application/json'}
212148

213149
def download(self, path=None, filename=None, payload=None, callback=None):
214150
""" Download file from API resource """
@@ -280,7 +216,7 @@ def get(self, path, payload=None, headers=None):
280216
if res.status_code not in list(range(200, 300)):
281217
raise RequestResponseError(res.text, res.status_code)
282218
logger.debug(res.text)
283-
if headers['Accept'] == 'application/json':
219+
if headers.get('Accept') == 'application/json':
284220
return res.json()
285221
else:
286222
return res.text
@@ -514,15 +450,6 @@ def wait_test_run(self, project_id, test_run_id):
514450

515451
while True:
516452
time.sleep(self.polling_interval_mins * 60)
517-
# WORKAROUND: access token thinks it's still valid,
518-
# > token valid for another 633.357925177
519-
# whilst this happens:
520-
# > Couldn't establish the state of the test run with id: 72593732. Aborting
521-
# > {u'error_description': u'Invalid access token: b3e62604-9d2a-49dc-88f5-89786ff5a6b6',
522-
# > u'error': u'invalid_token'}
523-
if not self.api_key:
524-
self.access_token = None
525-
self.get_token() # in case it expired
526453
test_run_status = self.get_test_run(project_id, test_run_id)
527454
if test_run_status and 'state' in test_run_status:
528455
if test_run_status['state'] == "FINISHED":
@@ -887,12 +814,6 @@ def format_epilog(self, formatter):
887814
parser.add_option("-k", "--apikey", dest="apikey",
888815
help="API key - the API key for Bitbar Cloud. Optional. "
889816
"You can use environment variable TESTDROID_APIKEY as well.")
890-
parser.add_option("-u", "--username", dest="username",
891-
help="Username - the email address. Optional. "
892-
"You can use environment variable TESTDROID_USERNAME as well.")
893-
parser.add_option("-p", "--password", dest="password",
894-
help="Password. Required if username is used. "
895-
"You can use environment variable TESTDROID_PASSWORD as well.")
896817
parser.add_option("-c", "--url", dest="url", default="https://cloud.bitbar.com",
897818
help="Cloud endpoint. Default is https://cloud.bitbar.com. "
898819
"You can use environment variable TESTDROID_URL as well.")
@@ -968,8 +889,6 @@ def cli(self, parser, commands):
968889
if options.quiet:
969890
logger.setLevel(logging.WARNING)
970891

971-
username = options.username or os.environ.get('TESTDROID_USERNAME')
972-
password = options.password or os.environ.get('TESTDROID_PASSWORD')
973892
apikey = options.apikey or os.environ.get('TESTDROID_APIKEY')
974893
url = os.environ.get('TESTDROID_URL') or options.url
975894

@@ -978,8 +897,6 @@ def cli(self, parser, commands):
978897
except:
979898
polling_interval_mins = 10
980899

981-
self.set_username(username)
982-
self.set_password(password)
983900
self.set_apikey(apikey)
984901
self.set_url(url)
985902
self.set_polling_interval_mins(polling_interval_mins)

testdroid/tests/test_all.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@
2727

2828
# check that API calls go where they should go
2929
class TestNetworking(TestCase):
30-
def setUp(self):
31-
# set up the token so gets, posts etc work
32-
url = '{}/oauth/token'.format(URL_BASE)
33-
json = {
34-
'access_token': 'token',
35-
'refresh_token': 'refresh',
36-
'expires_in': 65535
37-
}
38-
responses.add(responses.POST, url, json=json, status=200)
3930

4031
@responses.activate
4132
def test_get(self):
@@ -150,7 +141,7 @@ def test_get_device_sessions_files_without_tags(self):
150141

151142
@responses.activate
152143
def test_get_device_session_files_with_tags(self):
153-
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]={}'.format(
144+
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?limit=0&tag[]={}'.format(
154145
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)
155146
responses.add(responses.GET, url, json=JSON, status=200)
156147
response = t.get_device_session_files(PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)

0 commit comments

Comments
 (0)