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

Fix string/tuple/no auth on AsyncHttpConnection class #424

Merged
merged 14 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move AsyncContextManagerMock to utils package for future re-use
Signed-off-by: dannosaur <461956+dannosaur@users.noreply.github.com>
  • Loading branch information
dannosaur committed Jul 1, 2023
commit f6acb73780da887915c3e20cb1c55ccb7e970a0d
15 changes: 2 additions & 13 deletions test_opensearchpy/test_async_http_connection.py
dblock marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,12 @@
from unittest import IsolatedAsyncioTestCase

import pytest
from asynctest import CoroutineMock, MagicMock, patch
from asynctest import patch

from opensearchpy import AsyncHttpConnection
from opensearchpy._async._extra_imports import aiohttp
from opensearchpy._async.compat import get_running_loop


class AsyncContextManagerMock(MagicMock):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
type(self).__aenter__ = CoroutineMock(
return_value=MagicMock(
text=CoroutineMock(return_value='test'),
status=200,
)
)
type(self).__aexit__ = CoroutineMock(return_value=MagicMock())
from test_opensearchpy.utils import AsyncContextManagerMock


@pytest.mark.asyncio
Expand Down
14 changes: 14 additions & 0 deletions test_opensearchpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import time

from asynctest import CoroutineMock, MagicMock

from opensearchpy import OpenSearch


Expand Down Expand Up @@ -175,3 +177,15 @@ def wait_for_cluster_state_updates_to_finish(client, timeout=30):
while time.time() < end_time:
if not client.cluster.pending_tasks().get("tasks", ()):
break


class AsyncContextManagerMock(MagicMock):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
type(self).__aenter__ = CoroutineMock(
return_value=MagicMock(
text=CoroutineMock(return_value='test'),
status=200,
)
)
type(self).__aexit__ = CoroutineMock(return_value=MagicMock())