Skip to content

Commit 2e16afc

Browse files
committed
add test for timeout override
1 parent cff9506 commit 2e16afc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/src/test/python/test_restful.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ def mock_do_api_call(verb, uri, **kwargs):
131131
api_timeout=expected_api_timeout)
132132

133133

134+
def test_api_call_timeout_override(monkeypatch):
135+
"""
136+
Test that ApiCall object timeouts override timeouts passed as call_rest_api() arguments.
137+
"""
138+
expected_timeout = 42
139+
expected_api_timeout = 24
140+
141+
call = {"uri": "http://localhost:8080/source/api/v1/bar",
142+
"method": "POST", "data": "data",
143+
"api_timeout": expected_timeout,
144+
"async_api_timeout": expected_api_timeout}
145+
146+
def mock_do_api_call(verb, uri, **kwargs):
147+
assert kwargs['timeout'] == expected_timeout
148+
assert kwargs['api_timeout'] == expected_api_timeout
149+
150+
with monkeypatch.context() as m:
151+
m.setattr("opengrok_tools.utils.restful.do_api_call",
152+
mock_do_api_call)
153+
call_rest_api(ApiCall(call),
154+
timeout=expected_timeout + 1,
155+
api_timeout=expected_api_timeout + 1)
156+
157+
134158
def test_headers_timeout_requests():
135159
"""
136160
Test that headers and timeout parameters from do_call_api() are passed

0 commit comments

Comments
 (0)