Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to aiohttp 3.10.6. #829

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading