Skip to content

Commit c7b6152

Browse files
committed
Client stability fixes
1 parent 8b3599a commit c7b6152

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

reportportal_client/client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def finish_launch(self,
119119
CANCELLED
120120
:param attributes: Launch attributes
121121
"""
122+
if self.launch_id is NOT_FOUND or not self.launch_id:
123+
logger.warning("Attempt to finish non-existent launch")
124+
return
122125
url = uri_join(self.base_url_v2, 'launch', self.launch_id, 'finish')
123126
request_payload = LaunchFinishRequest(
124127
end_time,
@@ -159,9 +162,9 @@ def finish_test_item(self,
159162
:param retry: Used to report retry of the test. Allowable values:
160163
"True" or "False"
161164
"""
162-
if item_id is NOT_FOUND:
163-
logger.warning("Uttempt to finish non-existent item")
164-
return None
165+
if item_id is NOT_FOUND or not item_id:
166+
logger.warning("Attempt to finish non-existent item")
167+
return
165168
url = uri_join(self.base_url_v2, 'item', item_id)
166169
request_payload = ItemFinishRequest(
167170
end_time,
@@ -337,6 +340,10 @@ def start_test_item(self,
337340
values: "True" or "False"
338341
:param test_case_id: A unique ID of the current step
339342
"""
343+
if parent_item_id is NOT_FOUND:
344+
logger.warning("Attempt to start item for non-existent parent "
345+
"item")
346+
return
340347
if parent_item_id:
341348
url = uri_join(self.base_url_v2, 'item', parent_item_id)
342349
else:

reportportal_client/core/log_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
RPRequestLog
2525
)
2626
from reportportal_client.core.worker import APIWorker
27+
from reportportal_client.static.defines import NOT_FOUND
2728

2829
logger = logging.getLogger(__name__)
2930

@@ -91,6 +92,9 @@ def log(self, time, message=None, level=None, attachment=None,
9192
:param attachment: Attachments(images,files,etc.)
9293
:param item_id: parent item UUID
9394
"""
95+
if item_id is NOT_FOUND:
96+
logger.warning("Attempt to log to non-existent item")
97+
return
9498
rp_file = RPFile(**attachment) if attachment else None
9599
rp_log = RPRequestLog(self.launch_id, time, rp_file, item_id,
96100
level, message)

reportportal_client/core/rp_responses.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
See the License for the specific language governing permissions and
1919
limitations under the License.
2020
"""
21+
import logging
2122

2223
from reportportal_client.static.defines import NOT_FOUND
23-
from reportportal_client.static.errors import ResponseError
24+
25+
logger = logging.getLogger(__name__)
2426

2527

2628
class RPMessage(object):
@@ -74,8 +76,10 @@ def _get_json(data):
7476
try:
7577
return data.json()
7678
except ValueError as error:
77-
raise ResponseError('Invalid response: {0}: {1}'
78-
.format(error, data.text))
79+
logger.warning('Invalid response: {0}: {1}'
80+
.format(error, data.text),
81+
exc_info=error)
82+
return {}
7983

8084
@property
8185
def id(self):

tests/test_client.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,47 @@
1212
# limitations under the License
1313

1414
import pytest
15-
from reportportal_client.helpers import timestamp
15+
from requests import Response
1616
from requests.exceptions import ReadTimeout
1717

18+
from reportportal_client.helpers import timestamp
19+
from reportportal_client.static.defines import NOT_FOUND
20+
1821

1922
def connection_error(*args, **kwargs):
2023
raise ReadTimeout()
2124

2225

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+
2333
@pytest.mark.parametrize(
24-
'requests_method, client_method, client_params',
34+
'requests_method, client_method, client_params, expected_result',
2535
[
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)
3647
]
3748
)
3849
def test_connection_errors(rp_client, requests_method, client_method,
39-
client_params):
50+
client_params, expected_result):
4051
rp_client.launch_id = 'test_launch_id'
4152
getattr(rp_client.session, requests_method).side_effect = connection_error
4253
result = getattr(rp_client, client_method)(*client_params)
43-
4454
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

Comments
 (0)