Skip to content

Commit d0d3645

Browse files
author
Sakari Rautiainen
authored
Merge pull request #118 from lex/return-jsons
make file uploads return jsons
2 parents 9996015 + b8d037c commit d0d3645

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

testdroid/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ 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-
return res
243+
return res.json()
244244

245245
""" GET from API resource
246246
"""
@@ -396,22 +396,21 @@ def print_projects(self, limit=0):
396396
def upload_application_file(self, project_id, filename):
397397
me = self.get_me()
398398
path = "users/%s/projects/%s/files/application" % (me['id'], project_id)
399-
self.upload(path=path, filename=filename)
399+
return self.upload(path=path, filename=filename)
400400

401401
""" Upload application file to project
402402
"""
403403
def upload_file(self, filename):
404404
me = self.get_me()
405405
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']))
406+
return self.upload(path=path, filename=filename)
408407

409408
""" Upload test file to project
410409
"""
411410
def upload_test_file(self, project_id, filename):
412411
me = self.get_me()
413412
path = "users/%s/projects/%s/files/test" % (me['id'], project_id)
414-
self.upload(path=path, filename=filename)
413+
return self.upload(path=path, filename=filename)
415414

416415
""" Delete project parameter
417416
"""
@@ -431,7 +430,7 @@ def get_project_parameters(self, project_id):
431430
def upload_data_file(self, project_id, filename):
432431
me = self.get_me()
433432
path = "users/%s/projects/%s/files/data" % (me['id'], project_id)
434-
self.upload(path=path, filename=filename)
433+
return self.upload(path=path, filename=filename)
435434

436435
""" Set project parameters
437436
"""
@@ -464,7 +463,7 @@ def set_project_framework(self, project_id, frameworkId):
464463
path = "projects/%(project_id)s/frameworks" % {
465464
'project_id': project_id
466465
}
467-
self.post(path, payload={"frameworkId": frameworkId})
466+
return self.post(path, payload={"frameworkId": frameworkId})
468467

469468

470469
""" Start a test run using test run config

testdroid/tests/test_all.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_upload(self):
6969
url = '{}/{}'.format(URL_API, path)
7070
responses.add(responses.POST, url, json=JSON, status=200)
7171
response = t.upload(path, file_path)
72-
self.assertEqual(response.status_code, 200)
72+
self.assertEqual(response, JSON)
7373

7474
@responses.activate
7575
def test_get_me(self):
@@ -194,19 +194,20 @@ def test_start_test_run(self):
194194
'id': USER_ID,
195195
'name': 'Sample project',
196196
}
197+
197198
responses.add(responses.GET, url, json=json, status=200)
198199

199200
responses.add(responses.GET, URL_API_ME, json=json, status=200)
201+
200202
url = '{}/projects/{}/runs'.format(
201203
URL_USERS, PROJECT_ID)
202204
json = {
203205
'id': 12,
204206
'displayName': "My test run"
205207
}
206208

207-
208209
responses.add(responses.POST, url, json=json, status=201)
209-
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])
210+
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])
210211

211212
@responses.activate
212213
def test_delete_project_parameters(self):
@@ -216,9 +217,8 @@ def test_delete_project_parameters(self):
216217
json = {
217218
'id': USER_ID
218219
}
220+
219221
responses.add(responses.GET, URL_API_ME, json=json, status=200)
220222
responses.add(responses.DELETE, url, json=JSON, status=204)
221223
response = t.delete_project_parameters(PROJECT_ID, PARAM_ID)
222224
self.assertEqual(response.status_code, 204)
223-
224-

0 commit comments

Comments
 (0)