Skip to content

Commit f7842c1

Browse files
committed
refactor: streamline test_timeout_cloudantv1_sessionauth
1 parent 8e634ae commit f7842c1

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

test/integration/test_timeout.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ def get_authenticate_arguments(req):
8787

8888
@staticmethod
8989
def get_request_arguments(tci, srv, idx, call_count=None):
90+
"""
91+
Retrieve the arguments passed to a mocked HTTP request.
92+
93+
Parameters:
94+
tci (unittest.mock.Mock): A Mock object used for assertions.
95+
srv (Service): The instance of CloudantV1 service.
96+
idx (int): The index of the request in srv.http_client.request.mock_calls.
97+
call_count (int, optional): The total call count for the request. Defaults to None.
98+
99+
Returns:
100+
list: The arguments passed to the HTTP request at the specified index.
101+
102+
Raises:
103+
AssertionError: If the actual call count of the request does not match the provided or calculated call_count.
104+
"""
90105
call_count = idx + 1 if call_count is None else call_count
91106
tci.assertEqual(srv.http_client.request.call_count, call_count)
92107
return srv.http_client.request.mock_calls[idx]
@@ -146,23 +161,24 @@ def test_timeout_cloudantv1_sessionauth(self):
146161
# Mock out request response
147162
Helpers.mock_out_cloudant_request(my_service)
148163

149-
testcases = Helpers.defineTestCases(my_service)
164+
# Call the server
165+
my_service.get_server_information()
150166

151-
for tc_num, tc in enumerate(testcases):
152-
tc['set_timeout'](CUSTOM_TIMEOUT_CONFIG)
167+
# Assert timeout is set to the authenticator
168+
auth_args = Helpers.get_request_arguments(self, my_service.authenticator.token_manager, 0, call_count=2)
169+
self.assertEqual(auth_args.kwargs['timeout'], DEFAULT_TIMEOUT)
153170

154-
# Call the server
155-
my_service.get_server_information()
171+
# Assert timeout is set to the server request
172+
req_args = Helpers.get_request_arguments(self, my_service, 1, call_count=2)
173+
self.assertEqual(req_args.kwargs['timeout'], DEFAULT_TIMEOUT)
156174

157-
# first call is to a _session end-point, so we have an additional call on our mock request
158-
if tc_num == 0:
159-
# Assert timeout is set to the authenticator
160-
auth_args = Helpers.get_request_arguments(self, my_service.authenticator.token_manager, tc_num, tc_num+2)
161-
Helpers.assert_default_timeout_setting(self, auth_args)
175+
# Set a custom timeout and repeat the request. Client should be already authenticated.
176+
my_service.set_http_config(CUSTOM_TIMEOUT_CONFIG)
177+
my_service.get_server_information()
162178

163-
# Assert timeout is set in the server request
164-
req_args = Helpers.get_request_arguments(self, my_service, tc_num+1, tc_num+2)
165-
tc['assert_func'](self, req_args)
179+
# Assert the custom timeout is set to the server request
180+
req_args = Helpers.get_request_arguments(self, my_service, 2, call_count=3)
181+
self.assertEqual(req_args.kwargs['timeout'], CUSTOM_TIMEOUT)
166182

167183
def test_timeout_cloudantv1_iamauth(self):
168184
authenticator = IAMAuthenticator('apikey')

0 commit comments

Comments
 (0)