def test_commit(self): self.db.set('key', {'hello': 'world'}) db = MeuhDb(self.filename) # reload self.assertFalse(db.exists("key")) self.db.commit() db = MeuhDb(self.filename) # reload self.assertTrue(db.exists("key")) self.assertEquals(db.get('key'), {'hello': 'world'})
def test_autocommit_after(self): self.db.set('key', {'name': 'Alice'}) db = MeuhDb(self.filename) # reload self.assertFalse(db.exists('key')) self.db.set('key', {'name': 'Alice 2'}) db = MeuhDb(self.filename) # reload self.assertFalse(db.exists('key')) self.db.set('key', {'name': 'Alice 3'}) db = MeuhDb(self.filename) # reload self.assertTrue(db.exists('key'))
def test_autocommit_after_other_command(self): self.db.set('key1', {'name': 'Alice'}) self.db.set('key2', {'name': 'Alice'}) self.db.set('key3', {'name': 'Alice'}) # Should be committed self.db.delete('key3') db = MeuhDb(self.filename) # reload self.assertTrue(db.exists('key3'))
def test_create_index(self): self.db.set('1', {'name': 'Alice'}) self.db.set('2', {'name': 'Bob'}) self.db.create_index('name') db = MeuhDb(self.filename) # reload self.assertTrue(db.exists('1')) self.assertTrue(db.exists('2')) self.assertTrue('name' in db.indexes) index = db.indexes['name'] self.assertEquals(index['Alice'], set(['1'])) self.assertEquals(index['Bob'], set(['2']))
def test_delete(self): self.db.set('key', {'hello': 'world'}) self.db.delete('key') db = MeuhDb(self.filename) # reload self.assertFalse(db.exists('key'))