Skip to content

Commit 65944c3

Browse files
committed
Marking deprecated methods using old device-run api
1 parent 7e5d240 commit 65944c3

File tree

2 files changed

+89
-115
lines changed

2 files changed

+89
-115
lines changed

testdroid/__init__.py

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -569,32 +569,51 @@ def get_test_run(self, project_id, test_run_id):
569569

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

572-
def retry_test_run(self, project_id, test_run_id, device_run_ids=None):
573-
""" Re-run an already-existing test run. Specify individual device run IDs to only re-run those devices. """
572+
def retry_test_run(self, project_id, test_run_id, device_session_ids=None):
573+
""" Re-run an already-existing test run. Specify individual device session IDs to only re-run those devices. """
574574

575575
endpoint = "me/projects/%s/runs/%s/retry" % (project_id, test_run_id)
576-
if device_run_ids:
577-
endpoint += "?deviceRunIds[]=" + "&deviceRunIds[]=".join(str(device_id) for device_id in device_run_ids)
576+
if device_session_ids:
577+
endpoint += "?deviceRunIds[]=" + "&deviceRunIds[]=".join(str(device_id) for device_id in device_session_ids)
578578
return self.post(endpoint)
579579

580580
def abort_test_run(self, project_id, test_run_id):
581581
""" Abort a test run """
582582

583583
return self.post("me/projects/%s/runs/%s/abort" % (project_id, test_run_id))
584584

585+
def get_device_sessions(self, project_id, test_run_id, limit=0):
586+
""" Return device sessions for a project """
587+
588+
return self.get(path="me/projects/%s/runs/%s/device-sessions" %
589+
(project_id, test_run_id), payload={'limit': limit})
590+
585591
def get_device_runs(self, project_id, test_run_id, limit=0):
586-
""" Return device runs for a project """
592+
""" ***DEPRECATED***
593+
594+
Return device sessions for a project
595+
use get_device_sessions() instead
596+
"""
587597

588-
return self.get(path="me/projects/%s/runs/%s/device-runs" % (project_id, test_run_id), payload={'limit': limit})
598+
return self.get_device_sessions(project_id, test_run_id, limit)
599+
600+
def get_device_session_screenshots_list(self, project_id, test_run_id, device_session_id, limit=0):
601+
""" Downloads screenshots list for a device session """
602+
603+
return self.get("me/projects/%s/runs/%s/device-sessions/%s/screenshots" %
604+
(project_id, test_run_id, device_session_id), payload={'limit': limit})
589605

590606
def get_device_run_screenshots_list(self, project_id, test_run_id, device_run_id, limit=0):
591-
""" Downloads screenshots list for a device run """
607+
""" ***DEPRECATED***
592608
593-
return self.get("me/projects/%s/runs/%s/device-runs/%s/screenshots" % (project_id, test_run_id, device_run_id),
594-
payload={'limit': limit})
609+
Downloads screenshots list for a device run
610+
use get_device_run_screenshots_list() instead
611+
"""
595612

596-
def get_device_run_files(self, project_id, test_run_id, device_session_id, tags=None):
597-
""" Get list of files for device run """
613+
return self.get_device_session_screenshots_list(project_id, test_run_id, device_run_id, limit)
614+
615+
def get_device_session_files(self, project_id, test_run_id, device_session_id, tags=None):
616+
""" Get list of files for device session """
598617

599618
if tags is None:
600619
return self.get("me/projects/%s/runs/%s/device-sessions/%s/output-file-set/files" %
@@ -603,6 +622,15 @@ def get_device_run_files(self, project_id, test_run_id, device_session_id, tags=
603622
return self.get("me/projects/%s/runs/%s/device-sessions/%s/output-file-set/files?tag[]=%s" %
604623
(project_id, test_run_id, device_session_id, tags))
605624

625+
def get_device_run_files(self, project_id, test_run_id, device_session_id, tags=None):
626+
""" ***DEPRECATED***
627+
628+
Get list of files for device run
629+
use get_device_session_files() instead
630+
"""
631+
632+
return self.get_device_session_files(project_id, test_run_id, device_session_id, tags)
633+
606634
def get_input_files(self, limit=0):
607635
""" Get list of input files """
608636

@@ -612,25 +640,25 @@ def download_test_run(self, project_id, test_run_id):
612640
""" Downloads test run files to a directory hierarchy """
613641

614642
test_run = self.get_test_run(project_id, test_run_id)
615-
device_runs = self.get_device_runs(project_id, test_run_id)
643+
device_sessions = self.get_device_sessions(project_id, test_run_id)
616644

617645
logger.info("")
618-
logger.info("Test run %s: \"%s\" has %s device runs:" %
619-
(test_run['id'], test_run['displayName'], len(device_runs['data'])))
646+
logger.info("Test run %s: \"%s\" has %s device sessions:" %
647+
(test_run['id'], test_run['displayName'], len(device_sessions['data'])))
620648

621-
for device_run in device_runs['data']:
622-
state = device_run['state']
649+
for device_session in device_sessions['data']:
650+
state = device_session['state']
623651
logger.info("")
624-
logger.info("%s \"%s\" %s" % (device_run['id'], device_run['device']['displayName'], state))
652+
logger.info("%s \"%s\" %s" % (device_session['id'], device_session['device']['displayName'], state))
625653

626654
if state in ("ABORTED", "TIMEOUT", "WARNING", "SUCCEEDED", "FAILED", "EXCLUDED"):
627-
directory = "%s-%s/%d-%s" % (test_run_id, test_run['displayName'], device_run['id'],
628-
device_run['device']['displayName'])
629-
session_id = device_run['id']
630-
files = self.get_device_run_files(project_id, test_run_id, session_id)
655+
directory = "%s-%s/%d-%s" % (test_run_id, test_run['displayName'], device_session['id'],
656+
device_session['device']['displayName'])
657+
session_id = device_session['id']
658+
files = self.get_device_session_files(project_id, test_run_id, session_id)
631659
self.__download_files(files, directory)
632660
else:
633-
logger.info("Device run is not ended - Skipping file downloads")
661+
logger.info("Device session hasn't ended - Skipping file downloads")
634662
logger.info("")
635663

636664
def __download_files(self, files, directory):
@@ -654,18 +682,19 @@ def download_test_screenshots(self, project_id, test_run_id):
654682
""" Downloads test run screenshots """
655683

656684
test_run = self.get_test_run(project_id, test_run_id)
657-
device_runs = self.get_device_runs(project_id, test_run_id)
658-
logger.info("Test run %s: \"%s\" has %s device runs:" %
659-
(test_run['id'], test_run['displayName'], len(device_runs['data'])))
660-
for device_run in device_runs['data']:
661-
logger.info("%s \"%s\" %s" % (device_run['id'], device_run['device']['displayName'], device_run['state']))
685+
device_sessions = self.get_device_sessions(project_id, test_run_id)
686+
logger.info("Test run %s: \"%s\" has %s device sessions:" %
687+
(test_run['id'], test_run['displayName'], len(device_sessions['data'])))
688+
for device_session in device_sessions['data']:
689+
logger.info("%s \"%s\" %s" %
690+
(device_session['id'], device_session['device']['displayName'], device_session['state']))
662691

663692
logger.info("")
664-
for device_run in device_runs['data']:
665-
if device_run['state'] in ["SUCCEEDED", "FAILED", "ABORTED", "WARNING", "TIMEOUT"]:
693+
for device_session in device_sessions['data']:
694+
if device_session['state'] in ["SUCCEEDED", "FAILED", "ABORTED", "WARNING", "TIMEOUT"]:
666695
directory = "%s-%s/%d-%s/screenshots" % (test_run['id'], test_run['displayName'],
667-
device_run['id'], device_run['device']['displayName'])
668-
screenshots = self.get_device_run_screenshots_list(project_id, test_run_id, device_run['id'])
696+
device_session['id'], device_session['device']['displayName'])
697+
screenshots = self.get_device_session_screenshots_list(project_id, test_run_id, device_session['id'])
669698
no_screenshots = True
670699

671700
for screenshot in screenshots['data']:
@@ -675,7 +704,7 @@ def download_test_screenshots(self, project_id, test_run_id):
675704
os.makedirs(directory)
676705

677706
if not os.path.exists(full_path):
678-
self.__download_screenshot(project_id, test_run['id'], device_run['id'], screenshot['id'],
707+
self.__download_screenshot(project_id, test_run['id'], device_session['id'], screenshot['id'],
679708
full_path)
680709
else:
681710
''' Earlier downloaded images are checked, and if needed re-downloaded.
@@ -686,18 +715,18 @@ def download_test_screenshots(self, project_id, test_run_id):
686715
else:
687716
raise
688717
except:
689-
self.__download_screenshot(project_id, test_run['id'], device_run['id'], screenshot['id'],
690-
full_path)
718+
self.__download_screenshot(project_id, test_run['id'], device_session['id'],
719+
screenshot['id'], full_path)
691720

692721
if no_screenshots:
693-
logger.info("Device %s has no screenshots - skipping" % device_run['device']['displayName'])
722+
logger.info("Device %s has no screenshots - skipping" % device_session['device']['displayName'])
694723
else:
695724
logger.info("Device %s has errored or has not finished - skipping" %
696-
device_run['device']['displayName'])
725+
device_session['device']['displayName'])
697726

698-
def __download_screenshot(self, project_id, test_run_id, device_run_id, screenshot_id, full_path):
699-
url = "me/projects/%s/runs/%s/device-runs/%s/screenshots/%s" % \
700-
(project_id, test_run_id, device_run_id, screenshot_id)
727+
def __download_screenshot(self, project_id, test_run_id, device_session_id, screenshot_id, full_path):
728+
url = "me/projects/%s/runs/%s/device-sessions/%s/screenshots/%s" % \
729+
(project_id, test_run_id, device_session_id, screenshot_id)
701730
prog = DownloadProgressBar()
702731
self.download(url, full_path, callback=lambda pos, total: prog.update(int(pos), int(total)))
703732
print("")
@@ -740,7 +769,7 @@ def get_access_group_resources(self, access_group_id):
740769
def get_access_group_resource(self, access_group_id, resource_id):
741770
""" Get resource from access group """
742771

743-
return self.get("ame/ccess-groups/{}/resources/{}".format(access_group_id, resource_id))
772+
return self.get("me/access-groups/{}/resources/{}".format(access_group_id, resource_id))
744773

745774
def delete_access_group_resource(self, access_group_id, resource_id):
746775
""" Delete resource from access group """
@@ -795,7 +824,6 @@ def format_epilog(self, formatter):
795824
usage = "usage: %prog [options] <command> [arguments...]"
796825
description = "Client for Bitbar Cloud API v2"
797826
epilog = """
798-
799827
Commands:
800828
801829
me Get user details
@@ -824,15 +852,17 @@ def format_epilog(self, formatter):
824852
wait-test-run <project-id> <test-run-id> Await completion (polling) of the test run
825853
test-runs <project-id> Get test runs for a project
826854
test-run <project-id> <test-run-id> Get test run details
827-
device-runs <project-id> <test-run-id> Get device runs for a test run
855+
get_device_sessions <project-id> <test-run-id>
856+
Get device sessions for a test run
857+
device-runs <project-id> <test-run-id> ***DEPRECATED*** Get device runs for a test run
828858
download-test-run <project-id> <test-run-id>
829859
Download test run data. Data will be downloaded to
830860
current directory in a structure:
831-
[test-run-id]/[device-run-id]-[device-name]/files...
861+
[test-run-id]/[device-session-id]-[device-name]/files...
832862
download-test-screenshots <project-id> <test-run-id>
833863
Download test run screenshots. Screenshots will be downloaded to
834864
current directory in a structure:
835-
[test-run-id]/[device-run-id]-[device-name]/screenshots/...
865+
[test-run-id]/[device-session-id]-[device-name]/screenshots/...
836866
837867
access-groups Get access groups
838868
access-group <access-group-id> Get an access group by id
@@ -901,6 +931,8 @@ def get_commands(self):
901931
"wait-test-run": self.wait_test_run,
902932
"test-run": self.get_test_run,
903933
"test-runs": self.print_project_test_runs,
934+
"device-sessions": self.get_device_sessions,
935+
"device-session-files": self.get_device_session_files,
904936
"device-runs": self.get_device_runs,
905937
"device-run-files": self.get_device_run_files,
906938
"list-input-files": self.print_input_files,

testdroid/tests/test_all.py

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
JSON = {'k': 'v'}
1010
PROJECT_ID = 2
1111
TEST_RUN_ID = 3
12-
DEVICE_RUN_ID = 4
1312
DEVICE_SESSION_ID = 5
1413
DEVICE_GROUP_ID = 6
1514
USER_ID = 7
@@ -112,20 +111,6 @@ def test_get_project(self):
112111
response = t.get_project(PROJECT_ID)
113112
self.assertEqual(response, JSON)
114113

115-
@responses.activate
116-
def test_get_project_parameters(self):
117-
url = '{}/projects/{}/config/parameters'.format(URL_API_ME, PROJECT_ID)
118-
responses.add(responses.GET, url, json=JSON, status=200)
119-
response = t.get_project_parameters(PROJECT_ID)
120-
self.assertEqual(response, JSON)
121-
122-
@responses.activate
123-
def test_get_project_config(self):
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-
129114
@responses.activate
130115
def test_get_project_test_runs(self):
131116
url = '{}/projects/{}/runs'.format(URL_API_ME, PROJECT_ID)
@@ -135,87 +120,44 @@ def test_get_project_test_runs(self):
135120

136121
@responses.activate
137122
def test_get_test_run(self):
138-
url = '{}/projects/{}/runs/{}'.format(URL_API_ME, PROJECT_ID,
139-
TEST_RUN_ID)
123+
url = '{}/projects/{}/runs/{}'.format(URL_API_ME, PROJECT_ID, TEST_RUN_ID)
140124
responses.add(responses.GET, url, json=JSON, status=200)
141125
response = t.get_test_run(PROJECT_ID, TEST_RUN_ID)
142126
self.assertEqual(response, JSON)
143127

144128
@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)
129+
def test_get_device_session(self):
130+
url = '{}/projects/{}/runs/{}/device-sessions'.format(URL_API_ME, PROJECT_ID, TEST_RUN_ID)
148131
responses.add(responses.GET, url, json=JSON, status=200)
149-
response = t.get_device_runs(PROJECT_ID, TEST_RUN_ID)
132+
response = t.get_device_sessions(PROJECT_ID, TEST_RUN_ID)
150133
self.assertEqual(response, JSON)
151134

152135
@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)
136+
def test_get_device_session_screenshots_list(self):
137+
url = '{}/projects/{}/runs/{}/device-sessions/{}/screenshots'.format(
138+
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID)
156139
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)
140+
response = t.get_device_session_screenshots_list(PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID)
159141
self.assertEqual(response, JSON)
160142

161143
@responses.activate
162-
def test_get_device_run_files_without_tags(self):
144+
def test_get_device_sessions_files_without_tags(self):
163145
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files'.format(
164146
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID)
165147
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)
148+
response = t.get_device_session_files(PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID)
168149
self.assertEqual(response, JSON)
169150

170151
@responses.activate
171-
def test_get_device_run_files_with_tags(self):
152+
def test_get_device_session_files_with_tags(self):
172153
url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]={}'.format(
173154
URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)
174155
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)
156+
response = t.get_device_session_files(PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS)
177157
self.assertEqual(response, JSON)
178158

179159
@responses.activate
180160
def test_get_input_files(self):
181-
url = '{}/files?limit={}&filter=s_direction_eq_INPUT'.format(
182-
URL_API_ME, LIMIT)
161+
url = '{}/files?limit={}&filter=s_direction_eq_INPUT'.format(URL_API_ME, LIMIT)
183162
responses.add(responses.GET, url, json=JSON, status=200)
184163
self.assertEqual(t.get_input_files(LIMIT), JSON)
185-
186-
@responses.activate
187-
def test_start_test_run(self):
188-
url = '{}/projects/2'.format(
189-
URL_API_ME)
190-
json = {
191-
'id': USER_ID,
192-
'name': 'Sample project',
193-
}
194-
195-
responses.add(responses.GET, url, json=json, status=200)
196-
197-
responses.add(responses.GET, URL_API_ME, json=json, status=200)
198-
199-
url = '{}/projects/{}/runs'.format(
200-
URL_USERS, PROJECT_ID)
201-
json = {
202-
'id': 12,
203-
'displayName': "My test run"
204-
}
205-
206-
responses.add(responses.POST, url, json=json, status=201)
207-
self.assertEqual(t.start_test_run(PROJECT_ID, DEVICE_GROUP_ID), json['id'])
208-
209-
@responses.activate
210-
def test_delete_project_parameters(self):
211-
path = 'projects/{}/config/parameters/{}'.format(PROJECT_ID, PARAM_ID)
212-
url = '{}/{}'.format(URL_USERS, path)
213-
214-
json = {
215-
'id': USER_ID
216-
}
217-
218-
responses.add(responses.GET, URL_API_ME, json=json, status=200)
219-
responses.add(responses.DELETE, url, json=JSON, status=204)
220-
response = t.delete_project_parameters(PROJECT_ID, PARAM_ID)
221-
self.assertEqual(response.status_code, 204)

0 commit comments

Comments
 (0)