Skip to content

Commit b05b1ce

Browse files
search mi test (#35739)
* search_test_cleanup * Update tests * update * update * update * update * update * update * update * Subscription configuration * Param * chomp * Test samples * UseFederatedAuth * update * update * update * updates * updates * updates * add log * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update --------- Co-authored-by: Daniel Jurek <[email protected]>
1 parent 6327923 commit b05b1ce

26 files changed

+135
-687
lines changed

sdk/search/azure-search-documents/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Bugs Fixed
1212

13+
- Fixed the issue that we missed ODATA header when using Entra ID auth.
14+
1315
### Other Changes
1416

1517
## 11.6.0b4 (2024-05-07)

sdk/search/azure-search-documents/azure/search/documents/_headers_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
class HeadersMixin:
1111
@property
1212
def _headers(self) -> Dict[str, Any]:
13+
if self._aad: # type: ignore
14+
return {"Accept": self._ODATA_ACCEPT} # type: ignore
1315
return {"api-key": self._credential.key, "Accept": self._ODATA_ACCEPT} # type: ignore
1416

1517
def _merge_client_headers(self, headers: Optional[MutableMapping[str, str]]) -> MutableMapping[str, str]:
16-
if self._aad: # type: ignore
17-
return headers or {}
1818
headers = headers or {}
1919
combined = self._headers
2020
combined.update(headers)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-e ../../../tools/azure-sdk-tools
22
../../nspkg/azure-search-nspkg
33
aiohttp>=3.0
4+
azure-identity
45
azure-mgmt-resource<=21.1.0

sdk/search/azure-search-documents/tests/async_tests/test_search_client_basic_live_async.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from azure.core.exceptions import HttpResponseError
99
from azure.search.documents.aio import SearchClient
1010
from devtools_testutils.aio import recorded_by_proxy_async
11-
from devtools_testutils import AzureRecordedTestCase
11+
from devtools_testutils import AzureRecordedTestCase, get_credential
1212

1313
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1414

@@ -17,16 +17,16 @@ class TestSearchClientAsync(AzureRecordedTestCase):
1717
@SearchEnvVarPreparer()
1818
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
1919
@recorded_by_proxy_async
20-
async def test_get_document_count(self, endpoint, api_key, index_name):
21-
client = SearchClient(endpoint, index_name, api_key)
20+
async def test_get_document_count(self, endpoint, index_name):
21+
client = SearchClient(endpoint, index_name, get_credential(is_async=True))
2222
async with client:
2323
assert await client.get_document_count() == 10
2424

2525
@SearchEnvVarPreparer()
2626
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
2727
@recorded_by_proxy_async
28-
async def test_get_document(self, endpoint, api_key, index_name, index_batch):
29-
client = SearchClient(endpoint, index_name, api_key)
28+
async def test_get_document(self, endpoint, index_name, index_batch):
29+
client = SearchClient(endpoint, index_name, get_credential(is_async=True))
3030
async with client:
3131
for hotel_id in range(1, 11):
3232
result = await client.get_document(key=str(hotel_id))
@@ -38,8 +38,8 @@ async def test_get_document(self, endpoint, api_key, index_name, index_batch):
3838
@SearchEnvVarPreparer()
3939
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
4040
@recorded_by_proxy_async
41-
async def test_get_document_missing(self, endpoint, api_key, index_name):
42-
client = SearchClient(endpoint, index_name, api_key)
41+
async def test_get_document_missing(self, endpoint, index_name):
42+
client = SearchClient(endpoint, index_name, get_credential(is_async=True))
4343
async with client:
4444
with pytest.raises(HttpResponseError):
4545
await client.get_document(key="1000")

sdk/search/azure-search-documents/tests/async_tests/test_search_client_buffered_sender_live_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from azure.core.exceptions import HttpResponseError
1010
from azure.core.credentials import AzureKeyCredential
1111
from azure.search.documents.aio import SearchIndexingBufferedSender, SearchClient
12-
from devtools_testutils import AzureRecordedTestCase
12+
from devtools_testutils import AzureRecordedTestCase, get_credential
1313
from devtools_testutils.aio import recorded_by_proxy_async
1414
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1515

@@ -20,9 +20,9 @@ class TestSearchIndexingBufferedSenderAsync(AzureRecordedTestCase):
2020
@SearchEnvVarPreparer()
2121
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
2222
@recorded_by_proxy_async
23-
async def test_search_client_index_buffered_sender(self, endpoint, api_key, index_name):
24-
client = SearchClient(endpoint, index_name, api_key, retry_backoff_factor=60)
25-
batch_client = SearchIndexingBufferedSender(endpoint, index_name, api_key, retry_backoff_factor=60)
23+
async def test_search_client_index_buffered_sender(self, endpoint, index_name):
24+
client = SearchClient(endpoint, index_name, get_credential(is_async=True), retry_backoff_factor=60)
25+
batch_client = SearchIndexingBufferedSender(endpoint, index_name, get_credential(is_async=True), retry_backoff_factor=60)
2626
try:
2727
async with client:
2828
async with batch_client:

sdk/search/azure-search-documents/tests/async_tests/test_search_client_index_document_live_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010
from azure.core.exceptions import HttpResponseError
1111
from azure.search.documents.aio import SearchClient
12-
from devtools_testutils import AzureRecordedTestCase
12+
from devtools_testutils import AzureRecordedTestCase, get_credential
1313
from devtools_testutils.aio import recorded_by_proxy_async
1414
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1515

@@ -20,8 +20,8 @@ class TestSearchClientDocumentsAsync(AzureRecordedTestCase):
2020
@SearchEnvVarPreparer()
2121
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
2222
@recorded_by_proxy_async
23-
async def test_search_client_index_document(self, endpoint, api_key, index_name):
24-
client = SearchClient(endpoint, index_name, api_key, retry_backoff_factor=60)
23+
async def test_search_client_index_document(self, endpoint, index_name):
24+
client = SearchClient(endpoint, index_name, get_credential(is_async=True), retry_backoff_factor=60)
2525
doc_count = 10
2626
async with client:
2727
doc_count = await self._test_upload_documents_new(client, doc_count)

sdk/search/azure-search-documents/tests/async_tests/test_search_client_search_live_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from azure.core.exceptions import HttpResponseError
99
from azure.search.documents.aio import SearchClient
1010
from devtools_testutils.aio import recorded_by_proxy_async
11-
from devtools_testutils import AzureRecordedTestCase
11+
from devtools_testutils import AzureRecordedTestCase, get_credential
1212

1313
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1414

@@ -17,8 +17,8 @@ class TestClientTestAsync(AzureRecordedTestCase):
1717
@SearchEnvVarPreparer()
1818
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
1919
@recorded_by_proxy_async
20-
async def test_search_client(self, endpoint, api_key, index_name):
21-
client = SearchClient(endpoint, index_name, api_key, retry_backoff_factor=60)
20+
async def test_search_client(self, endpoint, index_name):
21+
client = SearchClient(endpoint, index_name, get_credential(is_async=True), retry_backoff_factor=60)
2222
async with client:
2323
await self._test_get_search_simple(client)
2424
await self._test_get_search_simple_with_top(client)
@@ -144,8 +144,8 @@ async def _test_suggest(self, client):
144144
@SearchEnvVarPreparer()
145145
@search_decorator(schema="hotel_schema.json", index_batch="hotel_large.json")
146146
@recorded_by_proxy_async
147-
async def test_search_client_large(self, endpoint, api_key, index_name):
148-
client = SearchClient(endpoint, index_name, api_key)
147+
async def test_search_client_large(self, endpoint, index_name):
148+
client = SearchClient(endpoint, index_name, get_credential(is_async=True))
149149
async with client:
150150
await self._test_get_search_simple_large(client)
151151

sdk/search/azure-search-documents/tests/async_tests/test_search_index_client_alias_live_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from azure.core.exceptions import HttpResponseError
1212
from azure.search.documents.indexes.aio import SearchIndexClient
1313
from devtools_testutils.aio import recorded_by_proxy_async
14-
from devtools_testutils import AzureRecordedTestCase
14+
from devtools_testutils import AzureRecordedTestCase, get_credential
1515
from azure.search.documents.indexes.models import (
1616
AnalyzeTextOptions,
1717
CorsOptions,
@@ -29,8 +29,8 @@ class TestSearchClientAlias(AzureRecordedTestCase):
2929
@SearchEnvVarPreparer()
3030
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
3131
@recorded_by_proxy_async
32-
async def test_alias(self, endpoint, api_key):
33-
client = SearchIndexClient(endpoint, api_key, retry_backoff_factor=60)
32+
async def test_alias(self, endpoint):
33+
client = SearchIndexClient(endpoint, get_credential(is_async=True), retry_backoff_factor=60)
3434
aliases = ["resort", "motel"]
3535

3636
async with client:

sdk/search/azure-search-documents/tests/async_tests/test_search_index_client_data_source_live_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from azure.core import MatchConditions
99
from azure.core.exceptions import HttpResponseError
1010
from devtools_testutils.aio import recorded_by_proxy_async
11-
from devtools_testutils import AzureRecordedTestCase
11+
from devtools_testutils import AzureRecordedTestCase, get_credential
1212

1313
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1414
from azure.search.documents.indexes.models import (
@@ -29,9 +29,9 @@ def _create_data_source_connection(self, cs, name):
2929
@SearchEnvVarPreparer()
3030
@search_decorator(schema="hotel_schema.json", index_batch="hotel_small.json")
3131
@recorded_by_proxy_async
32-
async def test_data_source(self, endpoint, api_key, **kwargs):
32+
async def test_data_source(self, endpoint, **kwargs):
3333
storage_cs = kwargs.get("search_storage_connection_string")
34-
client = SearchIndexerClient(endpoint, api_key, retry_backoff_factor=60)
34+
client = SearchIndexerClient(endpoint, get_credential(is_async=True), retry_backoff_factor=60)
3535
async with client:
3636
await self._test_create_datasource(client, storage_cs)
3737
await self._test_delete_datasource(client, storage_cs)

sdk/search/azure-search-documents/tests/async_tests/test_search_index_client_live_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from azure.core.exceptions import HttpResponseError
99
from azure.core import MatchConditions
1010
from devtools_testutils.aio import recorded_by_proxy_async
11-
from devtools_testutils import AzureRecordedTestCase
11+
from devtools_testutils import AzureRecordedTestCase, get_credential
1212

1313
from search_service_preparer import SearchEnvVarPreparer, search_decorator
1414
from azure.search.documents.indexes.aio import SearchIndexClient
@@ -26,8 +26,8 @@ class TestSearchIndexClientAsync(AzureRecordedTestCase):
2626
@SearchEnvVarPreparer()
2727
@search_decorator(schema=None, index_batch=None)
2828
@recorded_by_proxy_async
29-
async def test_search_index_client(self, api_key, endpoint, index_name):
30-
client = SearchIndexClient(endpoint, api_key, retry_backoff_factor=60)
29+
async def test_search_index_client(self, endpoint, index_name):
30+
client = SearchIndexClient(endpoint, get_credential(is_async=True), retry_backoff_factor=60)
3131
index_name = "hotels"
3232
async with client:
3333
await self._test_get_service_statistics(client)

0 commit comments

Comments
 (0)