def test_update_new(self): data = self._gen_data() index = EssentialIndex('f2') index.create_index(data) data['new'] = {'f1': 'v1a', 'f2': 'newval', 'f3': 10, "_id": "new"} index.update_index(data['new']) items = index.find(data, 'newval') self.assertEqual(len(items), 1)
def test_update_existing(self): data = self._gen_data() index = EssentialIndex('f2') index.create_index(data) data['b'] = {'f1': 'v1a', 'f2': 'updatedval', 'f3': 10, "_id": "b"} index.update_index(data['b']) items = index.find(data, 'updatedval') self.assertEqual(len(items), 1)
def test_remove_existing(self): data = self._gen_data() index = EssentialIndex('f2') index.create_index(data) items = index.find(data, 'v2') self.assertEqual(len(items), 3) removed = index.remove_from_index(data['b']) self.assertTrue(removed) items = index.find(data, 'v2') self.assertEqual(len(items), 2)
def test_remove_non_existing(self): data = self._gen_data() index = EssentialIndex('f2') index.create_index(data) removed = index.remove_from_index({'_id': 'doesnt exist'}) self.assertFalse(removed) removed = index.remove_from_index({'no id': 'doesnt exist'}) self.assertFalse(removed)
def createIndex(self, index_document, options=None): for key in index_document: if index_document[key] == "hashed": index = EssentialIndex(key) index.create_index(self.documents) self.indexes[key] = index
def test_find_unique(self): data = self._gen_data() index = EssentialIndex('f1') index.create_index(data) items = index.find(data, 'v1a') self.assertEqual(len(items), 1)
def test_find_none(self): data = self._gen_data() index = EssentialIndex('f2') index.create_index(data) items = index.find(data, 'v444') self.assertEqual(len(items), 0)
def test_create_index_unique(self): data = self._gen_data() index = EssentialIndex('f1') index_dict = index.create_index(data) self.assertEqual(len(index_dict), 3)
def test_create_index_multiple(self): data = self._gen_data() index = EssentialIndex('f2') index_dict = index.create_index(data) self.assertEqual(len(index_dict), 1)
def test_find_none(self): index = EssentialIndex() index.create_index(data, 'f2') items = index.find(data, 'v444') self.assertEqual(len(items), 0)
def test_find_multiple(self): index = EssentialIndex() index.create_index(data, 'f2') items = index.find(data, 'v2') self.assertEqual(len(items), 3)
def test_find_unique(self): index = EssentialIndex() index.create_index(data, 'f1') items = index.find(data, 'v1a') self.assertEqual(len(items), 1)
def test_create_index_multiple(self): index = EssentialIndex() index_dict = index.create_index(data, 'f2') self.assertEqual(len(index_dict), 1)
def test_create_index_unique(self): index = EssentialIndex() index_dict = index.create_index(data, 'f1') self.assertEqual(len(index_dict), 3)