def attr_mapping(resources): options = SearchOptions() attribute_match = set() range_fields = set() geo_fields = set() for t in resources: schema = getattr(interface.objects, t)._schema for k,v in schema.iteritems(): ion_type = v['type'] if ion_type=='int': range_fields.add(k) elif ion_type =='long': range_fields.add(k) elif ion_type == 'float': range_fields.add(k) elif ion_type == 'str': attribute_match.add(k) elif ion_type == 'GeospatialPoint': geo_fields.add(k) options.attribute_match = list(attribute_match) options.range_fields = list(range_fields) options.geo_fields = list(geo_fields) return options
def attr_mapping(resources): options = SearchOptions() attribute_match = set() range_fields = set() geo_fields = set() for t in resources: schema = getattr(interface.objects, t)._schema for k, v in schema.iteritems(): ion_type = v['type'] if ion_type == 'int': range_fields.add(k) elif ion_type == 'long': range_fields.add(k) elif ion_type == 'float': range_fields.add(k) elif ion_type == 'str': attribute_match.add(k) elif ion_type == 'GeospatialLocation': geo_fields.add(k) options.attribute_match = list(attribute_match) options.range_fields = list(range_fields) options.geo_fields = list(geo_fields) return options
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_create_elasticsearch_index(self): index_name = self.index_name ims_cli = self.ims_cli rr_cli = self.rr_cli options = SearchOptions() options.attribute_match = ["test_field"] index_id = ims_cli.create_index( name=index_name, content_type=IndexManagementService.ELASTICSEARCH_INDEX, options=options ) index_result = self.rr_cli.read(index_id) self.assertIsInstance(index_result, ElasticSearchIndex) self.assertTrue(index_result.name == index_name) # ====================================== # Clean up # ====================================== rr_cli.delete(index_id)
def test_create_datastore_index(self): index_name = self.index_name ims_cli = self.ims_cli rr_cli = self.rr_cli options = SearchOptions() options.attribute_match = ['test_field'] index_id = ims_cli.create_index( name=index_name, content_type=IndexManagementService.DATASTORE_INDEX, options=options) index_result = self.rr_cli.read(index_id) self.assertIsInstance(index_result, ElasticSearchIndex) self.assertTrue(index_result.name == index_name) #====================================== # Clean up #====================================== rr_cli.delete(index_id)
def test_create_couchdb_index(self): index_name = self.index_name ims_cli = self.ims_cli rr_cli = self.rr_cli options = SearchOptions() options.attribute_match = ['name'] index_id = ims_cli.create_index( index_name, content_type=IndexManagementService.COUCHDB_INDEX, options=options, datastore_name='fake', view_name='fake/by_fake') index_result = self.rr_cli.read(index_id) self.assertIsInstance(index_result, CouchDBIndex) self.assertTrue(index_result.name == index_name) #====================================== # Clean up #====================================== rr_cli.delete(index_id)
def test_create_couchdb_index(self): index_name = self.index_name ims_cli = self.ims_cli rr_cli = self.rr_cli options = SearchOptions() options.attribute_match = ["name"] index_id = ims_cli.create_index( index_name, content_type=IndexManagementService.COUCHDB_INDEX, options=options, datastore_name="fake", view_name="fake/by_fake", ) index_result = self.rr_cli.read(index_id) self.assertIsInstance(index_result, CouchDBIndex) self.assertTrue(index_result.name == index_name) # ====================================== # Clean up # ====================================== rr_cli.delete(index_id)