def test_cross_app_copy_index(self): rule = F.rule(object_id='one') synonym = F.synonym(object_id='one') responses = [ self.index.save_object({'objectID': 'one'}), self.index.save_rule(rule), self.index.save_synonym(synonym), self.index.set_settings({'searchableAttributes': ['objectID']}) ] MultipleResponse(responses).wait() AccountClient.copy_index(self.index, self.index2).wait() # Assert objects got copied res = self.index2.search('') self.assertEqual(len(res['hits']), 1) self.assertEqual(res['hits'][0], {'objectID': 'one'}) # Assert settings got copied settings = self.index2.get_settings() self.assertEqual(settings['searchableAttributes'], ['objectID']) # Assert synonyms got copied self.assertEqual(self.index2.get_rule('one'), rule) # Assert synonyms got copied self.assertEqual(self.index2.get_synonym('one'), synonym) # Assert that copying again fails because index already exists with self.assertRaises(AlgoliaException) as _: AccountClient.copy_index(self.index, self.index2)
def test_copy_index_applications_must_be_different(client_1): index_1 = client_1.init_index('copy_index') index_2 = client_1.init_index('copy_index_2') with pytest.raises(AlgoliaException): AccountClient.copy_index(index_1, index_2)
def test_copy_index_copy_the_index_and_destination_must_not_exist(index_1, index_2): responses = [ index_1.save_object({'objectID': 'one'}), index_1.batch_rules([rule_stub('one')]), index_1.batch_synonyms([synonym_stub('one')]), index_1.set_settings({'searchableAttributes': ['objectID']}) ] for response in responses: index_1.wait_task(response['taskID']) responses = AccountClient.copy_index(index_1, index_2) for response in responses: index_2.wait_task(response['taskID']) # Assert objects got copied res = index_2.search('') assert len(res['hits']) == 1 assert res['hits'][0] == {'objectID': 'one'} # Assert settings got copied settings = index_2.get_settings() assert settings['searchableAttributes'] == ['objectID'] # Assert synonyms got copied rule = index_2.read_rule('one') assert rule == rule_stub('one') # Assert synonyms got copied synonym = index_2.get_synonym('one') assert synonym == synonym_stub('one') # Assert that copying again fails because index already exists with pytest.raises(AlgoliaException): AccountClient.copy_index(index_1, index_2)
def test_can_not_copy_index_from_same_account(self): index1 = F.index('foo') index2 = F.index('bar') # Assert that copying indexes of same application with self.assertRaises(AlgoliaException) as _: AccountClient.copy_index(index1, index2)
def test_can_not_copy_index_from_same_account(self): client = F.search_client() index1 = F.index(client, "foo") index2 = F.index(client, "bar") # Assert that copying indexes of same application with self.assertRaises(AlgoliaException) as _: AccountClient.copy_index(index1, index2)
def test_cross_app_copy_index(self): rule = F.rule(object_id="one") synonym = F.synonym(object_id="one") responses = [ self.index.save_object({"objectID": "one"}), self.index.save_rule(rule), self.index.save_synonym(synonym), self.index.set_settings({"searchableAttributes": ["objectID"]}), ] MultipleResponse(responses).wait() AccountClient.copy_index(self.index, self.index2).wait() # Assert objects got copied res = self.index2.search("") self.assertEqual(len(res["hits"]), 1) self.assertEqual(res["hits"][0], {"objectID": "one"}) # Assert settings got copied settings = self.index2.get_settings() self.assertEqual(settings["searchableAttributes"], ["objectID"]) # Assert rules got copied self.assertEqual(rule_without_metadata(self.index2.get_rule("one")), rule) # Assert synonyms got copied list_synonyms1 = [synonym for synonym in self.index.browse_synonyms()] list_synonyms2 = [synonym for synonym in self.index2.browse_synonyms()] self.assertEqual(list_synonyms1, list_synonyms2) # Assert synomys are the same self.assertEqual(self.index2.get_synonym("one"), synonym) # Assert that copying again fails because index already exists with self.assertRaises(AlgoliaException) as _: AccountClient.copy_index(self.index, self.index2)