Skip to content

Commit 1f5a7c5

Browse files
committed
Http timeouts add
1 parent 323c553 commit 1f5a7c5

File tree

5 files changed

+67
-29
lines changed

5 files changed

+67
-29
lines changed

reportportal_client/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self,
5757
retries=None,
5858
max_pool_size=50,
5959
launch_id=None,
60+
http_timeout=(10, 10),
6061
**_):
6162
"""Initialize required attributes.
6263
@@ -70,6 +71,11 @@ def __init__(self,
7071
:param verify_ssl: Option to skip ssl verification
7172
:param max_pool_size: Option to set the maximum number of
7273
connections to save the pool.
74+
:param launch_id: a launch id to use instead of starting own
75+
one
76+
:param http_timeout: a float in seconds for connect and read
77+
timeout. Use a Tuple to specific connect
78+
and read separately.
7379
"""
7480
set_current(self)
7581
self._batch_logs = []
@@ -85,6 +91,7 @@ def __init__(self,
8591
self.log_batch_size = log_batch_size
8692
self.token = token
8793
self.verify_ssl = verify_ssl
94+
self.http_timeout=http_timeout
8895
self.session = requests.Session()
8996
self.step_reporter = StepReporter(self)
9097
self._item_stack = []

reportportal_client/client.pyi

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ class RPClient:
2323
project: Text = ...
2424
token: Text = ...
2525
verify_ssl: bool = ...
26+
http_timeout: Union[float, Tuple[float, float]] = ...
2627
session: Session = ...
2728
step_reporter: StepReporter = ...
2829

29-
def __init__(self,
30-
endpoint: Text,
31-
project: Text, token: Text,
32-
log_batch_size: int = ...,
33-
is_skipped_an_issue: bool = ...,
34-
verify_ssl: bool = ...,
35-
retries: int = ...,
36-
max_pool_size: int = ...,
37-
launch_id: Text = ...) -> None: ...
30+
def __init__(
31+
self,
32+
endpoint: Text,
33+
project: Text, token: Text,
34+
log_batch_size: int = ...,
35+
is_skipped_an_issue: bool = ...,
36+
verify_ssl: bool = ...,
37+
retries: int = ...,
38+
max_pool_size: int = ...,
39+
launch_id: Text = ...,
40+
http_timeout: Union[float, Tuple[float, float]] = ...
41+
) -> None: ...
3842

3943
def finish_launch(self,
4044
end_time: Text,

reportportal_client/core/rp_requests.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,35 @@ class HttpRequest:
4242
"""This model stores attributes related to RP HTTP requests."""
4343

4444
def __init__(self, session_method, url, data=None, json=None,
45-
files=None, verify_ssl=True):
45+
files=None, verify_ssl=True, http_timeout=(10, 10)):
4646
"""Initialize instance attributes.
4747
4848
:param session_method: Method of the requests.Session instance
4949
:param url: Request URL
5050
:param data: Dictionary, list of tuples, bytes, or file-like
5151
object to send in the body of the request
52-
:param json: JSON to be send in the body of the request
53-
:param verify: Is certificate verification required
52+
:param json: JSON to be sent in the body of the request
53+
:param verify_ssl: Is SSL certificate verification required
54+
:param http_timeout: a float in seconds for connect and read
55+
timeout. Use a Tuple to specific connect and
56+
read separately.
5457
"""
5558
self.data = data
5659
self.files = files
5760
self.json = json
5861
self.session_method = session_method
5962
self.url = url
6063
self.verify_ssl = verify_ssl
64+
self.http_timeout = http_timeout
6165

6266
def make(self):
6367
"""Make HTTP request to the Report Portal API."""
6468
for attempt in range(SEND_RETRY_COUNT):
6569
try:
6670
return RPResponse(self.session_method(
6771
self.url, data=self.data, json=self.json,
68-
files=self.files, verify=self.verify_ssl)
72+
files=self.files, verify=self.verify_ssl,
73+
timeout=self.http_timeout)
6974
)
7075
# https://github.com/reportportal/client-Python/issues/39
7176
except KeyError:

reportportal_client/core/rp_requests.pyi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ from reportportal_client.core.rp_issues import Issue as Issue
33
from reportportal_client.core.rp_responses import RPResponse as RPResponse
44
from reportportal_client.static.abstract import AbstractBaseClass
55
from reportportal_client.static.defines import Priority as Priority
6-
from typing import Any, Callable, ByteString, Dict, IO, List, Optional, Text, Union
6+
from typing import Any, Callable, ByteString, Dict, IO, List, Optional, Text, \
7+
Union, Tuple
8+
79

810
class HttpRequest:
911
session_method: Callable = ...
1012
url: Text = ...
11-
files: Optional[Dict]
12-
data = Optional[Union[Dict, List[Union[tuple, ByteString]], IO]] = ...
13-
json = Optional[Dict] = ...
14-
verify_ssl = Optional[bool]
13+
files: Optional[Dict] = ...
14+
data: Optional[Union[Dict, List[Union[tuple, ByteString]], IO]] = ...
15+
json: Optional[Dict] = ...
16+
verify_ssl: Optional[bool] = ...
17+
http_timeout: Union[float, Tuple[float, float]] = ...
1518
def __init__(self,
1619
session_method: Callable,
1720
url: Text,

reportportal_client/service.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
"""
1414

1515
import json
16+
import logging
17+
import uuid
1618
from time import sleep
1719

1820
import requests
19-
import uuid
20-
import logging
21-
2221
import six
23-
from six.moves.collections_abc import Mapping
2422
from requests.adapters import HTTPAdapter
23+
from six.moves.collections_abc import Mapping
2524

2625
from .errors import ResponseError, EntryCreatedError, OperationCompletionError
2726
from .helpers import verify_value_length
@@ -182,7 +181,7 @@ def __init__(self,
182181
verify_ssl: option to not verify ssl certificates
183182
max_pool_size: option to set the maximum number of
184183
connections to save in the pool.
185-
http_timeout: a float in seconds for the connect and read
184+
http_timeout: a float in seconds for connect and read
186185
timeout. Use a Tuple to specific connect and
187186
read separately.
188187
"""
@@ -262,7 +261,12 @@ def finish_launch(self, end_time, status=None, attributes=None, **kwargs):
262261
"attributes": verify_value_length(attributes)
263262
}
264263
url = uri_join(self.base_url_v2, "launch", self.launch_id, "finish")
265-
r = self.session.put(url=url, json=data, verify=self.verify_ssl)
264+
r = self.session.request(
265+
method='PUT',
266+
url=url,
267+
json=data,
268+
verify=self.verify_ssl
269+
)
266270
logger.debug("finish_launch - ID: %s", self.launch_id)
267271
return _get_msg(r)
268272

@@ -396,7 +400,13 @@ def update_test_item(self, item_uuid, attributes=None, description=None):
396400
}
397401
item_id = self.get_item_id_by_uuid(item_uuid)
398402
url = uri_join(self.base_url_v1, "item", item_id, "update")
399-
r = self.session.put(url=url, json=data, verify=self.verify_ssl)
403+
r = self.session.request(
404+
method='PUT',
405+
url=url,
406+
json=data,
407+
verify=self.verify_ssl,
408+
timeout=self.http_timeout
409+
)
400410
logger.debug("update_test_item - Item: %s", item_id)
401411
return _get_msg(r)
402412

@@ -433,7 +443,12 @@ def finish_test_item(self,
433443
"attributes": verify_value_length(attributes)
434444
}
435445
url = uri_join(self.base_url_v2, "item", item_id)
436-
r = self.session.put(url=url, json=data, verify=self.verify_ssl)
446+
r = self.session.request(
447+
method='PUT',
448+
url=url,
449+
json=data,
450+
verify=self.verify_ssl
451+
)
437452
logger.debug("finish_test_item - ID: %s", item_id)
438453
return _get_msg(r)
439454

@@ -444,11 +459,14 @@ def get_item_id_by_uuid(self, uuid):
444459
:return str: Test item id
445460
"""
446461
url = uri_join(self.base_url_v1, "item", "uuid", uuid)
447-
return _get_json(self.session.request(
462+
return _get_json(
463+
self.session.request(
448464
method='GET',
449465
url=url,
450466
verify=self.verify_ssl,
451-
timeout=self.http_timeout))["id"]
467+
timeout=self.http_timeout
468+
)
469+
)["id"]
452470

453471
def get_project_settings(self):
454472
"""
@@ -462,7 +480,8 @@ def get_project_settings(self):
462480
url=url,
463481
json={},
464482
verify=self.verify_ssl,
465-
timeout=self.http_timeout)
483+
timeout=self.http_timeout
484+
)
466485
logger.debug("settings")
467486
return _get_json(r)
468487

0 commit comments

Comments
 (0)