Expanded type coverage to benchmarks, samples and tests. (#566)
* Renamed json samples to fix duplicate module name. Signed-off-by: dblock <[email protected]> * Enabled mypy on all source files. Signed-off-by: dblock <[email protected]> * Added missing types. Signed-off-by: dblock <[email protected]> * Added CHANGELOG. Signed-off-by: dblock <[email protected]> * Move type: ignore to fix untyped decorator makes function untyped. Signed-off-by: dblock <[email protected]> * Fix nox -rs lint-3.7. Signed-off-by: dblock <[email protected]> * Fixed incorrect import. Signed-off-by: dblock <[email protected]> * Fix broken test. Signed-off-by: dblock <[email protected]> * Fixed TestBulk::test_bulk_works_with_bytestring_body. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]>
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from unittest import IsolatedAsyncioTestCase
|
||||
from unittest import IsolatedAsyncioTestCase # type: ignore
|
||||
|
||||
from opensearchpy._async.helpers.test import get_test_client
|
||||
from opensearchpy.connection.async_connections import add_connection
|
||||
@@ -34,7 +34,7 @@ from opensearchpy.connection.async_connections import add_connection
|
||||
from ...utils import wipe_cluster
|
||||
|
||||
|
||||
class AsyncOpenSearchTestCase(IsolatedAsyncioTestCase):
|
||||
class AsyncOpenSearchTestCase(IsolatedAsyncioTestCase): # type: ignore
|
||||
async def asyncSetUp(self) -> None:
|
||||
self.client = await get_test_client(
|
||||
verify_certs=False, http_auth=("admin", "admin")
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
@@ -39,15 +40,15 @@ from ...utils import wipe_cluster
|
||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def async_client():
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
async def async_client() -> Any:
|
||||
client = None
|
||||
try:
|
||||
if not hasattr(opensearchpy, "AsyncOpenSearch"):
|
||||
pytest.skip("test requires 'AsyncOpenSearch'")
|
||||
|
||||
kw = {"timeout": 3}
|
||||
client = opensearchpy.AsyncOpenSearch(OPENSEARCH_URL, **kw)
|
||||
client = opensearchpy.AsyncOpenSearch(OPENSEARCH_URL, **kw) # type: ignore
|
||||
|
||||
# wait for yellow status
|
||||
for _ in range(100):
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
|
||||
@@ -35,19 +37,19 @@ pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestUnicode:
|
||||
async def test_indices_analyze(self, async_client) -> None:
|
||||
async def test_indices_analyze(self, async_client: Any) -> None:
|
||||
await async_client.indices.analyze(body='{"text": "привет"}')
|
||||
|
||||
|
||||
class TestBulk:
|
||||
async def test_bulk_works_with_string_body(self, async_client) -> None:
|
||||
async def test_bulk_works_with_string_body(self, async_client: Any) -> None:
|
||||
docs = '{ "index" : { "_index" : "bulk_test_index", "_id" : "1" } }\n{"answer": 42}'
|
||||
response = await async_client.bulk(body=docs)
|
||||
|
||||
assert response["errors"] is False
|
||||
assert len(response["items"]) == 1
|
||||
|
||||
async def test_bulk_works_with_bytestring_body(self, async_client) -> None:
|
||||
async def test_bulk_works_with_bytestring_body(self, async_client: Any) -> None:
|
||||
docs = b'{ "index" : { "_index" : "bulk_test_index", "_id" : "2" } }\n{"answer": 42}'
|
||||
response = await async_client.bulk(body=docs)
|
||||
|
||||
@@ -57,7 +59,7 @@ class TestBulk:
|
||||
|
||||
class TestYarlMissing:
|
||||
async def test_aiohttp_connection_works_without_yarl(
|
||||
self, async_client, monkeypatch
|
||||
self, async_client: Any, monkeypatch: Any
|
||||
) -> None:
|
||||
# This is a defensive test case for if aiohttp suddenly stops using yarl.
|
||||
from opensearchpy._async import http_aiohttp
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from pytest import fixture
|
||||
@@ -34,32 +35,32 @@ from test_opensearchpy.test_async.test_server.test_helpers.test_document import
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
@fixture(scope="function")
|
||||
async def client():
|
||||
@fixture(scope="function") # type: ignore
|
||||
async def client() -> Any:
|
||||
client = await get_test_client(verify_certs=False, http_auth=("admin", "admin"))
|
||||
await add_connection("default", client)
|
||||
return client
|
||||
|
||||
|
||||
@fixture(scope="function")
|
||||
async def opensearch_version(client):
|
||||
@fixture(scope="function") # type: ignore
|
||||
async def opensearch_version(client: Any) -> Any:
|
||||
info = await client.info()
|
||||
print(info)
|
||||
yield tuple(
|
||||
int(x)
|
||||
for x in re.match(r"^([0-9.]+)", info["version"]["number"]).group(1).split(".")
|
||||
for x in re.match(r"^([0-9.]+)", info["version"]["number"]).group(1).split(".") # type: ignore
|
||||
)
|
||||
|
||||
|
||||
@fixture
|
||||
async def write_client(client):
|
||||
@fixture # type: ignore
|
||||
async def write_client(client: Any) -> Any:
|
||||
yield client
|
||||
await client.indices.delete("test-*", ignore=404)
|
||||
await client.indices.delete_template("test-template", ignore=404)
|
||||
|
||||
|
||||
@fixture
|
||||
async def data_client(client):
|
||||
@fixture # type: ignore
|
||||
async def data_client(client: Any) -> Any:
|
||||
# create mappings
|
||||
await create_git_index(client, "git")
|
||||
await create_flat_git_index(client, "flat-git")
|
||||
@@ -71,8 +72,8 @@ async def data_client(client):
|
||||
await client.indices.delete("flat-git", ignore=404)
|
||||
|
||||
|
||||
@fixture
|
||||
async def pull_request(write_client):
|
||||
@fixture # type: ignore
|
||||
async def pull_request(write_client: Any) -> Any:
|
||||
await PullRequest.init()
|
||||
pr = PullRequest(
|
||||
_id=42,
|
||||
@@ -95,8 +96,8 @@ async def pull_request(write_client):
|
||||
return pr
|
||||
|
||||
|
||||
@fixture
|
||||
async def setup_ubq_tests(client) -> str:
|
||||
@fixture # type: ignore
|
||||
async def setup_ubq_tests(client: Any) -> str:
|
||||
index = "test-git"
|
||||
await create_git_index(client, index)
|
||||
await async_bulk(client, TEST_GIT_DATA, raise_on_error=True, refresh=True)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
from typing import Tuple
|
||||
from typing import Any, List
|
||||
|
||||
import pytest
|
||||
from mock import MagicMock, patch
|
||||
@@ -40,19 +40,19 @@ pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class AsyncMock(MagicMock):
|
||||
async def __call__(self, *args, **kwargs):
|
||||
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
||||
return super(AsyncMock, self).__call__(*args, **kwargs)
|
||||
|
||||
def __await__(self):
|
||||
def __await__(self) -> Any:
|
||||
return self().__await__()
|
||||
|
||||
|
||||
class FailingBulkClient(object):
|
||||
def __init__(
|
||||
self,
|
||||
client,
|
||||
fail_at: Tuple[int] = (2,),
|
||||
fail_with=TransportError(599, "Error!", {}),
|
||||
client: Any,
|
||||
fail_at: Any = (2,),
|
||||
fail_with: TransportError = TransportError(599, "Error!", {}),
|
||||
) -> None:
|
||||
self.client = client
|
||||
self._called = 0
|
||||
@@ -60,7 +60,7 @@ class FailingBulkClient(object):
|
||||
self.transport = client.transport
|
||||
self._fail_with = fail_with
|
||||
|
||||
async def bulk(self, *args, **kwargs):
|
||||
async def bulk(self, *args: Any, **kwargs: Any) -> Any:
|
||||
self._called += 1
|
||||
if self._called in self._fail_at:
|
||||
raise self._fail_with
|
||||
@@ -68,7 +68,7 @@ class FailingBulkClient(object):
|
||||
|
||||
|
||||
class TestStreamingBulk(object):
|
||||
async def test_actions_remain_unchanged(self, async_client) -> None:
|
||||
async def test_actions_remain_unchanged(self, async_client: Any) -> None:
|
||||
actions1 = [{"_id": 1}, {"_id": 2}]
|
||||
async for ok, item in actions.async_streaming_bulk(
|
||||
async_client, actions1, index="test-index"
|
||||
@@ -76,7 +76,7 @@ class TestStreamingBulk(object):
|
||||
assert ok
|
||||
assert [{"_id": 1}, {"_id": 2}] == actions1
|
||||
|
||||
async def test_all_documents_get_inserted(self, async_client) -> None:
|
||||
async def test_all_documents_get_inserted(self, async_client: Any) -> None:
|
||||
docs = [{"answer": x, "_id": x} for x in range(100)]
|
||||
async for ok, item in actions.async_streaming_bulk(
|
||||
async_client, docs, index="test-index", refresh=True
|
||||
@@ -88,13 +88,13 @@ class TestStreamingBulk(object):
|
||||
"_source"
|
||||
]
|
||||
|
||||
async def test_documents_data_types(self, async_client):
|
||||
async def async_gen():
|
||||
async def test_documents_data_types(self, async_client: Any) -> None:
|
||||
async def async_gen() -> Any:
|
||||
for x in range(100):
|
||||
await asyncio.sleep(0)
|
||||
yield {"answer": x, "_id": x}
|
||||
|
||||
def sync_gen():
|
||||
def sync_gen() -> Any:
|
||||
for x in range(100):
|
||||
yield {"answer": x, "_id": x}
|
||||
|
||||
@@ -123,7 +123,7 @@ class TestStreamingBulk(object):
|
||||
]
|
||||
|
||||
async def test_all_errors_from_chunk_are_raised_on_failure(
|
||||
self, async_client
|
||||
self, async_client: Any
|
||||
) -> None:
|
||||
await async_client.indices.create(
|
||||
"i",
|
||||
@@ -144,7 +144,7 @@ class TestStreamingBulk(object):
|
||||
else:
|
||||
assert False, "exception should have been raised"
|
||||
|
||||
async def test_different_op_types(self, async_client):
|
||||
async def test_different_op_types(self, async_client: Any) -> None:
|
||||
await async_client.index(index="i", id=45, body={})
|
||||
await async_client.index(index="i", id=42, body={})
|
||||
docs = [
|
||||
@@ -159,7 +159,7 @@ class TestStreamingBulk(object):
|
||||
assert {"answer": 42} == (await async_client.get(index="i", id=42))["_source"]
|
||||
assert {"f": "v"} == (await async_client.get(index="i", id=47))["_source"]
|
||||
|
||||
async def test_transport_error_can_becaught(self, async_client):
|
||||
async def test_transport_error_can_becaught(self, async_client: Any) -> None:
|
||||
failing_client = FailingBulkClient(async_client)
|
||||
docs = [
|
||||
{"_index": "i", "_id": 47, "f": "v"},
|
||||
@@ -193,7 +193,7 @@ class TestStreamingBulk(object):
|
||||
}
|
||||
} == results[1][1]
|
||||
|
||||
async def test_rejected_documents_are_retried(self, async_client) -> None:
|
||||
async def test_rejected_documents_are_retried(self, async_client: Any) -> None:
|
||||
failing_client = FailingBulkClient(
|
||||
async_client, fail_with=TransportError(429, "Rejected!", {})
|
||||
)
|
||||
@@ -222,7 +222,7 @@ class TestStreamingBulk(object):
|
||||
assert 4 == failing_client._called
|
||||
|
||||
async def test_rejected_documents_are_retried_at_most_max_retries_times(
|
||||
self, async_client
|
||||
self, async_client: Any
|
||||
) -> None:
|
||||
failing_client = FailingBulkClient(
|
||||
async_client, fail_at=(1, 2), fail_with=TransportError(429, "Rejected!", {})
|
||||
@@ -253,7 +253,7 @@ class TestStreamingBulk(object):
|
||||
assert 4 == failing_client._called
|
||||
|
||||
async def test_transport_error_is_raised_with_max_retries(
|
||||
self, async_client
|
||||
self, async_client: Any
|
||||
) -> None:
|
||||
failing_client = FailingBulkClient(
|
||||
async_client,
|
||||
@@ -261,7 +261,7 @@ class TestStreamingBulk(object):
|
||||
fail_with=TransportError(429, "Rejected!", {}),
|
||||
)
|
||||
|
||||
async def streaming_bulk():
|
||||
async def streaming_bulk() -> Any:
|
||||
results = [
|
||||
x
|
||||
async for x in actions.async_streaming_bulk(
|
||||
@@ -280,7 +280,7 @@ class TestStreamingBulk(object):
|
||||
|
||||
|
||||
class TestBulk(object):
|
||||
async def test_bulk_works_with_single_item(self, async_client) -> None:
|
||||
async def test_bulk_works_with_single_item(self, async_client: Any) -> None:
|
||||
docs = [{"answer": 42, "_id": 1}]
|
||||
success, failed = await actions.async_bulk(
|
||||
async_client, docs, index="test-index", refresh=True
|
||||
@@ -293,7 +293,7 @@ class TestBulk(object):
|
||||
"_source"
|
||||
]
|
||||
|
||||
async def test_all_documents_get_inserted(self, async_client) -> None:
|
||||
async def test_all_documents_get_inserted(self, async_client: Any) -> None:
|
||||
docs = [{"answer": x, "_id": x} for x in range(100)]
|
||||
success, failed = await actions.async_bulk(
|
||||
async_client, docs, index="test-index", refresh=True
|
||||
@@ -306,7 +306,7 @@ class TestBulk(object):
|
||||
"_source"
|
||||
]
|
||||
|
||||
async def test_stats_only_reports_numbers(self, async_client) -> None:
|
||||
async def test_stats_only_reports_numbers(self, async_client: Any) -> None:
|
||||
docs = [{"answer": x} for x in range(100)]
|
||||
success, failed = await actions.async_bulk(
|
||||
async_client, docs, index="test-index", refresh=True, stats_only=True
|
||||
@@ -316,7 +316,7 @@ class TestBulk(object):
|
||||
assert 0 == failed
|
||||
assert 100 == (await async_client.count(index="test-index"))["count"]
|
||||
|
||||
async def test_errors_are_reported_correctly(self, async_client):
|
||||
async def test_errors_are_reported_correctly(self, async_client: Any) -> None:
|
||||
await async_client.indices.create(
|
||||
"i",
|
||||
{
|
||||
@@ -333,6 +333,7 @@ class TestBulk(object):
|
||||
raise_on_error=False,
|
||||
)
|
||||
assert 1 == success
|
||||
assert isinstance(failed, List)
|
||||
assert 1 == len(failed)
|
||||
error = failed[0]
|
||||
assert "42" == error["index"]["_id"]
|
||||
@@ -342,7 +343,7 @@ class TestBulk(object):
|
||||
error["index"]["error"]
|
||||
) or "mapper_parsing_exception" in repr(error["index"]["error"])
|
||||
|
||||
async def test_error_is_raised(self, async_client):
|
||||
async def test_error_is_raised(self, async_client: Any) -> None:
|
||||
await async_client.indices.create(
|
||||
"i",
|
||||
{
|
||||
@@ -355,7 +356,7 @@ class TestBulk(object):
|
||||
with pytest.raises(BulkIndexError):
|
||||
await actions.async_bulk(async_client, [{"a": 42}, {"a": "c"}], index="i")
|
||||
|
||||
async def test_ignore_error_if_raised(self, async_client):
|
||||
async def test_ignore_error_if_raised(self, async_client: Any) -> None:
|
||||
# ignore the status code 400 in tuple
|
||||
await actions.async_bulk(
|
||||
async_client, [{"a": 42}, {"a": "c"}], index="i", ignore_status=(400,)
|
||||
@@ -388,7 +389,7 @@ class TestBulk(object):
|
||||
failing_client, [{"a": 42}], index="i", ignore_status=(599,)
|
||||
)
|
||||
|
||||
async def test_errors_are_collected_properly(self, async_client):
|
||||
async def test_errors_are_collected_properly(self, async_client: Any) -> None:
|
||||
await async_client.indices.create(
|
||||
"i",
|
||||
{
|
||||
@@ -410,10 +411,12 @@ class TestBulk(object):
|
||||
|
||||
|
||||
class MockScroll:
|
||||
calls: Any
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.calls = []
|
||||
|
||||
async def __call__(self, *args, **kwargs):
|
||||
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
||||
self.calls.append((args, kwargs))
|
||||
if len(self.calls) == 1:
|
||||
return {
|
||||
@@ -432,25 +435,27 @@ class MockScroll:
|
||||
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, resp) -> None:
|
||||
def __init__(self, resp: Any) -> None:
|
||||
self.resp = resp
|
||||
|
||||
async def __call__(self, *args, **kwargs):
|
||||
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
||||
return self.resp
|
||||
|
||||
def __await__(self):
|
||||
def __await__(self) -> Any:
|
||||
return self().__await__()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def scan_teardown(async_client):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
async def scan_teardown(async_client: Any) -> Any:
|
||||
yield
|
||||
await async_client.clear_scroll(scroll_id="_all")
|
||||
|
||||
|
||||
class TestScan(object):
|
||||
async def test_order_can_be_preserved(self, async_client, scan_teardown):
|
||||
bulk = []
|
||||
async def test_order_can_be_preserved(
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
bulk: Any = []
|
||||
for x in range(100):
|
||||
bulk.append({"index": {"_index": "test_index", "_id": x}})
|
||||
bulk.append({"answer": x, "correct": x == 42})
|
||||
@@ -470,8 +475,10 @@ class TestScan(object):
|
||||
assert list(map(str, range(100))) == list(d["_id"] for d in docs)
|
||||
assert list(range(100)) == list(d["_source"]["answer"] for d in docs)
|
||||
|
||||
async def test_all_documents_are_read(self, async_client, scan_teardown):
|
||||
bulk = []
|
||||
async def test_all_documents_are_read(
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
bulk: Any = []
|
||||
for x in range(100):
|
||||
bulk.append({"index": {"_index": "test_index", "_id": x}})
|
||||
bulk.append({"answer": x, "correct": x == 42})
|
||||
@@ -486,8 +493,8 @@ class TestScan(object):
|
||||
assert set(map(str, range(100))) == set(d["_id"] for d in docs)
|
||||
assert set(range(100)) == set(d["_source"]["answer"] for d in docs)
|
||||
|
||||
async def test_scroll_error(self, async_client, scan_teardown):
|
||||
bulk = []
|
||||
async def test_scroll_error(self, async_client: Any, scan_teardown: Any) -> None:
|
||||
bulk: Any = []
|
||||
for x in range(4):
|
||||
bulk.append({"index": {"_index": "test_index"}})
|
||||
bulk.append({"value": x})
|
||||
@@ -522,7 +529,9 @@ class TestScan(object):
|
||||
assert len(data) == 3
|
||||
assert data[-1] == {"scroll_data": 42}
|
||||
|
||||
async def test_initial_search_error(self, async_client, scan_teardown):
|
||||
async def test_initial_search_error(
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
with patch.object(async_client, "clear_scroll", new_callable=AsyncMock):
|
||||
with patch.object(
|
||||
async_client,
|
||||
@@ -572,7 +581,9 @@ class TestScan(object):
|
||||
assert data == [{"search_data": 1}]
|
||||
assert mock_scroll.calls == []
|
||||
|
||||
async def test_no_scroll_id_fast_route(self, async_client, scan_teardown) -> None:
|
||||
async def test_no_scroll_id_fast_route(
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
with patch.object(async_client, "search", MockResponse({"no": "_scroll_id"})):
|
||||
with patch.object(async_client, "scroll") as scroll_mock:
|
||||
with patch.object(async_client, "clear_scroll") as clear_mock:
|
||||
@@ -588,8 +599,10 @@ class TestScan(object):
|
||||
clear_mock.assert_not_called()
|
||||
|
||||
@patch("opensearchpy._async.helpers.actions.logger")
|
||||
async def test_logger(self, logger_mock, async_client, scan_teardown):
|
||||
bulk = []
|
||||
async def test_logger(
|
||||
self, logger_mock: Any, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
bulk: Any = []
|
||||
for x in range(4):
|
||||
bulk.append({"index": {"_index": "test_index"}})
|
||||
bulk.append({"value": x})
|
||||
@@ -629,8 +642,8 @@ class TestScan(object):
|
||||
5,
|
||||
)
|
||||
|
||||
async def test_clear_scroll(self, async_client, scan_teardown):
|
||||
bulk = []
|
||||
async def test_clear_scroll(self, async_client: Any, scan_teardown: Any) -> None:
|
||||
bulk: Any = []
|
||||
for x in range(4):
|
||||
bulk.append({"index": {"_index": "test_index"}})
|
||||
bulk.append({"value": x})
|
||||
@@ -665,7 +678,7 @@ class TestScan(object):
|
||||
]
|
||||
spy.assert_not_called()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@pytest.mark.parametrize( # type: ignore
|
||||
"kwargs",
|
||||
[
|
||||
{"api_key": ("name", "value")},
|
||||
@@ -674,8 +687,8 @@ class TestScan(object):
|
||||
],
|
||||
)
|
||||
async def test_scan_auth_kwargs_forwarded(
|
||||
self, async_client, scan_teardown, kwargs
|
||||
):
|
||||
self, async_client: Any, scan_teardown: Any, kwargs: Any
|
||||
) -> None:
|
||||
((key, val),) = kwargs.items()
|
||||
|
||||
with patch.object(
|
||||
@@ -716,8 +729,8 @@ class TestScan(object):
|
||||
assert api_mock.call_args[1][key] == val
|
||||
|
||||
async def test_scan_auth_kwargs_favor_scroll_kwargs_option(
|
||||
self, async_client, scan_teardown
|
||||
):
|
||||
self, async_client: Any, scan_teardown: Any
|
||||
) -> None:
|
||||
with patch.object(
|
||||
async_client,
|
||||
"search",
|
||||
@@ -765,9 +778,9 @@ class TestScan(object):
|
||||
assert async_client.scroll.call_args[1]["sort"] == "asc"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def reindex_setup(async_client):
|
||||
bulk = []
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
async def reindex_setup(async_client: Any) -> Any:
|
||||
bulk: Any = []
|
||||
for x in range(100):
|
||||
bulk.append({"index": {"_index": "test_index", "_id": x}})
|
||||
bulk.append(
|
||||
@@ -783,7 +796,7 @@ async def reindex_setup(async_client):
|
||||
|
||||
class TestReindex(object):
|
||||
async def test_reindex_passes_kwargs_to_scan_and_bulk(
|
||||
self, async_client, reindex_setup
|
||||
self, async_client: Any, reindex_setup: Any
|
||||
) -> None:
|
||||
await actions.async_reindex(
|
||||
async_client,
|
||||
@@ -803,7 +816,9 @@ class TestReindex(object):
|
||||
await async_client.get(index="prod_index", id=42)
|
||||
)["_source"]
|
||||
|
||||
async def test_reindex_accepts_a_query(self, async_client, reindex_setup) -> None:
|
||||
async def test_reindex_accepts_a_query(
|
||||
self, async_client: Any, reindex_setup: Any
|
||||
) -> None:
|
||||
await actions.async_reindex(
|
||||
async_client,
|
||||
"test_index",
|
||||
@@ -822,7 +837,9 @@ class TestReindex(object):
|
||||
await async_client.get(index="prod_index", id=42)
|
||||
)["_source"]
|
||||
|
||||
async def test_all_documents_get_moved(self, async_client, reindex_setup) -> None:
|
||||
async def test_all_documents_get_moved(
|
||||
self, async_client: Any, reindex_setup: Any
|
||||
) -> None:
|
||||
await actions.async_reindex(async_client, "test_index", "prod_index")
|
||||
await async_client.indices.refresh()
|
||||
|
||||
@@ -843,8 +860,8 @@ class TestReindex(object):
|
||||
)["_source"]
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def parent_reindex_setup(async_client):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
async def parent_reindex_setup(async_client: Any) -> None:
|
||||
body = {
|
||||
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
|
||||
"mappings": {
|
||||
@@ -873,8 +890,8 @@ async def parent_reindex_setup(async_client):
|
||||
|
||||
class TestParentChildReindex:
|
||||
async def test_children_are_reindexed_correctly(
|
||||
self, async_client, parent_reindex_setup
|
||||
):
|
||||
self, async_client: Any, parent_reindex_setup: Any
|
||||
) -> None:
|
||||
await actions.async_reindex(async_client, "test-index", "real-index")
|
||||
assert {"question_answer": "question"} == (
|
||||
await async_client.get(index="real-index", id=42)
|
||||
|
||||
@@ -13,7 +13,7 @@ from __future__ import unicode_literals
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
async def create_flat_git_index(client, index):
|
||||
async def create_flat_git_index(client: Any, index: Any) -> None:
|
||||
# we will use user on several places
|
||||
user_mapping = {
|
||||
"properties": {"name": {"type": "text", "fields": {"raw": {"type": "keyword"}}}}
|
||||
@@ -56,7 +56,7 @@ async def create_flat_git_index(client, index):
|
||||
)
|
||||
|
||||
|
||||
async def create_git_index(client, index):
|
||||
async def create_git_index(client: Any, index: Any) -> None:
|
||||
# we will use user on several places
|
||||
user_mapping = {
|
||||
"properties": {"name": {"type": "text", "fields": {"raw": {"type": "keyword"}}}}
|
||||
@@ -1078,7 +1078,7 @@ DATA = [
|
||||
]
|
||||
|
||||
|
||||
def flatten_doc(d) -> Dict[str, Any]:
|
||||
def flatten_doc(d: Any) -> Dict[str, Any]:
|
||||
src = d["_source"].copy()
|
||||
del src["commit_repo"]
|
||||
return {"_index": "flat-git", "_id": d["_id"], "_source": src}
|
||||
@@ -1087,7 +1087,7 @@ def flatten_doc(d) -> Dict[str, Any]:
|
||||
FLAT_DATA = [flatten_doc(d) for d in DATA if "routing" in d]
|
||||
|
||||
|
||||
def create_test_git_data(d) -> Dict[str, Any]:
|
||||
def create_test_git_data(d: Any) -> Dict[str, Any]:
|
||||
src = d["_source"].copy()
|
||||
return {
|
||||
"_index": "test-git",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
from ipaddress import ip_address
|
||||
from typing import Any, Optional
|
||||
|
||||
import pytest
|
||||
from pytest import raises
|
||||
@@ -63,7 +64,7 @@ class Repository(AsyncDocument):
|
||||
tags = Keyword()
|
||||
|
||||
@classmethod
|
||||
def search(cls):
|
||||
def search(cls, using: Any = None, index: Optional[str] = None) -> Any:
|
||||
return super(Repository, cls).search().filter("term", commit_repo="repo")
|
||||
|
||||
class Index:
|
||||
@@ -116,7 +117,7 @@ class SerializationDoc(AsyncDocument):
|
||||
name = "test-serialization"
|
||||
|
||||
|
||||
async def test_serialization(write_client):
|
||||
async def test_serialization(write_client: Any) -> None:
|
||||
await SerializationDoc.init()
|
||||
await write_client.index(
|
||||
index="test-serialization",
|
||||
@@ -129,7 +130,7 @@ async def test_serialization(write_client):
|
||||
"ip": ["::1", "127.0.0.1", None],
|
||||
},
|
||||
)
|
||||
sd = await SerializationDoc.get(id=42)
|
||||
sd: Any = await SerializationDoc.get(id=42)
|
||||
|
||||
assert sd.i == [1, 2, 3, None]
|
||||
assert sd.b == [True, False, True, False, None]
|
||||
@@ -146,7 +147,7 @@ async def test_serialization(write_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_nested_inner_hits_are_wrapped_properly(pull_request) -> None:
|
||||
async def test_nested_inner_hits_are_wrapped_properly(pull_request: Any) -> None:
|
||||
history_query = Q(
|
||||
"nested",
|
||||
path="comments.history",
|
||||
@@ -174,7 +175,7 @@ async def test_nested_inner_hits_are_wrapped_properly(pull_request) -> None:
|
||||
assert "score" in history.meta
|
||||
|
||||
|
||||
async def test_nested_inner_hits_are_deserialized_properly(pull_request) -> None:
|
||||
async def test_nested_inner_hits_are_deserialized_properly(pull_request: Any) -> None:
|
||||
s = PullRequest.search().query(
|
||||
"nested",
|
||||
inner_hits={},
|
||||
@@ -189,7 +190,7 @@ async def test_nested_inner_hits_are_deserialized_properly(pull_request) -> None
|
||||
assert isinstance(pr.comments[0].created_at, datetime)
|
||||
|
||||
|
||||
async def test_nested_top_hits_are_wrapped_properly(pull_request) -> None:
|
||||
async def test_nested_top_hits_are_wrapped_properly(pull_request: Any) -> None:
|
||||
s = PullRequest.search()
|
||||
s.aggs.bucket("comments", "nested", path="comments").metric(
|
||||
"hits", "top_hits", size=1
|
||||
@@ -201,7 +202,7 @@ async def test_nested_top_hits_are_wrapped_properly(pull_request) -> None:
|
||||
assert isinstance(r.aggregations.comments.hits.hits[0], Comment)
|
||||
|
||||
|
||||
async def test_update_object_field(write_client) -> None:
|
||||
async def test_update_object_field(write_client: Any) -> None:
|
||||
await Wiki.init()
|
||||
w = Wiki(
|
||||
owner=User(name="Honza Kral"),
|
||||
@@ -221,7 +222,7 @@ async def test_update_object_field(write_client) -> None:
|
||||
assert w.ranked == {"test1": 0.1, "topic2": 0.2}
|
||||
|
||||
|
||||
async def test_update_script(write_client) -> None:
|
||||
async def test_update_script(write_client: Any) -> None:
|
||||
await Wiki.init()
|
||||
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
|
||||
await w.save()
|
||||
@@ -231,7 +232,7 @@ async def test_update_script(write_client) -> None:
|
||||
assert w.views == 47
|
||||
|
||||
|
||||
async def test_update_retry_on_conflict(write_client) -> None:
|
||||
async def test_update_retry_on_conflict(write_client: Any) -> None:
|
||||
await Wiki.init()
|
||||
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
|
||||
await w.save()
|
||||
@@ -249,8 +250,10 @@ async def test_update_retry_on_conflict(write_client) -> None:
|
||||
assert w.views == 52
|
||||
|
||||
|
||||
@pytest.mark.parametrize("retry_on_conflict", [None, 0])
|
||||
async def test_update_conflicting_version(write_client, retry_on_conflict) -> None:
|
||||
@pytest.mark.parametrize("retry_on_conflict", [None, 0]) # type: ignore
|
||||
async def test_update_conflicting_version(
|
||||
write_client: Any, retry_on_conflict: bool
|
||||
) -> None:
|
||||
await Wiki.init()
|
||||
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
|
||||
await w.save()
|
||||
@@ -267,7 +270,7 @@ async def test_update_conflicting_version(write_client, retry_on_conflict) -> No
|
||||
)
|
||||
|
||||
|
||||
async def test_save_and_update_return_doc_meta(write_client) -> None:
|
||||
async def test_save_and_update_return_doc_meta(write_client: Any) -> None:
|
||||
await Wiki.init()
|
||||
w = Wiki(owner=User(name="Honza Kral"), _id="opensearch-py", views=42)
|
||||
resp = await w.save(return_doc_meta=True)
|
||||
@@ -291,33 +294,33 @@ async def test_save_and_update_return_doc_meta(write_client) -> None:
|
||||
assert resp.keys().__contains__("_version")
|
||||
|
||||
|
||||
async def test_init(write_client) -> None:
|
||||
async def test_init(write_client: Any) -> None:
|
||||
await Repository.init(index="test-git")
|
||||
|
||||
assert await write_client.indices.exists(index="test-git")
|
||||
|
||||
|
||||
async def test_get_raises_404_on_index_missing(data_client) -> None:
|
||||
async def test_get_raises_404_on_index_missing(data_client: Any) -> None:
|
||||
with raises(NotFoundError):
|
||||
await Repository.get("opensearch-dsl-php", index="not-there")
|
||||
|
||||
|
||||
async def test_get_raises_404_on_non_existent_id(data_client) -> None:
|
||||
async def test_get_raises_404_on_non_existent_id(data_client: Any) -> None:
|
||||
with raises(NotFoundError):
|
||||
await Repository.get("opensearch-dsl-php")
|
||||
|
||||
|
||||
async def test_get_returns_none_if_404_ignored(data_client) -> None:
|
||||
async def test_get_returns_none_if_404_ignored(data_client: Any) -> None:
|
||||
assert None is await Repository.get("opensearch-dsl-php", ignore=404)
|
||||
|
||||
|
||||
async def test_get_returns_none_if_404_ignored_and_index_doesnt_exist(
|
||||
data_client,
|
||||
data_client: Any,
|
||||
) -> None:
|
||||
assert None is await Repository.get("42", index="not-there", ignore=404)
|
||||
|
||||
|
||||
async def test_get(data_client) -> None:
|
||||
async def test_get(data_client: Any) -> None:
|
||||
opensearch_repo = await Repository.get("opensearch-py")
|
||||
|
||||
assert isinstance(opensearch_repo, Repository)
|
||||
@@ -325,15 +328,15 @@ async def test_get(data_client) -> None:
|
||||
assert datetime(2014, 3, 3) == opensearch_repo.created_at
|
||||
|
||||
|
||||
async def test_exists_return_true(data_client) -> None:
|
||||
async def test_exists_return_true(data_client: Any) -> None:
|
||||
assert await Repository.exists("opensearch-py")
|
||||
|
||||
|
||||
async def test_exists_false(data_client) -> None:
|
||||
async def test_exists_false(data_client: Any) -> None:
|
||||
assert not await Repository.exists("opensearch-dsl-php")
|
||||
|
||||
|
||||
async def test_get_with_tz_date(data_client) -> None:
|
||||
async def test_get_with_tz_date(data_client: Any) -> None:
|
||||
first_commit = await Commit.get(
|
||||
id="3ca6e1e73a071a705b4babd2f581c91a2a3e5037", routing="opensearch-py"
|
||||
)
|
||||
@@ -345,7 +348,7 @@ async def test_get_with_tz_date(data_client) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_save_with_tz_date(data_client) -> None:
|
||||
async def test_save_with_tz_date(data_client: Any) -> None:
|
||||
tzinfo = timezone("Europe/Prague")
|
||||
first_commit = await Commit.get(
|
||||
id="3ca6e1e73a071a705b4babd2f581c91a2a3e5037", routing="opensearch-py"
|
||||
@@ -372,7 +375,7 @@ COMMIT_DOCS_WITH_MISSING = [
|
||||
]
|
||||
|
||||
|
||||
async def test_mget(data_client) -> None:
|
||||
async def test_mget(data_client: Any) -> None:
|
||||
commits = await Commit.mget(COMMIT_DOCS_WITH_MISSING)
|
||||
assert commits[0] is None
|
||||
assert commits[1].meta.id == "3ca6e1e73a071a705b4babd2f581c91a2a3e5037"
|
||||
@@ -380,25 +383,27 @@ async def test_mget(data_client) -> None:
|
||||
assert commits[3].meta.id == "eb3e543323f189fd7b698e66295427204fff5755"
|
||||
|
||||
|
||||
async def test_mget_raises_exception_when_missing_param_is_invalid(data_client) -> None:
|
||||
async def test_mget_raises_exception_when_missing_param_is_invalid(
|
||||
data_client: Any,
|
||||
) -> None:
|
||||
with raises(ValueError):
|
||||
await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="raj")
|
||||
|
||||
|
||||
async def test_mget_raises_404_when_missing_param_is_raise(data_client) -> None:
|
||||
async def test_mget_raises_404_when_missing_param_is_raise(data_client: Any) -> None:
|
||||
with raises(NotFoundError):
|
||||
await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="raise")
|
||||
|
||||
|
||||
async def test_mget_ignores_missing_docs_when_missing_param_is_skip(
|
||||
data_client,
|
||||
data_client: Any,
|
||||
) -> None:
|
||||
commits = await Commit.mget(COMMIT_DOCS_WITH_MISSING, missing="skip")
|
||||
assert commits[0].meta.id == "3ca6e1e73a071a705b4babd2f581c91a2a3e5037"
|
||||
assert commits[1].meta.id == "eb3e543323f189fd7b698e66295427204fff5755"
|
||||
|
||||
|
||||
async def test_update_works_from_search_response(data_client) -> None:
|
||||
async def test_update_works_from_search_response(data_client: Any) -> None:
|
||||
opensearch_repo = (await Repository.search().execute())[0]
|
||||
|
||||
await opensearch_repo.update(owner={"other_name": "opensearchpy"})
|
||||
@@ -409,7 +414,7 @@ async def test_update_works_from_search_response(data_client) -> None:
|
||||
assert "opensearch" == new_version.owner.name
|
||||
|
||||
|
||||
async def test_update(data_client) -> None:
|
||||
async def test_update(data_client: Any) -> None:
|
||||
opensearch_repo = await Repository.get("opensearch-py")
|
||||
v = opensearch_repo.meta.version
|
||||
|
||||
@@ -433,7 +438,7 @@ async def test_update(data_client) -> None:
|
||||
assert "primary_term" in new_version.meta
|
||||
|
||||
|
||||
async def test_save_updates_existing_doc(data_client) -> None:
|
||||
async def test_save_updates_existing_doc(data_client: Any) -> None:
|
||||
opensearch_repo = await Repository.get("opensearch-py")
|
||||
|
||||
opensearch_repo.new_field = "testing-save"
|
||||
@@ -446,7 +451,9 @@ async def test_save_updates_existing_doc(data_client) -> None:
|
||||
assert new_repo["_seq_no"] == opensearch_repo.meta.seq_no
|
||||
|
||||
|
||||
async def test_save_automatically_uses_seq_no_and_primary_term(data_client) -> None:
|
||||
async def test_save_automatically_uses_seq_no_and_primary_term(
|
||||
data_client: Any,
|
||||
) -> None:
|
||||
opensearch_repo = await Repository.get("opensearch-py")
|
||||
opensearch_repo.meta.seq_no += 1
|
||||
|
||||
@@ -454,7 +461,9 @@ async def test_save_automatically_uses_seq_no_and_primary_term(data_client) -> N
|
||||
await opensearch_repo.save()
|
||||
|
||||
|
||||
async def test_delete_automatically_uses_seq_no_and_primary_term(data_client) -> None:
|
||||
async def test_delete_automatically_uses_seq_no_and_primary_term(
|
||||
data_client: Any,
|
||||
) -> None:
|
||||
opensearch_repo = await Repository.get("opensearch-py")
|
||||
opensearch_repo.meta.seq_no += 1
|
||||
|
||||
@@ -462,13 +471,13 @@ async def test_delete_automatically_uses_seq_no_and_primary_term(data_client) ->
|
||||
await opensearch_repo.delete()
|
||||
|
||||
|
||||
async def assert_doc_equals(expected, actual) -> None:
|
||||
async def assert_doc_equals(expected: Any, actual: Any) -> None:
|
||||
async for f in aiter(expected):
|
||||
assert f in actual
|
||||
assert actual[f] == expected[f]
|
||||
|
||||
|
||||
async def test_can_save_to_different_index(write_client):
|
||||
async def test_can_save_to_different_index(write_client: Any) -> None:
|
||||
test_repo = Repository(description="testing", meta={"id": 42})
|
||||
assert await test_repo.save(index="test-document")
|
||||
|
||||
@@ -483,7 +492,9 @@ async def test_can_save_to_different_index(write_client):
|
||||
)
|
||||
|
||||
|
||||
async def test_save_without_skip_empty_will_include_empty_fields(write_client) -> None:
|
||||
async def test_save_without_skip_empty_will_include_empty_fields(
|
||||
write_client: Any,
|
||||
) -> None:
|
||||
test_repo = Repository(field_1=[], field_2=None, field_3={}, meta={"id": 42})
|
||||
assert await test_repo.save(index="test-document", skip_empty=False)
|
||||
|
||||
@@ -498,7 +509,7 @@ async def test_save_without_skip_empty_will_include_empty_fields(write_client) -
|
||||
)
|
||||
|
||||
|
||||
async def test_delete(write_client) -> None:
|
||||
async def test_delete(write_client: Any) -> None:
|
||||
await write_client.create(
|
||||
index="test-document",
|
||||
id="opensearch-py",
|
||||
@@ -519,11 +530,11 @@ async def test_delete(write_client) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_search(data_client) -> None:
|
||||
async def test_search(data_client: Any) -> None:
|
||||
assert await Repository.search().count() == 1
|
||||
|
||||
|
||||
async def test_search_returns_proper_doc_classes(data_client) -> None:
|
||||
async def test_search_returns_proper_doc_classes(data_client: Any) -> None:
|
||||
result = await Repository.search().execute()
|
||||
|
||||
opensearch_repo = result.hits[0]
|
||||
@@ -532,8 +543,10 @@ async def test_search_returns_proper_doc_classes(data_client) -> None:
|
||||
assert opensearch_repo.owner.name == "opensearch"
|
||||
|
||||
|
||||
async def test_refresh_mapping(data_client) -> None:
|
||||
async def test_refresh_mapping(data_client: Any) -> None:
|
||||
class Commit(AsyncDocument):
|
||||
_index: Any
|
||||
|
||||
class Index:
|
||||
name = "git"
|
||||
|
||||
@@ -546,7 +559,7 @@ async def test_refresh_mapping(data_client) -> None:
|
||||
assert isinstance(Commit._index._mapping["committed_date"], Date)
|
||||
|
||||
|
||||
async def test_highlight_in_meta(data_client) -> None:
|
||||
async def test_highlight_in_meta(data_client: Any) -> None:
|
||||
commit = (
|
||||
await Commit.search()
|
||||
.query("match", description="inverting")
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# GitHub history for details.
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
@@ -54,8 +55,8 @@ class MetricSearch(AsyncFacetedSearch):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def commit_search_cls(opensearch_version):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
def commit_search_cls(opensearch_version: Any) -> Any:
|
||||
interval_kwargs = {"fixed_interval": "1d"}
|
||||
|
||||
class CommitSearch(AsyncFacetedSearch):
|
||||
@@ -79,8 +80,8 @@ def commit_search_cls(opensearch_version):
|
||||
return CommitSearch
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def repo_search_cls(opensearch_version):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
def repo_search_cls(opensearch_version: Any) -> Any:
|
||||
interval_type = "calendar_interval"
|
||||
|
||||
class RepoSearch(AsyncFacetedSearch):
|
||||
@@ -93,15 +94,15 @@ def repo_search_cls(opensearch_version):
|
||||
),
|
||||
}
|
||||
|
||||
def search(self):
|
||||
def search(self) -> Any:
|
||||
s = super(RepoSearch, self).search()
|
||||
return s.filter("term", commit_repo="repo")
|
||||
|
||||
return RepoSearch
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def pr_search_cls(opensearch_version):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
def pr_search_cls(opensearch_version: Any) -> Any:
|
||||
interval_type = "calendar_interval"
|
||||
|
||||
class PRSearch(AsyncFacetedSearch):
|
||||
@@ -119,7 +120,7 @@ def pr_search_cls(opensearch_version):
|
||||
return PRSearch
|
||||
|
||||
|
||||
async def test_facet_with_custom_metric(data_client) -> None:
|
||||
async def test_facet_with_custom_metric(data_client: Any) -> None:
|
||||
ms = MetricSearch()
|
||||
r = await ms.execute()
|
||||
|
||||
@@ -128,7 +129,7 @@ async def test_facet_with_custom_metric(data_client) -> None:
|
||||
assert dates[0] == 1399038439000
|
||||
|
||||
|
||||
async def test_nested_facet(pull_request, pr_search_cls) -> None:
|
||||
async def test_nested_facet(pull_request: Any, pr_search_cls: Any) -> None:
|
||||
prs = pr_search_cls()
|
||||
r = await prs.execute()
|
||||
|
||||
@@ -136,7 +137,7 @@ async def test_nested_facet(pull_request, pr_search_cls) -> None:
|
||||
assert [(datetime(2018, 1, 1, 0, 0), 1, False)] == r.facets.comments
|
||||
|
||||
|
||||
async def test_nested_facet_with_filter(pull_request, pr_search_cls) -> None:
|
||||
async def test_nested_facet_with_filter(pull_request: Any, pr_search_cls: Any) -> None:
|
||||
prs = pr_search_cls(filters={"comments": datetime(2018, 1, 1, 0, 0)})
|
||||
r = await prs.execute()
|
||||
|
||||
@@ -148,7 +149,7 @@ async def test_nested_facet_with_filter(pull_request, pr_search_cls) -> None:
|
||||
assert not r.hits
|
||||
|
||||
|
||||
async def test_datehistogram_facet(data_client, repo_search_cls) -> None:
|
||||
async def test_datehistogram_facet(data_client: Any, repo_search_cls: Any) -> None:
|
||||
rs = repo_search_cls()
|
||||
r = await rs.execute()
|
||||
|
||||
@@ -156,7 +157,7 @@ async def test_datehistogram_facet(data_client, repo_search_cls) -> None:
|
||||
assert [(datetime(2014, 3, 1, 0, 0), 1, False)] == r.facets.created
|
||||
|
||||
|
||||
async def test_boolean_facet(data_client, repo_search_cls) -> None:
|
||||
async def test_boolean_facet(data_client: Any, repo_search_cls: Any) -> None:
|
||||
rs = repo_search_cls()
|
||||
r = await rs.execute()
|
||||
|
||||
@@ -167,7 +168,7 @@ async def test_boolean_facet(data_client, repo_search_cls) -> None:
|
||||
|
||||
|
||||
async def test_empty_search_finds_everything(
|
||||
data_client, opensearch_version, commit_search_cls
|
||||
data_client: Any, opensearch_version: Any, commit_search_cls: Any
|
||||
) -> None:
|
||||
cs = commit_search_cls()
|
||||
r = await cs.execute()
|
||||
@@ -213,7 +214,7 @@ async def test_empty_search_finds_everything(
|
||||
|
||||
|
||||
async def test_term_filters_are_shown_as_selected_and_data_is_filtered(
|
||||
data_client, commit_search_cls
|
||||
data_client: Any, commit_search_cls: Any
|
||||
) -> None:
|
||||
cs = commit_search_cls(filters={"files": "test_opensearchpy/test_dsl"})
|
||||
|
||||
@@ -259,7 +260,7 @@ async def test_term_filters_are_shown_as_selected_and_data_is_filtered(
|
||||
|
||||
|
||||
async def test_range_filters_are_shown_as_selected_and_data_is_filtered(
|
||||
data_client, commit_search_cls
|
||||
data_client: Any, commit_search_cls: Any
|
||||
) -> None:
|
||||
cs = commit_search_cls(filters={"deletions": "better"})
|
||||
|
||||
@@ -268,7 +269,7 @@ async def test_range_filters_are_shown_as_selected_and_data_is_filtered(
|
||||
assert 19 == r.hits.total.value
|
||||
|
||||
|
||||
async def test_pagination(data_client, commit_search_cls) -> None:
|
||||
async def test_pagination(data_client: Any, commit_search_cls: Any) -> None:
|
||||
cs = commit_search_cls()
|
||||
cs = cs[0:20]
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
|
||||
@@ -24,7 +26,7 @@ class Post(AsyncDocument):
|
||||
published_from = Date()
|
||||
|
||||
|
||||
async def test_index_template_works(write_client) -> None:
|
||||
async def test_index_template_works(write_client: Any) -> None:
|
||||
it = AsyncIndexTemplate("test-template", "test-*")
|
||||
it.document(Post)
|
||||
it.settings(number_of_replicas=0, number_of_shards=1)
|
||||
@@ -45,7 +47,7 @@ async def test_index_template_works(write_client) -> None:
|
||||
} == await write_client.indices.get_mapping(index="test-blog")
|
||||
|
||||
|
||||
async def test_index_can_be_saved_even_with_settings(write_client) -> None:
|
||||
async def test_index_can_be_saved_even_with_settings(write_client: Any) -> None:
|
||||
i = AsyncIndex("test-blog", using=write_client)
|
||||
i.settings(number_of_shards=3, number_of_replicas=0)
|
||||
await i.save()
|
||||
@@ -60,12 +62,14 @@ async def test_index_can_be_saved_even_with_settings(write_client) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_index_exists(data_client) -> None:
|
||||
async def test_index_exists(data_client: Any) -> None:
|
||||
assert await AsyncIndex("git").exists()
|
||||
assert not await AsyncIndex("not-there").exists()
|
||||
|
||||
|
||||
async def test_index_can_be_created_with_settings_and_mappings(write_client) -> None:
|
||||
async def test_index_can_be_created_with_settings_and_mappings(
|
||||
write_client: Any,
|
||||
) -> None:
|
||||
i = AsyncIndex("test-blog", using=write_client)
|
||||
i.document(Post)
|
||||
i.settings(number_of_replicas=0, number_of_shards=1)
|
||||
@@ -90,7 +94,7 @@ async def test_index_can_be_created_with_settings_and_mappings(write_client) ->
|
||||
}
|
||||
|
||||
|
||||
async def test_delete(write_client) -> None:
|
||||
async def test_delete(write_client: Any) -> None:
|
||||
await write_client.indices.create(
|
||||
index="test-index",
|
||||
body={"settings": {"number_of_replicas": 0, "number_of_shards": 1}},
|
||||
@@ -101,9 +105,9 @@ async def test_delete(write_client) -> None:
|
||||
assert not await write_client.indices.exists(index="test-index")
|
||||
|
||||
|
||||
async def test_multiple_indices_with_same_doc_type_work(write_client) -> None:
|
||||
i1 = AsyncIndex("test-index-1", using=write_client)
|
||||
i2 = AsyncIndex("test-index-2", using=write_client)
|
||||
async def test_multiple_indices_with_same_doc_type_work(write_client: Any) -> None:
|
||||
i1: Any = AsyncIndex("test-index-1", using=write_client)
|
||||
i2: Any = AsyncIndex("test-index-2", using=write_client)
|
||||
|
||||
for i in i1, i2:
|
||||
i.document(Post)
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from pytest import raises
|
||||
@@ -19,7 +21,7 @@ from opensearchpy.helpers import analysis
|
||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
async def test_mapping_saved_into_opensearch(write_client) -> None:
|
||||
async def test_mapping_saved_into_opensearch(write_client: Any) -> None:
|
||||
m = mapping.AsyncMapping()
|
||||
m.field(
|
||||
"name", "text", analyzer=analysis.analyzer("my_analyzer", tokenizer="keyword")
|
||||
@@ -40,7 +42,7 @@ async def test_mapping_saved_into_opensearch(write_client) -> None:
|
||||
|
||||
|
||||
async def test_mapping_saved_into_opensearch_when_index_already_exists_closed(
|
||||
write_client,
|
||||
write_client: Any,
|
||||
) -> None:
|
||||
m = mapping.AsyncMapping()
|
||||
m.field(
|
||||
@@ -65,7 +67,7 @@ async def test_mapping_saved_into_opensearch_when_index_already_exists_closed(
|
||||
|
||||
|
||||
async def test_mapping_saved_into_opensearch_when_index_already_exists_with_analysis(
|
||||
write_client,
|
||||
write_client: Any,
|
||||
) -> None:
|
||||
m = mapping.AsyncMapping()
|
||||
analyzer = analysis.analyzer("my_analyzer", tokenizer="keyword")
|
||||
@@ -95,7 +97,7 @@ async def test_mapping_saved_into_opensearch_when_index_already_exists_with_anal
|
||||
} == await write_client.indices.get_mapping(index="test-mapping")
|
||||
|
||||
|
||||
async def test_mapping_gets_updated_from_opensearch(write_client):
|
||||
async def test_mapping_gets_updated_from_opensearch(write_client: Any) -> None:
|
||||
await write_client.indices.create(
|
||||
index="test-mapping",
|
||||
body={
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
from pytest import raises
|
||||
@@ -29,7 +31,7 @@ class Repository(AsyncDocument):
|
||||
tags = Keyword()
|
||||
|
||||
@classmethod
|
||||
def search(cls):
|
||||
def search(cls, using: Any = None, index: Any = None) -> Any:
|
||||
return super(Repository, cls).search().filter("term", commit_repo="repo")
|
||||
|
||||
class Index:
|
||||
@@ -41,7 +43,7 @@ class Commit(AsyncDocument):
|
||||
name = "flat-git"
|
||||
|
||||
|
||||
async def test_filters_aggregation_buckets_are_accessible(data_client) -> None:
|
||||
async def test_filters_aggregation_buckets_are_accessible(data_client: Any) -> None:
|
||||
has_tests_query = Q("term", files="test_opensearchpy/test_dsl")
|
||||
s = Commit.search()[0:0]
|
||||
s.aggs.bucket("top_authors", "terms", field="author.name.raw").bucket(
|
||||
@@ -62,7 +64,7 @@ async def test_filters_aggregation_buckets_are_accessible(data_client) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_top_hits_are_wrapped_in_response(data_client) -> None:
|
||||
async def test_top_hits_are_wrapped_in_response(data_client: Any) -> None:
|
||||
s = Commit.search()[0:0]
|
||||
s.aggs.bucket("top_authors", "terms", field="author.name.raw").metric(
|
||||
"top_commits", "top_hits", size=5
|
||||
@@ -78,7 +80,7 @@ async def test_top_hits_are_wrapped_in_response(data_client) -> None:
|
||||
assert isinstance(hits[0], Commit)
|
||||
|
||||
|
||||
async def test_inner_hits_are_wrapped_in_response(data_client) -> None:
|
||||
async def test_inner_hits_are_wrapped_in_response(data_client: Any) -> None:
|
||||
s = AsyncSearch(index="git")[0:1].query(
|
||||
"has_parent", parent_type="repo", inner_hits={}, query=Q("match_all")
|
||||
)
|
||||
@@ -89,7 +91,7 @@ async def test_inner_hits_are_wrapped_in_response(data_client) -> None:
|
||||
assert repr(commit.meta.inner_hits.repo[0]).startswith("<Hit(git/opensearch-py): ")
|
||||
|
||||
|
||||
async def test_scan_respects_doc_types(data_client) -> None:
|
||||
async def test_scan_respects_doc_types(data_client: Any) -> None:
|
||||
result = Repository.search().scan()
|
||||
repos = await get_result(result)
|
||||
|
||||
@@ -98,7 +100,7 @@ async def test_scan_respects_doc_types(data_client) -> None:
|
||||
assert repos[0].organization == "opensearch"
|
||||
|
||||
|
||||
async def test_scan_iterates_through_all_docs(data_client) -> None:
|
||||
async def test_scan_iterates_through_all_docs(data_client: Any) -> None:
|
||||
s = AsyncSearch(index="flat-git")
|
||||
result = s.scan()
|
||||
commits = await get_result(result)
|
||||
@@ -107,14 +109,14 @@ async def test_scan_iterates_through_all_docs(data_client) -> None:
|
||||
assert {d["_id"] for d in FLAT_DATA} == {c.meta.id for c in commits}
|
||||
|
||||
|
||||
async def get_result(b):
|
||||
async def get_result(b: Any) -> Any:
|
||||
a = []
|
||||
async for i in b:
|
||||
a.append(i)
|
||||
return a
|
||||
|
||||
|
||||
async def test_multi_search(data_client) -> None:
|
||||
async def test_multi_search(data_client: Any) -> None:
|
||||
s1 = Repository.search()
|
||||
s2 = AsyncSearch(index="flat-git")
|
||||
|
||||
@@ -131,7 +133,7 @@ async def test_multi_search(data_client) -> None:
|
||||
assert r2._search is s2
|
||||
|
||||
|
||||
async def test_multi_missing(data_client) -> None:
|
||||
async def test_multi_missing(data_client: Any) -> None:
|
||||
s1 = Repository.search()
|
||||
s2 = AsyncSearch(index="flat-git")
|
||||
s3 = AsyncSearch(index="does_not_exist")
|
||||
@@ -154,7 +156,7 @@ async def test_multi_missing(data_client) -> None:
|
||||
assert r3 is None
|
||||
|
||||
|
||||
async def test_raw_subfield_can_be_used_in_aggs(data_client) -> None:
|
||||
async def test_raw_subfield_can_be_used_in_aggs(data_client: Any) -> None:
|
||||
s = AsyncSearch(index="git")[0:0]
|
||||
s.aggs.bucket("authors", "terms", field="author.name.raw", size=1)
|
||||
r = await s.execute()
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
|
||||
@@ -17,7 +19,9 @@ from opensearchpy.helpers.search import Q
|
||||
pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
|
||||
|
||||
async def test_update_by_query_no_script(write_client, setup_ubq_tests) -> None:
|
||||
async def test_update_by_query_no_script(
|
||||
write_client: Any, setup_ubq_tests: Any
|
||||
) -> None:
|
||||
index = setup_ubq_tests
|
||||
|
||||
ubq = (
|
||||
@@ -36,7 +40,9 @@ async def test_update_by_query_no_script(write_client, setup_ubq_tests) -> None:
|
||||
assert response.success()
|
||||
|
||||
|
||||
async def test_update_by_query_with_script(write_client, setup_ubq_tests) -> None:
|
||||
async def test_update_by_query_with_script(
|
||||
write_client: Any, setup_ubq_tests: Any
|
||||
) -> None:
|
||||
index = setup_ubq_tests
|
||||
|
||||
ubq = (
|
||||
@@ -53,7 +59,9 @@ async def test_update_by_query_with_script(write_client, setup_ubq_tests) -> Non
|
||||
assert response.version_conflicts == 0
|
||||
|
||||
|
||||
async def test_delete_by_query_with_script(write_client, setup_ubq_tests) -> None:
|
||||
async def test_delete_by_query_with_script(
|
||||
write_client: Any, setup_ubq_tests: Any
|
||||
) -> None:
|
||||
index = setup_ubq_tests
|
||||
|
||||
ubq = (
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
async def test_create_destination(self):
|
||||
async def test_create_destination(self) -> None:
|
||||
# Test to create alert destination
|
||||
dummy_destination = {
|
||||
"name": "my-destination",
|
||||
@@ -59,7 +59,7 @@ class TestAlertingPlugin(AsyncOpenSearchTestCase):
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
async def test_create_monitor(self):
|
||||
async def test_create_monitor(self) -> None:
|
||||
# Create a dummy destination
|
||||
await self.test_create_destination()
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ clients.
|
||||
"""
|
||||
import inspect
|
||||
import warnings
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest.mark.structures import MarkDecorator
|
||||
@@ -53,14 +54,14 @@ pytestmark: MarkDecorator = pytest.mark.asyncio
|
||||
OPENSEARCH_VERSION = None
|
||||
|
||||
|
||||
async def await_if_coro(x):
|
||||
async def await_if_coro(x: Any) -> Any:
|
||||
if inspect.iscoroutine(x):
|
||||
return await x
|
||||
return x
|
||||
|
||||
|
||||
class AsyncYamlRunner(YamlRunner):
|
||||
async def setup(self):
|
||||
async def setup(self) -> None:
|
||||
# Pull skips from individual tests to not do unnecessary setup.
|
||||
skip_code = []
|
||||
for action in self._run_code:
|
||||
@@ -78,12 +79,12 @@ class AsyncYamlRunner(YamlRunner):
|
||||
if self._setup_code:
|
||||
await self.run_code(self._setup_code)
|
||||
|
||||
async def teardown(self) -> None:
|
||||
async def teardown(self) -> Any:
|
||||
if self._teardown_code:
|
||||
self.section("teardown")
|
||||
await self.run_code(self._teardown_code)
|
||||
|
||||
async def opensearch_version(self):
|
||||
async def opensearch_version(self) -> Any:
|
||||
global OPENSEARCH_VERSION
|
||||
if OPENSEARCH_VERSION is None:
|
||||
version_string = (await self.client.info())["version"]["number"]
|
||||
@@ -93,10 +94,10 @@ class AsyncYamlRunner(YamlRunner):
|
||||
OPENSEARCH_VERSION = tuple(int(v) if v.isdigit() else 999 for v in version)
|
||||
return OPENSEARCH_VERSION
|
||||
|
||||
def section(self, name) -> None:
|
||||
def section(self, name: str) -> None:
|
||||
print(("=" * 10) + " " + name + " " + ("=" * 10))
|
||||
|
||||
async def run(self) -> None:
|
||||
async def run(self) -> Any:
|
||||
try:
|
||||
await self.setup()
|
||||
self.section("test")
|
||||
@@ -107,7 +108,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def run_code(self, test) -> None:
|
||||
async def run_code(self, test: Any) -> Any:
|
||||
"""Execute an instruction based on its type."""
|
||||
for action in test:
|
||||
assert len(action) == 1
|
||||
@@ -119,7 +120,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
else:
|
||||
raise RuntimeError("Invalid action type %r" % (action_type,))
|
||||
|
||||
async def run_do(self, action) -> None:
|
||||
async def run_do(self, action: Any) -> Any:
|
||||
api = self.client
|
||||
headers = action.pop("headers", None)
|
||||
catch = action.pop("catch", None)
|
||||
@@ -171,7 +172,7 @@ class AsyncYamlRunner(YamlRunner):
|
||||
|
||||
# Filter out warnings raised by other components.
|
||||
caught_warnings = [
|
||||
str(w.message)
|
||||
str(w.message) # type: ignore
|
||||
for w in caught_warnings
|
||||
if w.category == OpenSearchWarning
|
||||
and str(w.message) not in allowed_warnings
|
||||
@@ -179,13 +180,13 @@ class AsyncYamlRunner(YamlRunner):
|
||||
|
||||
# Sorting removes the issue with order raised. We only care about
|
||||
# if all warnings are raised in the single API call.
|
||||
if warn and sorted(warn) != sorted(caught_warnings):
|
||||
if warn and sorted(warn) != sorted(caught_warnings): # type: ignore
|
||||
raise AssertionError(
|
||||
"Expected warnings not equal to actual warnings: expected=%r actual=%r"
|
||||
% (warn, caught_warnings)
|
||||
)
|
||||
|
||||
async def run_skip(self, skip) -> None:
|
||||
async def run_skip(self, skip: Any) -> Any:
|
||||
if "features" in skip:
|
||||
features = skip["features"]
|
||||
if not isinstance(features, (tuple, list)):
|
||||
@@ -205,19 +206,19 @@ class AsyncYamlRunner(YamlRunner):
|
||||
if min_version <= (await self.opensearch_version()) <= max_version:
|
||||
pytest.skip(reason)
|
||||
|
||||
async def _feature_enabled(self, name) -> bool:
|
||||
async def _feature_enabled(self, name: str) -> Any:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def async_runner(async_client):
|
||||
@pytest.fixture(scope="function") # type: ignore
|
||||
def async_runner(async_client: Any) -> AsyncYamlRunner:
|
||||
return AsyncYamlRunner(async_client)
|
||||
|
||||
|
||||
if RUN_ASYNC_REST_API_TESTS:
|
||||
|
||||
@pytest.mark.parametrize("test_spec", YAML_TEST_SPECS)
|
||||
async def test_rest_api_spec(test_spec, async_runner) -> None:
|
||||
@pytest.mark.parametrize("test_spec", YAML_TEST_SPECS) # type: ignore
|
||||
async def test_rest_api_spec(test_spec: Any, async_runner: Any) -> None:
|
||||
if test_spec.get("skip", False):
|
||||
pytest.skip("Manually skipped in 'SKIP_TESTS'")
|
||||
async_runner.use_spec(test_spec)
|
||||
|
||||
Reference in New Issue
Block a user