diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index ec7d220d..f544a520 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -45,6 +45,12 @@ docker run -d -p 9200:9200 -p 9600:9600 -e OPENSEARCH_INITIAL_ADMIN_PASSWORD=myS Tests require a live instance of OpenSearch running in docker. +Set the password for your docker instance. + +``` +export OPENSEARCH_PASSWORD=myStrongPassword123! +``` + If you have one running. ``` diff --git a/dev-requirements.txt b/dev-requirements.txt index 81a288f1..b1383be9 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -20,6 +20,6 @@ black>=24.3.0 twine # Requirements for testing [async] extra -aiohttp>=3.9.4, <=3.10.5 +aiohttp>=3.9.4, <4 pytest-asyncio<=0.24.0 unasync diff --git a/test_opensearchpy/test_async/test_http_connection.py b/test_opensearchpy/test_async/test_http_connection.py index fe60c977..34c729e0 100644 --- a/test_opensearchpy/test_async/test_http_connection.py +++ b/test_opensearchpy/test_async/test_http_connection.py @@ -37,6 +37,27 @@ from opensearchpy.connection.http_async import AsyncHttpConnection class TestAsyncHttpConnection: + class MockResponse: + + def __init__( + self, + text: Any = None, + status: int = 200, + headers: Any = CIMultiDict(), + ) -> None: + self._text = text + self.status = status + self.headers = headers + + async def text(self) -> Any: + return self._text + + async def __aexit__(self, *args: Any) -> None: + pass + + async def __aenter__(self) -> Any: + return self + def test_auth_as_tuple(self) -> None: c = AsyncHttpConnection(http_auth=("username", "password")) assert isinstance(c._http_auth, aiohttp.BasicAuth) @@ -57,15 +78,10 @@ class TestAsyncHttpConnection: assert callable(c._http_auth) @pytest.mark.asyncio # type: ignore - @mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock) + @mock.patch("aiohttp.ClientSession.request") async def test_basicauth_in_request_session(self, mock_request: Any) -> None: - async def do_request(*args: Any, **kwargs: Any) -> Any: - response_mock = mock.AsyncMock() - response_mock.headers = CIMultiDict() - response_mock.status = 200 - return response_mock - mock_request.return_value = aiohttp.client._RequestContextManager(do_request()) + mock_request.return_value = TestAsyncHttpConnection.MockResponse() c = AsyncHttpConnection( http_auth=("username", "password"), @@ -89,20 +105,14 @@ class TestAsyncHttpConnection: ) @pytest.mark.asyncio # type: ignore - @mock.patch("aiohttp.ClientSession.request", new_callable=mock.Mock) + @mock.patch("aiohttp.ClientSession.request") async def test_callable_in_request_session(self, mock_request: Any) -> None: def auth_fn(*args: Any, **kwargs: Any) -> Any: return { "Test": "PASSED", } - async def do_request(*args: Any, **kwargs: Any) -> Any: - response_mock = mock.AsyncMock() - response_mock.headers = CIMultiDict() - response_mock.status = 200 - return response_mock - - mock_request.return_value = aiohttp.client._RequestContextManager(do_request()) + mock_request.return_value = TestAsyncHttpConnection.MockResponse() c = AsyncHttpConnection(http_auth=auth_fn, loop=get_running_loop()) c.headers = {}