def test_list_datasource(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source_connection1 = self._create_data_source_connection() data_source_connection2 = self._create_data_source_connection( name="another-sample") created1 = client.create_data_source_connection( data_source_connection1) created2 = client.create_data_source_connection( data_source_connection2) result = client.get_data_source_connections() assert isinstance(result, list) assert set(x.name for x in result) == {"sample-datasource", "another-sample"}
def test_delete_datasource(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source_connection = self._create_data_source_connection() result = client.create_data_source_connection(data_source_connection) assert len(client.get_data_source_connections()) == 1 client.delete_data_source_connection("sample-datasource") assert len(client.get_data_source_connections()) == 0
def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sample-datasource", id_name="hotels"): con_str = self.settings.AZURE_STORAGE_CONNECTION_STRING self.scrubber.register_name_pair(con_str, 'connection_string') container = SearchIndexerDataContainer(name='searchcontainer') data_source_connection = SearchIndexerDataSourceConnection( name=ds_name, type="azureblob", connection_string=con_str, container=container) client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) ds = client.create_data_source_connection(data_source_connection) index_name = id_name fields = [{ "name": "hotelId", "type": "Edm.String", "key": True, "searchable": False }] index = SearchIndex(name=index_name, fields=fields) ind = SearchIndexClient( endpoint, AzureKeyCredential(api_key)).create_index(index) return SearchIndexer(name=name, data_source_name=ds.name, target_index_name=ind.name)
def test_create_or_update_datasource(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source_connection = self._create_data_source_connection() created = client.create_data_source_connection(data_source_connection) assert len(client.get_data_source_connections()) == 1 data_source_connection.description = "updated" client.create_or_update_data_source_connection(data_source_connection) assert len(client.get_data_source_connections()) == 1 result = client.get_data_source_connection("sample-datasource") assert result.name == "sample-datasource" assert result.description == "updated"
def _create_datasource(): # Here we create a datasource. As mentioned in the description we have stored it in # "searchcontainer" ds_client = SearchIndexerClient(service_endpoint, AzureKeyCredential(key)) container = SearchIndexerDataContainer(name='searchcontainer') data_source_connection = SearchIndexerDataSourceConnection( name="hotel-datasource", type="azureblob", connection_string=connection_string, container=container ) data_source = ds_client.create_data_source_connection(data_source_connection) return data_source
def test_delete_datasource_string_if_unchanged(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source_connection = self._create_data_source_connection() created = client.create_data_source_connection(data_source_connection) etag = created.e_tag # Now update the data source connection data_source_connection.description = "updated" client.create_or_update_data_source_connection(data_source_connection) # prepare data source connection data_source_connection.e_tag = etag # reset to the original data source connection with pytest.raises(ValueError): client.delete_data_source_connection(data_source_connection.name, match_condition=MatchConditions.IfNotModified)
def test_create_datasource(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key)) data_source_connection = self._create_data_source_connection() result = client.create_data_source_connection(data_source_connection) assert result.name == "sample-datasource" assert result.type == "azureblob"