Skip to content

Commit

Permalink
[Search] Enable test-proxy and test-resources.bicep (Azure#22187)
Browse files Browse the repository at this point in the history
* Add test-resources.bicep

* Test-proxy configuration.

* Convert test_search_indexer_client_live.py

* Update test to use variables.

* Fix Azure#22187.

* Commit first successful recordings!

* Synonym map progress.

* Convert test_search_index_client_synonym_map_live.py

* Fix imports for CI.

* Parameterized search_decorator.

* FINALLY get parameterized test working.... ..............................................

* Fix up tests.

* Progress

* Finalize skillset tests. Remove old recordings and legacy code.

* search_index_client_live.py

* Recording updates.

* test_search_index_client_data_source_live.py

* test_search_client_search_live.py

* Workaround for Python recording bug.

* test_search_client_index_document_live.py

* test_search_client_buffered_sender_live.py

* test_search_client_basic_live_async.py

* test_serach_client_search_live_async.py

* test_search_index_client_live_async.py

* test_search_index_client_synonym_map_live_async.py

* test_search_index_client_skillset_live_async.py

* test_search_index_client_data_source_live.py

* Remove workaround annotations.

* test_search_client_index_document_live_async.py

* test_search_client_buffered_sender_live_async.py

* Re-record and finalize all tests.

* Ignore cSpell

* Goodbye PowershellPreparer
  • Loading branch information
tjprescott authored and rakshith91 committed Apr 10, 2022
1 parent 5a53476 commit 178ca4c
Show file tree
Hide file tree
Showing 115 changed files with 31,413 additions and 13,420 deletions.
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

0 comments on commit 178ca4c

Please sign in to comment.