def test_indexing(self): """Test basic indexing around name """ db = IndexedDatabase(os.path.join(self._temp_dir, 'test_db'), _serialize_tuple, _deserialize_tuple, indexes={'name': lambda tup: [tup[1].encode()]}, flag='c', _size=1024**2) db.put('1', (1, "foo", "bar")) db.put('2', (2, "alice", "Alice's data")) db.put('3', (3, "bob", "Bob's data")) self.assertEqual((1, "foo", "bar"), db.get('1')) self.assertEqual((2, "alice", "Alice's data"), db.get('alice', index='name'))
def test_indexing(self): """Test basic indexing around name """ db = IndexedDatabase( os.path.join(self._temp_dir, 'test_db'), _serialize_tuple, _deserialize_tuple, indexes={'name': lambda tup: [tup[1].encode()]}, flag='c', _size=1024**2) db.put('1', (1, "foo", "bar")) db.put('2', (2, "alice", "Alice's data")) db.put('3', (3, "bob", "Bob's data")) self.assertEqual((1, "foo", "bar"), db.get('1')) self.assertEqual( (2, "alice", "Alice's data"), db.get('alice', index='name'))
def test_update_replace_index(self): """Test that update will properly update insert records that have the same index value of a deleted record. - insert items should be added - inserted items index should be correct - deleted items should be removed """ db = IndexedDatabase(os.path.join(self._temp_dir, 'test_db'), _serialize_tuple, _deserialize_tuple, indexes={'name': lambda tup: [tup[1].encode()]}, flag='c', _size=1024**2) db.put('1', (1, "foo", "bar")) db.put('2', (2, "alice", "Alice's data")) db.put('3', (3, "bob", "Bob's data")) db.update([('4', (4, 'foo', "foo's data"))], ['1']) self.assertEqual(['2', '3', '4'], db.keys()) self.assertEqual((4, 'foo', "foo's data"), db.get('foo', index='name'))
def test_update_replace_index(self): """Test that update will properly update insert records that have the same index value of a deleted record. - insert items should be added - inserted items index should be correct - deleted items should be removed """ db = IndexedDatabase( os.path.join(self._temp_dir, 'test_db'), _serialize_tuple, _deserialize_tuple, indexes={'name': lambda tup: [tup[1].encode()]}, flag='c', _size=1024**2) db.put('1', (1, "foo", "bar")) db.put('2', (2, "alice", "Alice's data")) db.put('3', (3, "bob", "Bob's data")) db.update([('4', (4, 'foo', "foo's data"))], ['1']) self.assertEqual(['2', '3', '4'], db.keys()) self.assertEqual( (4, 'foo', "foo's data"), db.get('foo', index='name'))