def test_delete_documents_missing(self, api_key, endpoint, index_name, **kwargs): client = SearchClient(endpoint, index_name, AzureKeyCredential(api_key)) batch_client = SearchIndexDocumentBatchingClient( endpoint, index_name, AzureKeyCredential(api_key)) batch_client._batch_size = 2 batch_client.add_delete_actions([{ "hotelId": "1000" }, { "hotelId": "4" }]) batch_client.close() # There can be some lag before a document is searchable if self.is_live: time.sleep(TIME_TO_SLEEP) assert client.get_document_count() == 9 with pytest.raises(HttpResponseError): client.get_document(key="1000") with pytest.raises(HttpResponseError): client.get_document(key="4")
def test_flush_if_needed(self, mock_flush): client = SearchIndexDocumentBatchingClient("endpoint", "index name", CREDENTIAL, window=1000, batch_size=2) client.add_upload_actions(["upload1"]) client.add_delete_actions(["delete1", "delete2"]) assert mock_flush.called client.close()
def test_failed_queue(self): client = SearchIndexDocumentBatchingClient("endpoint", "index name", CREDENTIAL) assert client._index_documents_batch client.add_upload_actions(["upload1"]) client.add_delete_actions(["delete1", "delete2"]) client.add_merge_actions(["merge1", "merge2", "merge3"]) client.add_merge_or_upload_actions(["merge_or_upload1"]) actions = client._index_documents_batch.dequeue_actions() client._index_documents_batch.enqueue_failed_actions(actions) assert len(client.failed_actions) == 7
def test_batch_queue(self): client = SearchIndexDocumentBatchingClient("endpoint", "index name", CREDENTIAL, auto_flush=False) assert client._index_documents_batch client.add_upload_actions(["upload1"]) client.add_delete_actions(["delete1", "delete2"]) client.add_merge_actions(["merge1", "merge2", "merge3"]) client.add_merge_or_upload_actions(["merge_or_upload1"]) assert len(client.actions) == 7 actions = client._index_documents_batch.dequeue_actions() assert len(client.actions) == 0 client._index_documents_batch.enqueue_actions(actions) assert len(client.actions) == 7 actions = client._index_documents_batch.dequeue_actions() assert len(client.actions) == 0 for action in actions: client._index_documents_batch.enqueue_action(action) assert len(client.actions) == 7
def test_process_if_needed(self, mock_process_if_needed): client = SearchIndexDocumentBatchingClient("endpoint", "index name", CREDENTIAL, window=1000, auto_flush=False) client.add_upload_actions(["upload1"]) client.add_delete_actions(["delete1", "delete2"]) assert mock_process_if_needed.called