-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix rest api aiohttp timeout * Added test cases for rest api timeout parameter * handled scenario when request_timeout is ClientTimeout object
- Loading branch information
1 parent
089f487
commit 6897114
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import asyncio | ||
import unittest | ||
from unittest.mock import AsyncMock | ||
import aiohttp | ||
from kubernetes_asyncio.client.rest import RESTClientObject | ||
from kubernetes_asyncio.client.configuration import Configuration | ||
class TestRESTClientObject(unittest.IsolatedAsyncioTestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.config = Configuration() | ||
|
||
|
||
async def test_rest_request_timeout(self): | ||
rest_api = RESTClientObject(configuration=self.config) | ||
for request_timeout, expected_timeout_arg in [ | ||
(None, aiohttp.ClientTimeout()), | ||
(5.0, aiohttp.ClientTimeout(total=5.0)), | ||
(3, aiohttp.ClientTimeout(total=3)), | ||
((5, 7), aiohttp.ClientTimeout(connect=5, sock_connect=5, sock_read=7)), | ||
(aiohttp.ClientTimeout(total=None), aiohttp.ClientTimeout(total=None)), | ||
]: | ||
with self.subTest(request_timeout=request_timeout, expected_timeout_arg=expected_timeout_arg): | ||
mock_request = AsyncMock() | ||
rest_api.pool_manager.request = mock_request | ||
await rest_api.request(method="GET", url="http://test-api", _preload_content=False, _request_timeout=request_timeout) | ||
mock_request.assert_called_once_with( | ||
method="GET", | ||
url="http://test-api", | ||
timeout=expected_timeout_arg, | ||
headers={"Content-Type": "application/json"} | ||
) |