def test_list_indexes(self): ims_cli = self.ims_cli rr_cli = self.rr_cli index_name = self.index_name #====================================== # Index Pool #====================================== indexes = [ Index(name='first'), Index(name='second'), Index(name='third') ] id_pool = list() for index in indexes: id_pool.append(rr_cli.create(index)[0]) names = set(ims_cli.list_indexes().keys()) self.assertTrue(names == set(['first', 'second', 'third'])) #====================================== # Clean up #====================================== for index_id in id_pool: rr_cli.delete(index_id)
def test_find_indexes(self): ims_cli = self.ims_cli rr_cli = self.rr_cli index_name = self.index_name #====================================== # Index Pool #====================================== indexes = [ Index(name='first'), Index(name='second'), Index(name='third') ] id_pool = list() for index in indexes: id_pool.append(rr_cli.create(index)[0]) index_id = ims_cli.find_indexes(index_name='second') index = ims_cli.read_index(index_id) self.assertTrue(index.name == 'second') #====================================== # Clean up #====================================== for index_id in id_pool: rr_cli.delete(index_id)
def test_catalog_field_exclusion(self): half_match = Index(name='half_match', options=SearchOptions(attribute_match=['one'])) full_match = Index(name='full_match', options=SearchOptions(attribute_match=['one','two'])) half_match_id, _ = self.rr_cli.create(half_match) full_match_id, _ = self.rr_cli.create(full_match) catalog_id = self.cms_cli.create_catalog('test_cat', keywords=['one','two']) index_list = self.cms_cli.list_indexes(catalog_id, id_only=True) self.assertTrue(index_list == [full_match_id])
def test_create_catalog_matching(self): #------------------------------------------- # Tests catalog creation and index matching #------------------------------------------- indexes = [ Index(name='index1'), Index(name='index2'), Index(name='index3') ] indexes[0].options = SearchOptions( **{ # Devices 'attribute_match': ['name', 'model', 'serial'], 'geo_fields': ['index_location'] }) indexes[1].options = SearchOptions( **{ # BankAccount 'attribute_match': ['name', 'description', 'owner'], 'range_fields': ['cash_balance'] }) indexes[2].options = SearchOptions( **{ # Hybrid 'attribute_match': ['name'], 'range_fields': ['arc'], 'geo_fields': ['index_location'] }) index_ids = list([self.rr_cli.create(i)[0] for i in indexes]) devices_catalog_id = self.cms_cli.create_catalog( 'devices_catalog', ['model']) self.assertTrue( index_ids[0] in self.cms_cli.list_indexes(devices_catalog_id), 'The catalog did\'nt match the correct index.') accounts_catalog_id = self.cms_cli.create_catalog( 'accounts_catalog', ['cash_balance']) self.assertTrue( index_ids[1] in self.cms_cli.list_indexes(accounts_catalog_id), 'The catalog did\'nt match the correct index.') geo_catalog_id = self.cms_cli.create_catalog('geo_catalog', ['index_location']) self.assertTrue( index_ids[2] in self.cms_cli.list_indexes(geo_catalog_id), 'The catalog did\'nt match the correct index.') names_catalog_id = self.cms_cli.create_catalog('names_catalog', ['name']) names_list = self.cms_cli.list_indexes(names_catalog_id) for i in index_ids: self.assertIn(i, names_list)
def test_delete_index(self): ims_cli = self.ims_cli rr_cli = self.rr_cli index_name = self.index_name index_res = Index(name=index_name) index_id, _ = rr_cli.create(index_res) ims_cli.delete_index(index_id) with self.assertRaises(NotFound): rr_cli.delete(index_id)
def test_create_catalog(self): #------------------------------------- # Tests basic catalog creation #------------------------------------- index1 = Index(name='index1') index1.options.attribute_match = ['common'] index_id, _ = self.rr_cli.create(index1) catalog_id = self.cms_cli.create_catalog('common_catalog', ['common']) self.assertTrue(index_id in self.cms_cli.list_indexes(catalog_id))
def test_read_index(self): ims_cli = self.ims_cli rr_cli = self.rr_cli index_name = self.index_name index_res = Index(name=index_name) index_id, _ = rr_cli.create(index_res) index = ims_cli.read_index(index_id) self.assertIsInstance(index, Index) self.assertTrue(index.name == index_name) rr_cli.delete(index_id)
def test_update_index(self): ims_cli = self.ims_cli rr_cli = self.rr_cli index_name = self.index_name index_res = Index(name=index_name) index_id, _ = rr_cli.create(index_res) index = ims_cli.read_index(index_id) index.name = 'another' ims_cli.update_index(index) index = rr_cli.read(index_id) self.assertTrue(index.name == 'another')
def test_update_index(self): with self.assertRaises(BadRequest): self.index_management.update_index() with self.assertRaises(BadRequest): self.index_management.update_index('hi') self.index_management.update_index(Index())
def test_update_collection(self): with self.assertRaises(BadRequest): ind = Index() self.index_management.update_collection(ind) self.index_management.update_collection(Collection()) self.assertTrue(self.rr_update.called)