diff --git a/sdk/search/azure-search-documents/azure/search/documents/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/__init__.py index 11191c28483a..2437d1bcf989 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/__init__.py @@ -49,6 +49,9 @@ ConditionalSkill, CorsOptions, CustomAnalyzer, + DataSource, + DataSourceCredentials, + DataContainer, DictionaryDecompounderTokenFilter, DistanceScoringFunction, DistanceScoringParameters, @@ -135,6 +138,9 @@ "ConditionalSkill", "CorsOptions", "CustomAnalyzer", + "DataSource", + "DataSourceCredentials", + "DataContainer", "DictionaryDecompounderTokenFilter", "DistanceScoringFunction", "DistanceScoringParameters", diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_models.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_models.py index 529af151836f..57158bb88fb0 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_models.py @@ -3,7 +3,10 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from ._generated.models import Analyzer, Tokenizer +from ._generated.models import ( + Analyzer, + Tokenizer +) class PatternAnalyzer(Analyzer): diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py index 7d469ca62495..b6c78d2b6d27 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/_search_service_client.py @@ -29,11 +29,11 @@ # pylint:disable=unused-import,ungrouped-imports from typing import Any, List, Sequence, Union from azure.core.credentials import AzureKeyCredential - from ._generated.models import Skill + from ._generated.models import Skill, DataSource from .. import Index, AnalyzeResult, AnalyzeRequest -class SearchServiceClient(HeadersMixin): +class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-methods """A client to interact with an existing Azure search service. :param endpoint: The URL endpoint of an Azure search service @@ -554,3 +554,114 @@ def create_or_update_skillset(self, name, **kwargs): ) return self._client.skillsets.create_or_update(name, skillset, **kwargs) + + @distributed_trace + def create_datasource(self, data_source, **kwargs): + # type: (str, DataSource, **Any) -> Dict[str, Any] + """Creates a new datasource. + + :param data_source: The definition of the datasource to create. + :type data_source: ~search.models.DataSource + :return: The created DataSource + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START create_data_source] + :end-before: [END create_data_source] + :language: python + :dedent: 4 + :caption: Create a Data Source + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.create(data_source, **kwargs) + return result + + @distributed_trace + def create_or_update_datasource(self, data_source, name=None, **kwargs): + # type: (str, DataSource, Optional[str], **Any) -> Dict[str, Any] + """Creates a new datasource or updates a datasource if it already exists. + + :param name: The name of the datasource to create or update. + :type name: str + :param data_source: The definition of the datasource to create or update. + :type data_source: ~search.models.DataSource + :return: The created DataSource + :rtype: dict + """ + # TODO: access_condition + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + if not name: + name = data_source.name + result = self._client.data_sources.create_or_update(name, data_source, **kwargs) + return result + + @distributed_trace + def get_datasource(self, name, **kwargs): + # type: (str, **Any) -> Dict[str, Any] + """Retrieves a datasource definition. + + :param name: The name of the datasource to retrieve. + :type name: str + :return: The DataSource that is fetched. + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START get_data_source] + :end-before: [END get_data_source] + :language: python + :dedent: 4 + :caption: Retrieve a DataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.get(name, **kwargs) + return result + + @distributed_trace + def get_datasources(self, **kwargs): + # type: (**Any) -> Sequence[DataSource] + """Lists all datasources available for a search service. + + :return: List of all the data sources. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START list_data_source] + :end-before: [END list_data_source] + :language: python + :dedent: 4 + :caption: List all the DataSources + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.list(**kwargs) + return result.data_sources + + @distributed_trace + def delete_datasource(self, name, **kwargs): + # type: (str, **Any) -> None + """Deletes a datasource. + + :param name: The name of the datasource to delete. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/sample_data_source_operations.py + :start-after: [START delete_data_source] + :end-before: [END delete_data_source] + :language: python + :dedent: 4 + :caption: Delete a DataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = self._client.data_sources.delete(name, **kwargs) + return result diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py index 60831b574977..b56c96454f1b 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/_search_service_client_async.py @@ -33,7 +33,7 @@ from ... import Index, AnalyzeResult, AnalyzeRequest -class SearchServiceClient(HeadersMixin): +class SearchServiceClient(HeadersMixin): # pylint: disable=too-many-public-methods """A client to interact with an existing Azure search service. :param endpoint: The URL endpoint of an Azure search service @@ -555,3 +555,109 @@ async def create_or_update_skillset(self, name, **kwargs): ) return await self._client.skillsets.create_or_update(name, skillset, **kwargs) + + @distributed_trace_async + async def create_datasource(self, data_source, **kwargs): + # type: (str, DataSource, **Any) -> Dict[str, Any] + """Creates a new datasource. + :param data_source: The definition of the datasource to create. + :type data_source: ~search.models.DataSource + :return: The created DataSource + :rtype: dict + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START create_data_source_async] + :end-before: [END create_data_source_async] + :language: python + :dedent: 4 + :caption: Create a DataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.create(data_source, **kwargs) + return result + + @distributed_trace_async + async def create_or_update_datasource(self, data_source, name=None, **kwargs): + # type: (str, DataSource, Optional[str], **Any) -> Dict[str, Any] + """Creates a new datasource or updates a datasource if it already exists. + + :param name: The name of the datasource to create or update. + :type name: str + :param data_source: The definition of the datasource to create or update. + :type data_source: ~search.models.DataSource + :return: The created DataSource + :rtype: dict + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + + if not name: + name = data_source.name + result = await self._client.data_sources.create_or_update(name, data_source, **kwargs) + return result + + @distributed_trace_async + async def delete_datasource(self, name, **kwargs): + # type: (str, **Any) -> None + """Deletes a datasource. + + :param name: The name of the datasource to delete. + :type name: str + + :return: None + :rtype: None + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START delete_data_source_async] + :end-before: [END delete_data_source_async] + :language: python + :dedent: 4 + :caption: Delete a DataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.delete(name, **kwargs) + return result + + @distributed_trace_async + async def get_datasource(self, name, **kwargs): + # type: (str, **Any) -> Dict[str, Any] + """Retrieves a datasource definition. + + :param name: The name of the datasource to retrieve. + :type name: str + :return: The DataSource that is fetched. + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START get_data_source_async] + :end-before: [END get_data_source_async] + :language: python + :dedent: 4 + :caption: Retrieve a DataSource + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.get(name, **kwargs) + return result + + @distributed_trace_async + async def get_datasources(self, **kwargs): + # type: (**Any) -> Sequence[DataSource] + """Lists all datasources available for a search service. + + :return: List of all the data sources. + :rtype: `list[dict]` + + .. admonition:: Example: + + .. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py + :start-after: [START list_data_source_async] + :end-before: [END list_data_source_async] + :language: python + :dedent: 4 + :caption: List all DataSources + """ + kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) + result = await self._client.data_sources.list(**kwargs) + return result.data_sources diff --git a/sdk/search/azure-search-documents/samples/async_samples/sample_data_source_operations_async.py b/sdk/search/azure-search-documents/samples/async_samples/sample_data_source_operations_async.py new file mode 100644 index 000000000000..783ba3aecb1e --- /dev/null +++ b/sdk/search/azure-search-documents/samples/async_samples/sample_data_source_operations_async.py @@ -0,0 +1,77 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_data_source_operations_async.py +DESCRIPTION: + This sample demonstrates how to get, create, update, or delete a Synonym Map. +USAGE: + python sample_data_source_operations_async.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_SEARCH_SERVICE_ENDPOINT - the endpoint of your Azure Cognitive Search service + 2) AZURE_SEARCH_API_KEY - your search API key +""" + +import asyncio +import os + +service_endpoint = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT") +key = os.getenv("AZURE_SEARCH_API_KEY") +connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + +from azure.core.credentials import AzureKeyCredential +from azure.search.documents import DataSource, DataContainer, DataSourceCredentials +from azure.search.documents.aio import SearchServiceClient + +service_client = SearchServiceClient(service_endpoint, AzureKeyCredential(key)) + +async def create_data_source(): + # [START create_data_source_async] + credentials = DataSourceCredentials(connection_string=connection_string) + container = DataContainer(name='searchcontainer') + data_source = DataSource(name="async-sample-datasource", type="azureblob", credentials=credentials, container=container) + async with service_client: + result = await service_client.create_datasource(data_source) + print("Create new Data Source - async-sample-datasource") + # [END create_data_source_async] + +async def list_data_sources(): + # [START list_data_source_async] + async with service_client: + result = await service_client.get_datasources() + names = [x.name for x in result] + print("Found {} Data Sources in the service: {}".format(len(result), ", ".join(names))) + # [END list_data_source_async] + +async def get_data_source(): + # [START get_data_source_async] + async with service_client: + result = await service_client.get_datasource("async-sample-datasource") + print("Retrived Data Source 'async-sample-datasource'") + return result + # [END get_data_source_async] + +async def delete_data_source(): + # [START delete_data_source_async] + async with service_client: + service_client.delete_datasource("async-sample-datasource") + print("Data Source 'async-sample-datasource' successfully deleted") + # [END delete_data_source_async] + +async def main(): + await create_data_source() + await list_data_sources() + await get_data_source() + await delete_data_source() + await service_client.close() + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) + loop.close() diff --git a/sdk/search/azure-search-documents/samples/sample_data_source_operations.py b/sdk/search/azure-search-documents/samples/sample_data_source_operations.py new file mode 100644 index 000000000000..38aac89cdc11 --- /dev/null +++ b/sdk/search/azure-search-documents/samples/sample_data_source_operations.py @@ -0,0 +1,65 @@ +# coding: utf-8 + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +""" +FILE: sample_data_source_operations.py +DESCRIPTION: + This sample demonstrates how to get, create, update, or delete a Data Source. +USAGE: + python sample_data_source_operations.py + + Set the environment variables with your own values before running the sample: + 1) AZURE_SEARCH_SERVICE_ENDPOINT - the endpoint of your Azure Cognitive Search service + 2) AZURE_SEARCH_API_KEY - your search API key +""" + +import os + +service_endpoint = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT") +key = os.getenv("AZURE_SEARCH_API_KEY") +connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + +from azure.core.credentials import AzureKeyCredential +from azure.search.documents import SearchServiceClient, DataSource, DataContainer, DataSourceCredentials + +service_client = SearchServiceClient(service_endpoint, AzureKeyCredential(key)) + +def create_data_source(): + # [START create_data_source] + credentials = DataSourceCredentials(connection_string=connection_string) + container = DataContainer(name='searchcontainer') + data_source = DataSource(name="sample-datasource", type="azureblob", credentials=credentials, container=container) + result = service_client.create_datasource(data_source) + print(result) + print("Create new Data Source - sample-datasource") + # [END create_data_source] + +def list_data_sources(): + # [START list_data_source] + result = service_client.get_datasources() + names = [ds.name for ds in result] + print("Found {} Data Sources in the service: {}".format(len(result), ", ".join(names))) + # [END list_data_source] + +def get_data_source(): + # [START get_data_source] + result = service_client.get_datasource("sample-datasource") + print("Retrived Data Source 'sample-datasource'") + # [END get_data_source] + +def delete_data_source(): + # [START delete_data_source] + service_client.delete_datasource("sample-datasource") + print("Data Source 'sample-datasource' successfully deleted") + # [END delete_data_source] + +if __name__ == '__main__': + create_data_source() + list_data_sources() + get_data_source() + delete_data_source() diff --git a/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_datasource_async.yaml b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_datasource_async.yaml new file mode 100644 index 000000000000..e50881866f27 --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_datasource_async.yaml @@ -0,0 +1,47 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - D59D8B92A259BB430B2DD58824AC5800 + method: POST + uri: https://search386b1565.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search386b1565.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B55FC94A6\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '370' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:28 GMT + elapsed-time: '36' + etag: W/"0x8D7E76B55FC94A6" + expires: '-1' + location: https://search386b1565.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 71366868-8547-11ea-a573-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search386b1565.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +version: 1 diff --git a/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_or_update_datasource_async.yaml b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_or_update_datasource_async.yaml new file mode 100644 index 000000000000..1644b0223374 --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_create_or_update_datasource_async.yaml @@ -0,0 +1,213 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - F34B15CF6FD4025C37227F974B55974F + method: POST + uri: https://search251c1987.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search251c1987.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B62D671B9\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '370' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:50 GMT + elapsed-time: '33' + etag: W/"0x8D7E76B62D671B9" + expires: '-1' + location: https://search251c1987.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 7e1e1b12-8547-11ea-a5c9-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search251c1987.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - F34B15CF6FD4025C37227F974B55974F + method: GET + uri: https://search251c1987.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search251c1987.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B62D671B9\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '366' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:50 GMT + elapsed-time: '52' + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 7e431602-8547-11ea-8aae-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search251c1987.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: '{"name": "sample-datasource", "description": "updated", "type": "azureblob", + "credentials": {"connectionString": "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '345' + Content-Type: + - application/json + Prefer: + - return=representation + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - F34B15CF6FD4025C37227F974B55974F + method: PUT + uri: https://search251c1987.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search251c1987.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B62F151BA\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '366' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:50 GMT + elapsed-time: '35' + etag: W/"0x8D7E76B62F151BA" + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 7e51ffba-8547-11ea-afc8-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search251c1987.search.windows.net + - /datasources('sample-datasource') + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - F34B15CF6FD4025C37227F974B55974F + method: GET + uri: https://search251c1987.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search251c1987.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B62F151BA\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '372' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:50 GMT + elapsed-time: '9' + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 7e5dde9c-8547-11ea-96e1-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search251c1987.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - F34B15CF6FD4025C37227F974B55974F + method: GET + uri: https://search251c1987.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search251c1987.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B62F151BA\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '366' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:47:50 GMT + elapsed-time: '5' + etag: W/"0x8D7E76B62F151BA" + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 7e65b04c-8547-11ea-8ac9-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search251c1987.search.windows.net + - /datasources('sample-datasource') + - api-version=2019-05-06-Preview + - '' +version: 1 diff --git a/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_delete_datasource_async.yaml b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_delete_datasource_async.yaml new file mode 100644 index 000000000000..c38fd450c8f4 --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_delete_datasource_async.yaml @@ -0,0 +1,158 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - B9AD3FA1A5A00F28630A84A8C57C2595 + method: POST + uri: https://search38471564.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search38471564.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B7020FF97\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '370' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:48:12 GMT + elapsed-time: '52' + etag: W/"0x8D7E76B7020FF97" + expires: '-1' + location: https://search38471564.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 8b696eba-8547-11ea-a514-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search38471564.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - B9AD3FA1A5A00F28630A84A8C57C2595 + method: GET + uri: https://search38471564.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search38471564.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B7020FF97\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '366' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:48:12 GMT + elapsed-time: '22' + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 8b8d7e18-8547-11ea-8d15-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search38471564.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - B9AD3FA1A5A00F28630A84A8C57C2595 + method: DELETE + uri: https://search38471564.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '' + headers: + cache-control: no-cache + date: Thu, 23 Apr 2020 09:48:12 GMT + elapsed-time: '26' + expires: '-1' + pragma: no-cache + request-id: 8b97b236-8547-11ea-87a8-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 204 + message: No Content + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search38471564.search.windows.net + - /datasources('sample-datasource') + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - B9AD3FA1A5A00F28630A84A8C57C2595 + method: GET + uri: https://search38471564.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search38471564.search.windows.net/$metadata#datasources","value":[]}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '202' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:48:12 GMT + elapsed-time: '5' + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 8ba2572e-8547-11ea-b58f-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search38471564.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +version: 1 diff --git a/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_get_datasource_async.yaml b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_get_datasource_async.yaml new file mode 100644 index 000000000000..b82b33d192ff --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_get_datasource_async.yaml @@ -0,0 +1,87 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 51E1A53A641E5EE7069C83D5F23E7C4C + method: POST + uri: https://searchfa0d1431.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchfa0d1431.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B7D1B6295\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '370' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:48:33 GMT + elapsed-time: '38' + etag: W/"0x8D7E76B7D1B6295" + expires: '-1' + location: https://searchfa0d1431.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 98587b54-8547-11ea-8bd6-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - searchfa0d1431.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 51E1A53A641E5EE7069C83D5F23E7C4C + method: GET + uri: https://searchfa0d1431.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchfa0d1431.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B7D1B6295\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '359' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:48:33 GMT + elapsed-time: '8' + etag: W/"0x8D7E76B7D1B6295" + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: 9888909e-8547-11ea-9e77-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - searchfa0d1431.search.windows.net + - /datasources('sample-datasource') + - api-version=2019-05-06-Preview + - '' +version: 1 diff --git a/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_list_datasource_async.yaml b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_list_datasource_async.yaml new file mode 100644 index 000000000000..5f17c5745c8d --- /dev/null +++ b/sdk/search/azure-search-documents/tests/async_tests/recordings/test_service_live_async.test_list_datasource_async.yaml @@ -0,0 +1,131 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 722B42706843D7367FB3BE7F15D7B37B + method: POST + uri: https://search101414ad.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search101414ad.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B919F686C\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '370' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:49:08 GMT + elapsed-time: '74' + etag: W/"0x8D7E76B919F686C" + expires: '-1' + location: https://search101414ad.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: acde73ac-8547-11ea-8db0-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search101414ad.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: '{"name": "another-sample", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Content-Length: + - '316' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 722B42706843D7367FB3BE7F15D7B37B + method: POST + uri: https://search101414ad.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search101414ad.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B91AEAD78\"","name":"another-sample","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: no-cache + content-length: '367' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:49:08 GMT + elapsed-time: '44' + etag: W/"0x8D7E76B91AEAD78" + expires: '-1' + location: https://search101414ad.search.windows.net/datasources('another-sample')?api-version=2019-05-06-Preview + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: ad0c1cfe-8547-11ea-b589-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + status: + code: 201 + message: Created + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search101414ad.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 722B42706843D7367FB3BE7F15D7B37B + method: GET + uri: https://search101414ad.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search101414ad.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B91AEAD78\"","name":"another-sample","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null},{"@odata.etag":"\"0x8D7E76B919F686C\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: no-cache + content-encoding: gzip + content-length: '390' + content-type: application/json; odata.metadata=minimal + date: Thu, 23 Apr 2020 09:49:08 GMT + elapsed-time: '14' + expires: '-1' + odata-version: '4.0' + pragma: no-cache + preference-applied: odata.include-annotations="*" + request-id: ad1b79f4-8547-11ea-9015-2816a845e8c6 + strict-transport-security: max-age=15724800; includeSubDomains + vary: Accept-Encoding + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - https + - search101414ad.search.windows.net + - /datasources + - api-version=2019-05-06-Preview + - '' +version: 1 diff --git a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py index e89c5dadbb87..0e8374f70d1a 100644 --- a/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py +++ b/sdk/search/azure-search-documents/tests/async_tests/test_service_live_async.py @@ -30,6 +30,9 @@ SearchServiceClient, ScoringProfile, Skillset, + DataSourceCredentials, + DataSource, + DataContainer ) from azure.search.documents.aio import SearchServiceClient @@ -37,6 +40,7 @@ SCHEMA = open(join(CWD, "..", "hotel_schema.json")).read() BATCH = json.load(open(join(CWD, "..", "hotel_small.json"), encoding='utf-8')) TIME_TO_SLEEP = 5 +CONNECTION_STRING = 'DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net' def await_prepared_test(test_fn): """Synchronous wrapper for async test methods. Used to avoid making changes @@ -53,6 +57,17 @@ def run(test_class_instance, *args, **kwargs): class SearchClientTest(AzureMgmtTestCase): + def _create_datasource(self, name="sample-datasource"): + credentials = DataSourceCredentials(connection_string=CONNECTION_STRING) + container = DataContainer(name='searchcontainer') + data_source = DataSource( + name=name, + type="azureblob", + credentials=credentials, + container=container + ) + return data_source + @ResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() async def test_get_service_statistics(self, api_key, endpoint, **kwargs): @@ -364,4 +379,58 @@ async def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_ result = await client.get_skillset("test-ss") assert isinstance(result, Skillset) assert result.name == "test-ss" - assert result.description == "desc2" \ No newline at end of file + assert result.description == "desc2" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + async def test_create_datasource_async(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + result = await client.create_datasource(data_source) + assert result.name == "sample-datasource" + assert result.type == "azureblob" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + async def test_delete_datasource_async(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + result = await client.create_datasource(data_source) + assert len(await client.get_datasources()) == 1 + await client.delete_datasource("sample-datasource") + assert len(await client.get_datasources()) == 0 + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + async def test_get_datasource_async(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + created = await client.create_datasource(data_source) + result = await client.get_datasource("sample-datasource") + assert result.name == "sample-datasource" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + async def test_list_datasource_async(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source1 = self._create_datasource() + data_source2 = self._create_datasource(name="another-sample") + created1 = await client.create_datasource(data_source1) + created2 = await client.create_datasource(data_source2) + result = await client.get_datasources() + assert isinstance(result, list) + assert set(x.name for x in result) == {"sample-datasource", "another-sample"} + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + async def test_create_or_update_datasource_async(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + created = await client.create_datasource(data_source) + assert len(await client.get_datasources()) == 1 + data_source.description = "updated" + await client.create_or_update_datasource(data_source) + assert len(await client.get_datasources()) == 1 + result = await client.get_datasource("sample-datasource") + assert result.name == "sample-datasource" + assert result.description == "updated" diff --git a/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_datasource.yaml b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_datasource.yaml new file mode 100644 index 000000000000..625dd6f0247c --- /dev/null +++ b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_datasource.yaml @@ -0,0 +1,56 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 6EE1AFB6E75621F4C0D8091DB40240CE + method: POST + uri: https://search51c7106b.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search51c7106b.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B0EE7CAE6\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '370' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:29 GMT + elapsed-time: + - '59' + etag: + - W/"0x8D7E76B0EE7CAE6" + expires: + - '-1' + location: + - https://search51c7106b.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 29fadd68-8547-11ea-946b-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +version: 1 diff --git a/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_or_update_datasource.yaml b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_or_update_datasource.yaml new file mode 100644 index 000000000000..b79b92c85201 --- /dev/null +++ b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_create_or_update_datasource.yaml @@ -0,0 +1,252 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - E4BC53B804F034F1EAA7589A86038793 + method: POST + uri: https://searchcca148d.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchcca148d.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B1CF33474\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '369' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:52 GMT + elapsed-time: + - '84' + etag: + - W/"0x8D7E76B1CF33474" + expires: + - '-1' + location: + - https://searchcca148d.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 381dde6e-8547-11ea-9c14-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - E4BC53B804F034F1EAA7589A86038793 + method: GET + uri: https://searchcca148d.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchcca148d.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B1CF33474\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: + - no-cache + content-length: + - '373' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:52 GMT + elapsed-time: + - '19' + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 386479e2-8547-11ea-b642-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +- request: + body: '{"name": "sample-datasource", "description": "updated", "type": "azureblob", + "credentials": {"connectionString": "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '345' + Content-Type: + - application/json + Prefer: + - return=representation + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - E4BC53B804F034F1EAA7589A86038793 + method: PUT + uri: https://searchcca148d.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchcca148d.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B1D1AC0E6\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '374' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:52 GMT + elapsed-time: + - '34' + etag: + - W/"0x8D7E76B1D1AC0E6" + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 3873ff9c-8547-11ea-bd5b-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - E4BC53B804F034F1EAA7589A86038793 + method: GET + uri: https://searchcca148d.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchcca148d.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B1D1AC0E6\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: + - no-cache + content-length: + - '378' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:52 GMT + elapsed-time: + - '9' + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 38872d8a-8547-11ea-9731-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - E4BC53B804F034F1EAA7589A86038793 + method: GET + uri: https://searchcca148d.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://searchcca148d.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B1D1AC0E6\"","name":"sample-datasource","description":"updated","type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '374' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:45:52 GMT + elapsed-time: + - '6' + etag: + - W/"0x8D7E76B1D1AC0E6" + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 389554ba-8547-11ea-8993-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_delete_datasource.yaml b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_delete_datasource.yaml new file mode 100644 index 000000000000..0a5151847aef --- /dev/null +++ b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_delete_datasource.yaml @@ -0,0 +1,186 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8D1DA77C1D33A3A2C2E202F91D866E5C + method: POST + uri: https://search51a9106a.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search51a9106a.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B266466FE\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '370' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:08 GMT + elapsed-time: + - '51' + etag: + - W/"0x8D7E76B266466FE" + expires: + - '-1' + location: + - https://search51a9106a.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 419d323e-8547-11ea-a215-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8D1DA77C1D33A3A2C2E202F91D866E5C + method: GET + uri: https://search51a9106a.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search51a9106a.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B266466FE\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: + - no-cache + content-length: + - '374' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:08 GMT + elapsed-time: + - '18' + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 41d079fa-8547-11ea-9f01-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8D1DA77C1D33A3A2C2E202F91D866E5C + method: DELETE + uri: https://search51a9106a.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '' + headers: + cache-control: + - no-cache + date: + - Thu, 23 Apr 2020 09:46:08 GMT + elapsed-time: + - '54' + expires: + - '-1' + pragma: + - no-cache + request-id: + - 41dff18c-8547-11ea-8d51-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 204 + message: No Content +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8D1DA77C1D33A3A2C2E202F91D866E5C + method: GET + uri: https://search51a9106a.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search51a9106a.search.windows.net/$metadata#datasources","value":[]}' + headers: + cache-control: + - no-cache + content-length: + - '95' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:08 GMT + elapsed-time: + - '6' + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 41f5654a-8547-11ea-a7a9-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_get_datasource.yaml b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_get_datasource.yaml new file mode 100644 index 000000000000..b6007dee5a8d --- /dev/null +++ b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_get_datasource.yaml @@ -0,0 +1,104 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8CD7256132FD7881C2091E30F89DA85F + method: POST + uri: https://search22270f37.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search22270f37.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B3349695F\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '370' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:30 GMT + elapsed-time: + - '49' + etag: + - W/"0x8D7E76B3349695F" + expires: + - '-1' + location: + - https://search22270f37.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 4e608d6e-8547-11ea-8181-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 8CD7256132FD7881C2091E30F89DA85F + method: GET + uri: https://search22270f37.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search22270f37.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B3349695F\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '370' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:30 GMT + elapsed-time: + - '11' + etag: + - W/"0x8D7E76B3349695F" + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 4eb64b08-8547-11ea-a135-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_list_datasource.yaml b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_list_datasource.yaml new file mode 100644 index 000000000000..d7b8b79ef0cd --- /dev/null +++ b/sdk/search/azure-search-documents/tests/recordings/test_service_live.test_list_datasource.yaml @@ -0,0 +1,156 @@ +interactions: +- request: + body: '{"name": "sample-datasource", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '319' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 886DBEB78F10DFC648810BF835D2FBCD + method: POST + uri: https://search32ba0fb3.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search32ba0fb3.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B3C7A050D\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '370' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:45 GMT + elapsed-time: + - '27' + etag: + - W/"0x8D7E76B3C7A050D" + expires: + - '-1' + location: + - https://search32ba0fb3.search.windows.net/datasources('sample-datasource')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 57b61746-8547-11ea-aa62-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +- request: + body: '{"name": "another-sample", "type": "azureblob", "credentials": {"connectionString": + "DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net"}, + "container": {"name": "searchcontainer"}}' + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '316' + Content-Type: + - application/json + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 886DBEB78F10DFC648810BF835D2FBCD + method: POST + uri: https://search32ba0fb3.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search32ba0fb3.search.windows.net/$metadata#datasources/$entity","@odata.etag":"\"0x8D7E76B3C8B1F58\"","name":"another-sample","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}' + headers: + cache-control: + - no-cache + content-length: + - '367' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:45 GMT + elapsed-time: + - '28' + etag: + - W/"0x8D7E76B3C8B1F58" + expires: + - '-1' + location: + - https://search32ba0fb3.search.windows.net/datasources('another-sample')?api-version=2019-05-06-Preview + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 57e5e03e-8547-11ea-87b0-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - application/json;odata.metadata=minimal + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - azsdk-python-search-documents/1.0.0b3 Python/3.7.3 (Windows-10-10.0.17763-SP0) + api-key: + - 886DBEB78F10DFC648810BF835D2FBCD + method: GET + uri: https://search32ba0fb3.search.windows.net/datasources?api-version=2019-05-06-Preview + response: + body: + string: '{"@odata.context":"https://search32ba0fb3.search.windows.net/$metadata#datasources","value":[{"@odata.etag":"\"0x8D7E76B3C8B1F58\"","name":"another-sample","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null},{"@odata.etag":"\"0x8D7E76B3C7A050D\"","name":"sample-datasource","description":null,"type":"azureblob","subtype":null,"credentials":{"connectionString":null},"container":{"name":"searchcontainer","query":null},"dataChangeDetectionPolicy":null,"dataDeletionDetectionPolicy":null}]}' + headers: + cache-control: + - no-cache + content-length: + - '651' + content-type: + - application/json; odata.metadata=minimal + date: + - Thu, 23 Apr 2020 09:46:45 GMT + elapsed-time: + - '32' + expires: + - '-1' + odata-version: + - '4.0' + pragma: + - no-cache + preference-applied: + - odata.include-annotations="*" + request-id: + - 57f6c49c-8547-11ea-a5de-2816a845e8c6 + strict-transport-security: + - max-age=15724800; includeSubDomains + vary: + - Accept-Encoding + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/search/azure-search-documents/tests/test_service_live.py b/sdk/search/azure-search-documents/tests/test_service_live.py index dac18cb3da68..a644dd18138f 100644 --- a/sdk/search/azure-search-documents/tests/test_service_live.py +++ b/sdk/search/azure-search-documents/tests/test_service_live.py @@ -27,14 +27,29 @@ SearchServiceClient, ScoringProfile, Skillset, + DataSourceCredentials, + DataSource, + DataContainer ) CWD = dirname(realpath(__file__)) SCHEMA = open(join(CWD, "hotel_schema.json")).read() BATCH = json.load(open(join(CWD, "hotel_small.json"))) TIME_TO_SLEEP = 5 +CONNECTION_STRING = 'DefaultEndpointsProtocol=https;AccountName=storagename;AccountKey=NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg==;EndpointSuffix=core.windows.net' class SearchClientTest(AzureMgmtTestCase): + def _create_datasource(self, name="sample-datasource"): + credentials = DataSourceCredentials(connection_string=CONNECTION_STRING) + container = DataContainer(name='searchcontainer') + data_source = DataSource( + name=name, + type="azureblob", + credentials=credentials, + container=container + ) + return data_source + @ResourceGroupPreparer(random_name_enabled=True) @SearchServicePreparer() def test_get_service_statistics(self, api_key, endpoint, **kwargs): @@ -344,4 +359,58 @@ def test_create_or_update_skillset_inplace(self, api_key, endpoint, index_name, result = client.get_skillset("test-ss") assert isinstance(result, Skillset) assert result.name == "test-ss" - assert result.description == "desc2" \ No newline at end of file + assert result.description == "desc2" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + def test_create_datasource(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + result = client.create_datasource(data_source) + assert result.name == "sample-datasource" + assert result.type == "azureblob" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + def test_delete_datasource(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + result = client.create_datasource(data_source) + assert len(client.get_datasources()) == 1 + client.delete_datasource("sample-datasource") + assert len(client.get_datasources()) == 0 + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + def test_get_datasource(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + created = client.create_datasource(data_source) + result = client.get_datasource("sample-datasource") + assert result.name == "sample-datasource" + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + def test_list_datasource(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source1 = self._create_datasource() + data_source2 = self._create_datasource(name="another-sample") + created1 = client.create_datasource(data_source1) + created2 = client.create_datasource(data_source2) + result = client.get_datasources() + assert isinstance(result, list) + assert set(x.name for x in result) == {"sample-datasource", "another-sample"} + + @ResourceGroupPreparer(random_name_enabled=True) + @SearchServicePreparer(schema=SCHEMA, index_batch=BATCH) + def test_create_or_update_datasource(self, api_key, endpoint, index_name, **kwargs): + client = SearchServiceClient(endpoint, AzureKeyCredential(api_key)) + data_source = self._create_datasource() + created = client.create_datasource(data_source) + assert len(client.get_datasources()) == 1 + data_source.description = "updated" + client.create_or_update_datasource(data_source) + assert len(client.get_datasources()) == 1 + result = client.get_datasource("sample-datasource") + assert result.name == "sample-datasource" + assert result.description == "updated"