Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions testdroid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def upload(self, path=None, filename=None):
res = requests.post(url, files=files, headers=self._build_headers())
if res.status_code not in list(range(200, 300)):
raise RequestResponseError(res.text, res.status_code)
return res
return res.json()

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

""" Upload application file to project
"""
def upload_file(self, filename):
me = self.get_me()
path = "users/%s/files" % (me['id'])
res = self.upload(path=path, filename=filename).json()
print("ID:%s Name:%s Size:%s" % (str(res['id']).ljust(10), res['name'].ljust(15), res['size']))
return self.upload(path=path, filename=filename)

""" Upload test file to project
"""
def upload_test_file(self, project_id, filename):
me = self.get_me()
path = "users/%s/projects/%s/files/test" % (me['id'], project_id)
self.upload(path=path, filename=filename)
return self.upload(path=path, filename=filename)

""" Delete project parameter
"""
Expand All @@ -431,7 +430,7 @@ def get_project_parameters(self, project_id):
def upload_data_file(self, project_id, filename):
me = self.get_me()
path = "users/%s/projects/%s/files/data" % (me['id'], project_id)
self.upload(path=path, filename=filename)
return self.upload(path=path, filename=filename)

""" Set project parameters
"""
Expand Down Expand Up @@ -464,7 +463,7 @@ def set_project_framework(self, project_id, frameworkId):
path = "projects/%(project_id)s/frameworks" % {
'project_id': project_id
}
self.post(path, payload={"frameworkId": frameworkId})
return self.post(path, payload={"frameworkId": frameworkId})


""" Start a test run using test run config
Expand Down
10 changes: 5 additions & 5 deletions testdroid/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_upload(self):
url = '{}/{}'.format(URL_API, path)
responses.add(responses.POST, url, json=JSON, status=200)
response = t.upload(path, file_path)
self.assertEqual(response.status_code, 200)
self.assertEqual(response, JSON)

@responses.activate
def test_get_me(self):
Expand Down Expand Up @@ -194,19 +194,20 @@ def test_start_test_run(self):
'id': USER_ID,
'name': 'Sample project',
}

responses.add(responses.GET, url, json=json, status=200)

responses.add(responses.GET, URL_API_ME, json=json, status=200)

url = '{}/projects/{}/runs'.format(
URL_USERS, PROJECT_ID)
json = {
'id': 12,
'displayName': "My test run"
}


responses.add(responses.POST, url, json=json, status=201)
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])

@responses.activate
def test_delete_project_parameters(self):
Expand All @@ -216,9 +217,8 @@ def test_delete_project_parameters(self):
json = {
'id': USER_ID
}

responses.add(responses.GET, URL_API_ME, json=json, status=200)
responses.add(responses.DELETE, url, json=JSON, status=204)
response = t.delete_project_parameters(PROJECT_ID, PARAM_ID)
self.assertEqual(response.status_code, 204)