|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +from unittest import TestCase |
| 4 | +import os |
| 5 | + |
| 6 | +import testdroid |
| 7 | +import responses |
| 8 | + |
| 9 | +URL_BASE = 'https://cloud.bitbar.com' |
| 10 | +URL_API = '{}/api/v2'.format(URL_BASE) |
| 11 | +URL_API_ME = '{}/me'.format(URL_API) |
| 12 | +URL_USERS = '{}/users'.format(URL_BASE) |
| 13 | +JSON = {'k': 'v'} |
| 14 | +PROJECT_ID = 2 |
| 15 | +TEST_RUN_ID = 3 |
| 16 | +DEVICE_RUN_ID = 4 |
| 17 | +DEVICE_SESSION_ID = 5 |
| 18 | +TAGS = 'tags' |
| 19 | +LIMIT = 0 |
| 20 | + |
| 21 | +t = testdroid.Testdroid() |
| 22 | + |
| 23 | + |
| 24 | +# check that API calls go where they should go |
| 25 | +class TestNetworking(TestCase): |
| 26 | + def setUp(self): |
| 27 | + # set up the token so gets, posts etc work |
| 28 | + url = '{}/oauth/token'.format(URL_BASE) |
| 29 | + json = { |
| 30 | + 'access_token': 'token', |
| 31 | + 'refresh_token': 'refresh', |
| 32 | + 'expires_in': 65535 |
| 33 | + } |
| 34 | + responses.add(responses.POST, url, json=json, status=200) |
| 35 | + |
| 36 | + @responses.activate |
| 37 | + def test_get(self): |
| 38 | + path = 'get' |
| 39 | + url = '{}/{}'.format(URL_API, path) |
| 40 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 41 | + response = t.get('get') |
| 42 | + self.assertEqual(response, JSON) |
| 43 | + |
| 44 | + @responses.activate |
| 45 | + def test_get_post(self): |
| 46 | + path = 'post' |
| 47 | + url = '{}/{}'.format(URL_API, path) |
| 48 | + responses.add(responses.POST, url, json=JSON, status=200) |
| 49 | + response = t.post(path) |
| 50 | + self.assertEqual(response, JSON) |
| 51 | + |
| 52 | + @responses.activate |
| 53 | + def test_delete(self): |
| 54 | + path = 'delete' |
| 55 | + url = '{}/{}'.format(URL_API, path) |
| 56 | + responses.add(responses.DELETE, url, json=JSON, status=200) |
| 57 | + response = t.delete(path) |
| 58 | + self.assertEqual(response.status_code, 200) |
| 59 | + |
| 60 | + @responses.activate |
| 61 | + def test_upload(self): |
| 62 | + path = 'upload' |
| 63 | + file_path = '{}/testdroid/tests/upload.txt'.format(os.getcwd()) |
| 64 | + url = '{}/{}'.format(URL_API, path) |
| 65 | + responses.add(responses.POST, url, json=JSON, status=200) |
| 66 | + response = t.upload(path, file_path) |
| 67 | + self.assertEqual(response.status_code, 200) |
| 68 | + |
| 69 | + @responses.activate |
| 70 | + def test_get_me(self): |
| 71 | + url = URL_API_ME |
| 72 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 73 | + self.assertEqual(t.get_me(), JSON) |
| 74 | + |
| 75 | + @responses.activate |
| 76 | + def test_get_device_groups(self): |
| 77 | + url = '{}/device-groups'.format(URL_API_ME) |
| 78 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 79 | + response = t.get_device_groups() |
| 80 | + self.assertEqual(response, JSON) |
| 81 | + |
| 82 | + @responses.activate |
| 83 | + def test_get_frameworks(self): |
| 84 | + url = '{}/available-frameworks'.format(URL_API_ME) |
| 85 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 86 | + response = t.get_frameworks() |
| 87 | + self.assertEqual(response, JSON) |
| 88 | + |
| 89 | + @responses.activate |
| 90 | + def test_get_devices(self): |
| 91 | + url = '{}/devices'.format(URL_API) |
| 92 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 93 | + response = t.get_devices() |
| 94 | + self.assertEqual(response, JSON) |
| 95 | + |
| 96 | + @responses.activate |
| 97 | + def test_get_projects(self): |
| 98 | + url = '{}/projects'.format(URL_API_ME) |
| 99 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 100 | + response = t.get_projects() |
| 101 | + self.assertEqual(response, JSON) |
| 102 | + |
| 103 | + @responses.activate |
| 104 | + def test_get_project(self): |
| 105 | + PROJECT_ID = 2 |
| 106 | + url = '{}/projects/{}'.format(URL_API_ME, PROJECT_ID) |
| 107 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 108 | + response = t.get_project(PROJECT_ID) |
| 109 | + self.assertEqual(response, JSON) |
| 110 | + |
| 111 | + @responses.activate |
| 112 | + def test_get_project_parameters(self): |
| 113 | + PROJECT_ID = 2 |
| 114 | + url = '{}/projects/{}/config/parameters'.format(URL_API_ME, PROJECT_ID) |
| 115 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 116 | + response = t.get_project_parameters(PROJECT_ID) |
| 117 | + self.assertEqual(response, JSON) |
| 118 | + |
| 119 | + @responses.activate |
| 120 | + def test_get_project_config(self): |
| 121 | + PROJECT_ID = 2 |
| 122 | + url = '{}/projects/{}/config'.format(URL_API_ME, PROJECT_ID) |
| 123 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 124 | + response = t.get_project_config(PROJECT_ID) |
| 125 | + self.assertEqual(response, JSON) |
| 126 | + |
| 127 | + @responses.activate |
| 128 | + def test_get_project_test_runs(self): |
| 129 | + url = '{}/projects/{}/runs'.format(URL_API_ME, PROJECT_ID) |
| 130 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 131 | + response = t.get_project_test_runs(PROJECT_ID) |
| 132 | + self.assertEqual(response, JSON) |
| 133 | + |
| 134 | + @responses.activate |
| 135 | + def test_get_test_run(self): |
| 136 | + url = '{}/projects/{}/runs/{}'.format(URL_API_ME, PROJECT_ID, |
| 137 | + TEST_RUN_ID) |
| 138 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 139 | + response = t.get_test_run(PROJECT_ID, TEST_RUN_ID) |
| 140 | + self.assertEqual(response, JSON) |
| 141 | + |
| 142 | + @responses.activate |
| 143 | + def test_get_device_runs(self): |
| 144 | + url = '{}/projects/{}/runs/{}/device-runs'.format( |
| 145 | + URL_API_ME, PROJECT_ID, TEST_RUN_ID) |
| 146 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 147 | + response = t.get_device_runs(PROJECT_ID, TEST_RUN_ID) |
| 148 | + self.assertEqual(response, JSON) |
| 149 | + |
| 150 | + @responses.activate |
| 151 | + def test_get_device_run_screenshots_list(self): |
| 152 | + url = '{}/projects/{}/runs/{}/device-runs/{}/screenshots'.format( |
| 153 | + URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_RUN_ID) |
| 154 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 155 | + response = t.get_device_run_screenshots_list(PROJECT_ID, TEST_RUN_ID, |
| 156 | + DEVICE_RUN_ID) |
| 157 | + self.assertEqual(response, JSON) |
| 158 | + |
| 159 | + @responses.activate |
| 160 | + def test_get_device_run_files_without_tags(self): |
| 161 | + url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files'.format( |
| 162 | + URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID) |
| 163 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 164 | + response = t.get_device_run_files(PROJECT_ID, TEST_RUN_ID, |
| 165 | + DEVICE_SESSION_ID) |
| 166 | + self.assertEqual(response, JSON) |
| 167 | + |
| 168 | + @responses.activate |
| 169 | + def test_get_device_run_files_with_tags(self): |
| 170 | + url = '{}/projects/{}/runs/{}/device-sessions/{}/output-file-set/files?tag[]?={}'.format( |
| 171 | + URL_API_ME, PROJECT_ID, TEST_RUN_ID, DEVICE_SESSION_ID, TAGS) |
| 172 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 173 | + response = t.get_device_run_files(PROJECT_ID, TEST_RUN_ID, |
| 174 | + DEVICE_SESSION_ID, TAGS) |
| 175 | + self.assertEqual(response, JSON) |
| 176 | + |
| 177 | + @responses.activate |
| 178 | + def test_get_input_files(self): |
| 179 | + url = '{}/files?limit={}&filter=s_direction_eq_INPUT'.format( |
| 180 | + URL_API_ME, LIMIT) |
| 181 | + responses.add(responses.GET, url, json=JSON, status=200) |
| 182 | + self.assertEqual(t.get_input_files(LIMIT), JSON) |
0 commit comments