Skip to content

Commit e543b3d

Browse files
committed
test failed
1 parent bd175cf commit e543b3d

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

cuenca/http/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def __init__(self):
4343
api_key = os.getenv('CUENCA_API_KEY', '')
4444
api_secret = os.getenv('CUENCA_API_SECRET', '')
4545
self.basic_auth = (api_key, api_secret)
46+
retry = Retry(
47+
total=self.retries,
48+
backoff_factor=self.backoff_factor,
49+
read=self.retries,
50+
)
51+
adapter = HTTPAdapter(max_retries=retry)
52+
self.session.mount("https://", adapter)
53+
print('Retry adapter mounted')
4654

4755
@property
4856
def auth(self) -> Optional[Tuple[str, str]]:
@@ -82,13 +90,6 @@ def configure(
8290
if session_token:
8391
self.headers['X-Cuenca-SessionId'] = session_token
8492

85-
retry = Retry(
86-
total=self.retries,
87-
backoff_factor=self.backoff_factor,
88-
)
89-
adapter = HTTPAdapter(max_retries=retry)
90-
self.session.mount("https://", adapter)
91-
9293
def get(
9394
self, endpoint: str, params: ClientRequestParams = None
9495
) -> DictStrAny:

tests/http/test_client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime as dt
2-
from unittest.mock import patch
3-
2+
from unittest.mock import patch, Mock
3+
from requests.exceptions import Timeout
44
import pytest
55
from cuenca_validations.errors import (
66
NoPasswordFoundError,
@@ -90,3 +90,14 @@ def test_no_password():
9090
def test_no_session():
9191
with pytest.raises(UserNotLoggedInError):
9292
Transfer.count()
93+
94+
95+
def test_timeout_raises():
96+
session = Session()
97+
session.configure(
98+
api_key='USER_API_KEY', api_secret='USER_SECRET', sandbox=True
99+
)
100+
with patch('requests.Session.request', side_effect=Timeout()) as mock_timeout:
101+
with pytest.raises(Timeout):
102+
Card.first(user_id='USER_ID', session=session)
103+
assert mock_timeout.call_count == 3

0 commit comments

Comments
 (0)