Skip to content

Commit 64f7cbc

Browse files
committed
fixing failing tests
1 parent fc21c2e commit 64f7cbc

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

tests/e2e/common/retry_test_mixins.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def _test_retry_disabled_with_message(self, error_msg_substring, exception_type)
5959

6060

6161
@contextmanager
62-
def mocked_server_response(
63-
status: int = 200, headers: dict = {}, redirect_location: str = None
64-
):
62+
def mocked_server_response(status: int = 200, headers: dict = {}, redirect_location: str = None):
6563
"""Context manager for patching urllib3 responses"""
6664

6765
# When mocking mocking a BaseHTTPResponse for urllib3 the mock must include
@@ -99,9 +97,7 @@ def mock_sequential_server_responses(responses: List[dict]):
9997
# Each resp should have these members:
10098

10199
for resp in responses:
102-
_mock = MagicMock(
103-
headers=resp["headers"], msg=resp["headers"], status=resp["status"]
104-
)
100+
_mock = MagicMock(headers=resp["headers"], msg=resp["headers"], status=resp["status"])
105101
_mock.get_redirect_location.return_value = (
106102
False if resp["redirect_location"] is None else resp["redirect_location"]
107103
)
@@ -122,7 +118,7 @@ class PySQLRetryTestsMixin:
122118
_retry_policy = {
123119
"_retry_delay_min": 0.1,
124120
"_retry_delay_max": 5,
125-
"_re" "_retry_stop_after_attempts_count": 5,
121+
"_retry_stop_after_attempts_count": 5,
126122
"_retry_stop_after_attempts_duration": 10,
127123
"_retry_delay_default": 0.5,
128124
}
@@ -180,9 +176,7 @@ def test_retry_exponential_backoff(self):
180176
retry_policy["_retry_delay_min"] = 1
181177

182178
time_start = time.time()
183-
with mocked_server_response(
184-
status=429, headers={"Retry-After": "3"}
185-
) as mock_obj:
179+
with mocked_server_response(status=429, headers={"Retry-After": "3"}) as mock_obj:
186180
with pytest.raises(RequestError) as cm:
187181
with self.connection(extra_params=retry_policy) as conn:
188182
pass
@@ -262,9 +256,7 @@ def test_retry_dangerous_codes(self):
262256
assert isinstance(cm.value.args[1], UnsafeToRetryError)
263257

264258
# Prove that these codes are retried if forced by the user
265-
with self.connection(
266-
extra_params={**self._retry_policy, **additional_settings}
267-
) as conn:
259+
with self.connection(extra_params={**self._retry_policy, **additional_settings}) as conn:
268260
with conn.cursor() as cursor:
269261
for dangerous_code in DANGEROUS_CODES:
270262
with mocked_server_response(status=dangerous_code):
@@ -334,9 +326,7 @@ def test_retry_abort_close_operation_on_404(self, caplog):
334326
curs.execute("SELECT 1")
335327
with mock_sequential_server_responses(responses):
336328
curs.close()
337-
assert (
338-
"Operation was canceled by a prior request" in caplog.text
339-
)
329+
assert "Operation was canceled by a prior request" in caplog.text
340330

341331
def test_retry_max_redirects_raises_too_many_redirects_exception(self):
342332
"""GIVEN the connector is configured with a custom max_redirects
@@ -347,9 +337,7 @@ def test_retry_max_redirects_raises_too_many_redirects_exception(self):
347337
max_redirects, expected_call_count = 1, 2
348338

349339
# Code 302 is a redirect
350-
with mocked_server_response(
351-
status=302, redirect_location="/foo.bar"
352-
) as mock_obj:
340+
with mocked_server_response(status=302, redirect_location="/foo.bar") as mock_obj:
353341
with pytest.raises(MaxRetryError) as cm:
354342
with self.connection(
355343
extra_params={
@@ -371,9 +359,7 @@ def test_retry_max_redirects_unset_doesnt_redirect_forever(self):
371359
_stop_after_attempts_count is enforced.
372360
"""
373361
# Code 302 is a redirect
374-
with mocked_server_response(
375-
status=302, redirect_location="/foo.bar/"
376-
) as mock_obj:
362+
with mocked_server_response(status=302, redirect_location="/foo.bar/") as mock_obj:
377363
with pytest.raises(MaxRetryError) as cm:
378364
with self.connection(
379365
extra_params={
@@ -399,9 +385,7 @@ def test_retry_max_redirects_is_bounded_by_stop_after_attempts_count(self):
399385

400386
with pytest.raises(RequestError) as cm:
401387
with mock_sequential_server_responses(responses):
402-
with self.connection(
403-
extra_params={**self._retry_policy, **additional_settings}
404-
):
388+
with self.connection(extra_params={**self._retry_policy, **additional_settings}):
405389
pass
406390

407391
# The error should be the result of the 500, not because of too many requests.
@@ -421,9 +405,5 @@ def test_retry_max_redirects_exceeds_max_attempts_count_warns_user(self, caplog)
421405
assert "it will have no affect!" in caplog.text
422406

423407
def test_retry_legacy_behavior_warns_user(self, caplog):
424-
with self.connection(
425-
extra_params={**self._retry_policy, "_enable_v3_retries": False}
426-
):
427-
assert (
428-
"Legacy retry behavior is enabled for this connection." in caplog.text
429-
)
408+
with self.connection(extra_params={**self._retry_policy, "_enable_v3_retries": False}):
409+
assert "Legacy retry behavior is enabled for this connection." in caplog.text

0 commit comments

Comments
 (0)