Skip to content

Commit

Permalink
Test also changing the max retry attemps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukant committed Oct 17, 2024
1 parent 207ffc4 commit 10003c3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/mocks/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
import requests
import responses

from kbcstorage.base import Endpoint
from kbcstorage.tables import Tables

from .table_responses import list_response


class NoRetriesEndpoint(Endpoint):
def __init__(self, root_url, token):
super().__init__(root_url, 'no-retries', token, max_requests_retries=0)

def list(self):
return self._get(self.base_url)


class TestRequestRetry(unittest.TestCase):
"""
Test that requests are retried.
Expand All @@ -20,6 +29,7 @@ def setUp(self):
token = 'dummy_token'
base_url = 'https://connection.keboola.com/'
self.tables = Tables(base_url, token)
self.no_retries = NoRetriesEndpoint(base_url, token)

@responses.activate
@patch('time.sleep', return_value=None)
Expand Down Expand Up @@ -84,3 +94,27 @@ def test_raises_error_on_4xx(self, sleep_mock):
)
with self.assertRaises(requests.exceptions.HTTPError):
self.tables.list()

@responses.activate
@patch('time.sleep', return_value=None)
def test_no_retries(self, sleep_mock):
"""
Request wont be retried for endpoints that configured it.
"""
responses.add(
responses.Response(
method='GET',
url='https://connection.keboola.com/v2/storage/no-retries',
json=list_response,
status=502
)
)
responses.add(
responses.Response(
method='GET',
url='https://connection.keboola.com/v2/storage/no-retries',
json=list_response,
)
)
with self.assertRaises(requests.exceptions.HTTPError):
self.no_retries.list()

0 comments on commit 10003c3

Please sign in to comment.