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

[Search] Enable test-proxy and test-resources.bicep #22187

Merged
merged 33 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5b9b938
Add test-resources.bicep
tjprescott Dec 15, 2021
9140656
Test-proxy configuration.
tjprescott Dec 15, 2021
c2f57a9
Convert test_search_indexer_client_live.py
tjprescott Dec 15, 2021
d0a6de3
Update test to use variables.
tjprescott Dec 16, 2021
c1037e9
Fix #22187.
tjprescott Jan 7, 2022
1e53483
Commit first successful recordings!
tjprescott Jan 21, 2022
c6aa75c
Synonym map progress.
tjprescott Jan 21, 2022
a42fbbe
Convert test_search_index_client_synonym_map_live.py
tjprescott Jan 24, 2022
c7c2e50
Fix imports for CI.
tjprescott Jan 24, 2022
bea1092
Parameterized search_decorator.
tjprescott Jan 24, 2022
7024207
FINALLY get parameterized test working.... ..........................…
tjprescott Jan 24, 2022
7454598
Fix up tests.
tjprescott Jan 25, 2022
8490409
Progress
tjprescott Jan 25, 2022
a6eda7f
Finalize skillset tests. Remove old recordings and legacy code.
tjprescott Jan 25, 2022
9462361
search_index_client_live.py
tjprescott Jan 25, 2022
815315c
Recording updates.
tjprescott Jan 25, 2022
0076369
test_search_index_client_data_source_live.py
tjprescott Jan 25, 2022
b542f29
test_search_client_search_live.py
tjprescott Jan 25, 2022
ab7f533
Workaround for Python recording bug.
tjprescott Jan 26, 2022
cf46397
test_search_client_index_document_live.py
tjprescott Jan 26, 2022
c0f39f3
test_search_client_buffered_sender_live.py
tjprescott Jan 26, 2022
8feb67a
test_search_client_basic_live_async.py
tjprescott Jan 26, 2022
bcc186a
test_serach_client_search_live_async.py
tjprescott Jan 26, 2022
bc2314e
test_search_index_client_live_async.py
tjprescott Jan 27, 2022
a4a1407
test_search_index_client_synonym_map_live_async.py
tjprescott Jan 27, 2022
2e45fb3
test_search_index_client_skillset_live_async.py
tjprescott Jan 27, 2022
4cf0fa6
test_search_index_client_data_source_live.py
tjprescott Jan 27, 2022
23bca69
Remove workaround annotations.
tjprescott Jan 27, 2022
425aa51
test_search_client_index_document_live_async.py
tjprescott Jan 27, 2022
a371a05
test_search_client_buffered_sender_live_async.py
tjprescott Jan 27, 2022
939710b
Re-record and finalize all tests.
tjprescott Jan 27, 2022
775a249
Ignore cSpell
tjprescott Jan 27, 2022
1588c28
Goodbye PowershellPreparer
tjprescott Jan 31, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,43 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import asyncio
import functools
import json
from os.path import dirname, join, realpath

import pytest

from devtools_testutils import AzureMgmtTestCase, ResourceGroupPreparer
from azure_devtools.scenario_tests import ReplayableTest

from search_service_preparer import SearchServicePreparer

from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function

CWD = dirname(realpath(__file__))

SCHEMA = open(join(CWD, "..", "hotel_schema.json")).read()
BATCH = json.load(open(join(CWD, "..", "hotel_small.json"), encoding='utf-8'))

from azure.core.exceptions import HttpResponseError
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.aio import SearchClient
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils import AzureRecordedTestCase

TIME_TO_SLEEP = 3

def await_prepared_test(test_fn):
"""Synchronous wrapper for async test methods. Used to avoid making changes
upstream to AbstractPreparer (which doesn't await the functions it wraps)
"""

@functools.wraps(test_fn)
def run(test_class_instance, *args, **kwargs):
trim_kwargs_from_test_function(test_fn, kwargs)
loop = asyncio.get_event_loop()
return loop.run_until_complete(test_fn(test_class_instance, **kwargs))

return run

from search_service_preparer import SearchEnvVarPreparer, search_decorator

class SearchClientTestAsync(AzureMgmtTestCase):
FILTER_HEADERS = ReplayableTest.FILTER_HEADERS + ['api-key']
class TestSearchClientAsync(AzureRecordedTestCase):

@ResourceGroupPreparer(random_name_enabled=True)
@SearchServicePreparer(schema=SCHEMA, index_batch=BATCH)
async def test_async_get_document_count(
self, api_key, endpoint, index_name, **kwargs
):
client = SearchClient(
endpoint, index_name, AzureKeyCredential(api_key)
)
@SearchEnvVarPreparer()
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
@recorded_by_proxy_async
async def test_get_document_count(self, endpoint, api_key, index_name):
client = SearchClient(endpoint, index_name, api_key)
async with client:
assert await client.get_document_count() == 10

@ResourceGroupPreparer(random_name_enabled=True)
@SearchServicePreparer(schema=SCHEMA, index_batch=BATCH)
async def test_get_document(self, api_key, endpoint, index_name, **kwargs):
client = SearchClient(
endpoint, index_name, AzureKeyCredential(api_key)
)
@SearchEnvVarPreparer()
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
@recorded_by_proxy_async
async def test_get_document(self, endpoint, api_key, index_name, index_batch):
client = SearchClient(endpoint, index_name, api_key)
async with client:
for hotel_id in range(1, 11):
result = await client.get_document(key=str(hotel_id))
expected = BATCH["value"][hotel_id - 1]
expected = index_batch["value"][hotel_id - 1]
assert result.get("hotelId") == expected.get("hotelId")
assert result.get("hotelName") == expected.get("hotelName")
assert result.get("description") == expected.get("description")

@ResourceGroupPreparer(random_name_enabled=True)
@SearchServicePreparer(schema=SCHEMA, index_batch=BATCH)
async def test_get_document_missing(self, api_key, endpoint, index_name, **kwargs):
client = SearchClient(
endpoint, index_name, AzureKeyCredential(api_key)
)
@SearchEnvVarPreparer()
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
@recorded_by_proxy_async
async def test_get_document_missing(self, endpoint, api_key, index_name):
client = SearchClient(endpoint, index_name, api_key)
async with client:
with pytest.raises(HttpResponseError):
await client.get_document(key="1000")
Loading