def test_request_too_large_error(self): with mock.patch.object( SearchClient, "_index_documents_actions", side_effect=RequestEntityTooLargeError("Error")): client = SearchClient("endpoint", "index name", CREDENTIAL) batch = IndexDocumentsBatch() batch.add_upload_actions("upload1") with pytest.raises(RequestEntityTooLargeError): client.index_documents(batch, extra="foo")
def test_index_documents(self, mock_index): client = SearchClient("endpoint", "index name", CREDENTIAL) batch = IndexDocumentsBatch() actions = batch.add_upload_actions("upload1") assert len(actions) == 1 for x in actions: assert x.action_type == "upload" actions = batch.add_delete_actions("delete1", "delete2") assert len(actions) == 2 for x in actions: assert x.action_type == "delete" actions = batch.add_merge_actions(["merge1", "merge2", "merge3"]) for x in actions: assert x.action_type == "merge" actions = batch.add_merge_or_upload_actions("merge_or_upload1") for x in actions: assert x.action_type == "mergeOrUpload" client.index_documents(batch, extra="foo") assert mock_index.called assert mock_index.call_args[0] == () assert len(mock_index.call_args[1]) == 4 assert mock_index.call_args[1]["headers"] == client._headers assert mock_index.call_args[1]["extra"] == "foo"
def test_index_documents(self, mock_index): client = SearchClient("endpoint", "index name", CREDENTIAL) batch = IndexDocumentsBatch() batch.add_upload_actions("upload1") batch.add_delete_actions("delete1", "delete2") batch.add_merge_actions(["merge1", "merge2", "merge3"]) batch.add_merge_or_upload_actions("merge_or_upload1") client.index_documents(batch, extra="foo") assert mock_index.called assert mock_index.call_args[0] == () assert len(mock_index.call_args[1]) == 3 assert mock_index.call_args[1]["headers"] == client._headers assert mock_index.call_args[1]["extra"] == "foo" index_documents = mock_index.call_args[1]["batch"] assert isinstance(index_documents, IndexBatch) assert index_documents.actions == batch.actions