|
12 | 12 | # limitations under the License |
13 | 13 |
|
14 | 14 | import pytest |
15 | | -from reportportal_client.helpers import timestamp |
| 15 | +from requests import Response |
16 | 16 | from requests.exceptions import ReadTimeout |
17 | 17 |
|
| 18 | +from reportportal_client.helpers import timestamp |
| 19 | +from reportportal_client.static.defines import NOT_FOUND |
| 20 | + |
18 | 21 |
|
19 | 22 | def connection_error(*args, **kwargs): |
20 | 23 | raise ReadTimeout() |
21 | 24 |
|
22 | 25 |
|
| 26 | +def response_error(*args, **kwargs): |
| 27 | + result = Response() |
| 28 | + result._content = '502 Gateway Timeout'.encode('ASCII') |
| 29 | + result.status_code = 502 |
| 30 | + return result |
| 31 | + |
| 32 | + |
23 | 33 | @pytest.mark.parametrize( |
24 | | - 'requests_method, client_method, client_params', |
| 34 | + 'requests_method, client_method, client_params, expected_result', |
25 | 35 | [ |
26 | | - ('put', 'finish_launch', [timestamp()]), |
27 | | - ('put', 'finish_test_item', ['test_item_id', timestamp()]), |
28 | | - ('get', 'get_item_id_by_uuid', ['test_item_uuid']), |
29 | | - ('get', 'get_launch_info', []), |
30 | | - ('get', 'get_launch_ui_id', []), |
31 | | - ('get', 'get_launch_ui_url', []), |
32 | | - ('get', 'get_project_settings', []), |
33 | | - ('post', 'start_launch', ['Test Launch', timestamp()]), |
34 | | - ('post', 'start_test_item', ['Test Item', timestamp(), 'STEP']), |
35 | | - ('put', 'update_test_item', ['test_item_id']) |
| 36 | + ('put', 'finish_launch', [timestamp()], NOT_FOUND), |
| 37 | + ('put', 'finish_test_item', ['test_item_id', timestamp()], NOT_FOUND), |
| 38 | + ('get', 'get_item_id_by_uuid', ['test_item_uuid'], NOT_FOUND), |
| 39 | + ('get', 'get_launch_info', [], {}), |
| 40 | + ('get', 'get_launch_ui_id', [], None), |
| 41 | + ('get', 'get_launch_ui_url', [], None), |
| 42 | + ('get', 'get_project_settings', [], {}), |
| 43 | + ('post', 'start_launch', ['Test Launch', timestamp()], NOT_FOUND), |
| 44 | + ('post', 'start_test_item', ['Test Item', timestamp(), 'STEP'], |
| 45 | + NOT_FOUND), |
| 46 | + ('put', 'update_test_item', ['test_item_id'], NOT_FOUND) |
36 | 47 | ] |
37 | 48 | ) |
38 | 49 | def test_connection_errors(rp_client, requests_method, client_method, |
39 | | - client_params): |
| 50 | + client_params, expected_result): |
40 | 51 | rp_client.launch_id = 'test_launch_id' |
41 | 52 | getattr(rp_client.session, requests_method).side_effect = connection_error |
42 | 53 | result = getattr(rp_client, client_method)(*client_params) |
43 | | - |
44 | 54 | assert result is None |
| 55 | + |
| 56 | + getattr(rp_client.session, requests_method).side_effect = response_error |
| 57 | + result = getattr(rp_client, client_method)(*client_params) |
| 58 | + assert result == expected_result |
0 commit comments