Skip to content

Commit e93f503

Browse files
committed
Fix review comments
1 parent c1d54ea commit e93f503

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

reportportal_client/_internal/aio/http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ async def __request(self, method: Callable, url, **kwargs: Any) -> ClientRespons
100100
for i in range(self.__retry_number + 1): # add one for the first attempt, which is not a retry
101101
retry_factor = None
102102
if result is not None:
103-
# Close previous result if it's retried to release resources
104-
result.close()
103+
# Release previous result to return connection to pool
104+
await result.release()
105105
try:
106106
result = await method(url, **kwargs)
107107
except Exception as exc:
@@ -210,8 +210,8 @@ async def __request(self, method: Callable, url: str, **kwargs: Any) -> ClientRe
210210
if result.status in AUTH_PROBLEM_STATUSES and self.__auth:
211211
refreshed_header = await self.__auth.refresh()
212212
if refreshed_header:
213-
# Close previous result if it's retried to release resources
214-
result.close()
213+
# Release previous result to return connection to pool
214+
await result.release()
215215
# Retry with new auth header
216216
request_kwargs["headers"] = request_kwargs.get("headers", {}).copy()
217217
request_kwargs["headers"]["Authorization"] = refreshed_header

reportportal_client/_internal/http.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from types import TracebackType
1818
from typing import Any, Callable, Optional, Type, Union
1919

20-
import requests
20+
from requests import Response, Session
21+
from requests.adapters import BaseAdapter
2122

2223
from reportportal_client._internal.services.auth import Auth
2324

@@ -27,7 +28,7 @@
2728
class ClientSession:
2829
"""Class wraps requests.Session and adds authentication support."""
2930

30-
_client: requests.Session
31+
_client: Session
3132
__auth: Optional[Auth]
3233

3334
def __init__(
@@ -38,10 +39,10 @@ def __init__(
3839
3940
:param auth: authentication instance to use for requests
4041
"""
41-
self._client = requests.Session()
42+
self._client = Session()
4243
self.__auth = auth
4344

44-
def __request(self, method: Callable, url: Union[str, bytes], **kwargs: Any) -> requests.Response:
45+
def __request(self, method: Callable, url: Union[str, bytes], **kwargs: Any) -> Response:
4546
"""Make a request with authentication support.
4647
4748
The method adds Authorization header if auth is configured and handles auth refresh
@@ -73,19 +74,19 @@ def __request(self, method: Callable, url: Union[str, bytes], **kwargs: Any) ->
7374

7475
return result
7576

76-
def get(self, url: str, **kwargs: Any) -> requests.Response:
77+
def get(self, url: Union[str, bytes], **kwargs: Any) -> Response:
7778
"""Perform HTTP GET request."""
7879
return self.__request(self._client.get, url, **kwargs)
7980

80-
def post(self, url: str, **kwargs: Any) -> requests.Response:
81+
def post(self, url: Union[str, bytes], **kwargs: Any) -> Response:
8182
"""Perform HTTP POST request."""
8283
return self.__request(self._client.post, url, **kwargs)
8384

84-
def put(self, url: str, **kwargs: Any) -> requests.Response:
85+
def put(self, url: Union[str, bytes], **kwargs: Any) -> Response:
8586
"""Perform HTTP PUT request."""
8687
return self.__request(self._client.put, url, **kwargs)
8788

88-
def mount(self, prefix: str, adapter: requests.adapters.BaseAdapter) -> None:
89+
def mount(self, prefix: str, adapter: BaseAdapter) -> None:
8990
"""Mount an adapter to a specific URL prefix.
9091
9192
:param prefix: URL prefix (e.g., 'http://', 'https://')

tests/_internal/services/test_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ async def test_refresh_request_401_fallback_to_password_grant(self):
426426
assert result1 == f"Bearer {ACCESS_TOKEN}"
427427

428428
# Wait for token to expire
429-
time.sleep(1)
429+
await asyncio.sleep(1)
430430

431431
# Simulate refresh failure and password grant success
432432
refresh_response = mock.AsyncMock()
@@ -468,7 +468,7 @@ async def test_refresh_request_403_fallback_to_password_grant(self):
468468
assert result1 == f"Bearer {ACCESS_TOKEN}"
469469

470470
# Wait for token to expire
471-
time.sleep(1)
471+
await asyncio.sleep(1)
472472

473473
# Simulate refresh failure with 403 and password grant success
474474
refresh_response = mock.AsyncMock()
@@ -520,7 +520,7 @@ async def test_refresh_method_on_valid_token(self):
520520
mock_session.post.return_value = refreshed_response
521521

522522
# Wait to avoid throttling
523-
time.sleep(1)
523+
await asyncio.sleep(1)
524524

525525
result2 = await oauth.refresh()
526526
assert result2 == f"Bearer {new_token}"

0 commit comments

Comments
 (0)