Skip to content

Commit 7e5d240

Browse files
committed
Clean mutable parameters
1 parent 6860eb9 commit 7e5d240

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

testdroid/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ def __build_headers(self):
210210
else:
211211
return {'Authorization': 'Bearer %s' % self.get_token(), 'Accept': 'application/json'}
212212

213-
def download(self, path=None, filename=None, payload={}, callback=None):
213+
def download(self, path=None, filename=None, payload=None, callback=None):
214214
""" Download file from API resource """
215215

216+
if payload is None:
217+
payload = {}
216218
url = "%s/api/v2/%s" % (self.cloud_url, path)
217219
try:
218220
res = requests.get(url, params=payload, headers=self.__build_headers(), stream=True, timeout=60.0)
@@ -264,15 +266,16 @@ def upload(self, path=None, filename=None):
264266
raise RequestResponseError(res.text, res.status_code)
265267
return res.json()
266268

267-
def get(self, path=None, payload={}, headers={}):
269+
def get(self, path, payload=None, headers=None):
268270
""" GET from API resource """
269271

272+
if payload is None:
273+
payload = {}
270274
if path.find('v2/') >= 0:
271275
cut_path = path.split('v2/')
272276
path = cut_path[1]
273277

274-
url = "%s/api/v2/%s" % (self.cloud_url, path)
275-
headers = dict(list(self.__build_headers().items()) + list(headers.items()))
278+
(url, headers) = self.__get_request_params(path, headers)
276279
res = requests.get(url, params=payload, headers=headers)
277280
if res.status_code not in list(range(200, 300)):
278281
raise RequestResponseError(res.text, res.status_code)
@@ -282,26 +285,30 @@ def get(self, path=None, payload={}, headers={}):
282285
else:
283286
return res.text
284287

285-
def post(self, path=None, payload=None, headers={}):
288+
def post(self, path=None, payload=None, headers=None):
286289
""" POST against API resources """
287290

288-
headers = dict(list(self.__build_headers().items()) + list(headers.items()))
289-
url = "%s/api/v2/%s" % (self.cloud_url, path)
291+
(url, headers) = self.__get_request_params(path, headers)
290292
res = requests.post(url, payload, headers=headers)
291293
if res.status_code not in list(range(200, 300)):
292294
raise RequestResponseError(res.text, res.status_code)
293295
return res.json()
294296

295-
def delete(self, path=None, headers={}):
297+
def delete(self, path=None, headers=None):
296298
""" DELETE API resource """
297299

298-
headers = dict(list(self.__build_headers().items()) + list(headers.items()))
299-
url = "%s/api/v2/%s" % (self.cloud_url, path)
300+
(url, headers) = self.__get_request_params(path, headers)
300301
res = requests.delete(url, headers=headers)
301302
if res.status_code not in list(range(200, 300)):
302303
raise RequestResponseError(res.text, res.status_code)
303304
return res
304305

306+
def __get_request_params(self, path, headers):
307+
if headers is None:
308+
headers = {}
309+
return ("%s/api/v2/%s" % (self.cloud_url, path),
310+
dict(list(self.__build_headers().items()) + list(headers.items())))
311+
305312
def get_me(self):
306313
""" Returns user details """
307314

@@ -562,7 +569,7 @@ def get_test_run(self, project_id, test_run_id):
562569

563570
return self.get("me/projects/%s/runs/%s" % (project_id, test_run_id))
564571

565-
def retry_test_run(self, project_id, test_run_id, device_run_ids=[]):
572+
def retry_test_run(self, project_id, test_run_id, device_run_ids=None):
566573
""" Re-run an already-existing test run. Specify individual device run IDs to only re-run those devices. """
567574

568575
endpoint = "me/projects/%s/runs/%s/retry" % (project_id, test_run_id)

0 commit comments

Comments
 (0)