Skip to content

Commit

Permalink
Upgrade to aiohttp 3.10.6.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Sep 26, 2024
1 parent 3087686 commit 837dac0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

```
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 25 additions & 15 deletions test_opensearchpy/test_async/test_http_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@


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)
Expand All @@ -57,15 +78,10 @@ def auth_fn() -> None:
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"),
Expand All @@ -89,20 +105,14 @@ async def do_request(*args: Any, **kwargs: Any) -> Any:
)

@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 = {}
Expand Down

0 comments on commit 837dac0

Please sign in to comment.