def test_upload_documents_existing(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexClient( endpoint, index_name, AzureKeyCredential(api_key) ) DOCUMENTS = [ {"hotelId": "1000", "rating": 5, "rooms": [], "hotelName": "Azure Inn"}, {"hotelId": "3", "rating": 4, "rooms": [], "hotelName": "Redmond Hotel"}, ] results = client.upload_documents(DOCUMENTS) assert len(results) == 2 assert set(x.status_code for x in results) == {200, 201}
def test_upload_documents_new(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexClient( endpoint, index_name, SearchApiKeyCredential(api_key) ) DOCUMENTS = [ {"hotelId": "1000", "rating": 5, "rooms": [], "hotelName": "Azure Inn"}, {"hotelId": "1001", "rating": 4, "rooms": [], "hotelName": "Redmond Hotel"}, ] results = client.upload_documents(DOCUMENTS) assert len(results) == 2 assert set(x.status_code for x in results) == {201} # There can be some lag before a document is searchable time.sleep(3) assert client.get_document_count() == 12 for doc in DOCUMENTS: result = client.get_document(key=doc["hotelId"]) assert result["hotelId"] == doc["hotelId"] assert result["hotelName"] == doc["hotelName"] assert result["rating"] == doc["rating"] assert result["rooms"] == doc["rooms"]