def test_cancel_transaction(self): db = DataBase(store) self.assertFalse(db.in_transaction()) r = db.cancel_transaction() self.assertFalse(r) with db.transaction(): self.assertTrue(db.in_transaction()) id = db.execute( 'insert into foo(name, age, age_str, `key`) values(%s, %s, %s, %s)', ('foo', 1, '1', '1')) r = db.cancel_transaction() self.assertTrue(r) rv = db.execute('select * from foo where id = %s', id) self.assertEqual(rv, ())
def test_do_beansdb_commands(self): db = DataBase(store) with db.transaction(): with self.assertRaises(DataBaseError): db.db_set('a', 'xixi') db = DataBase(store, beansdb=beansdb) oa = db.db_get('a') ob = db.db_get('b') try: with db.transaction(): db.db_set('a', 'xixi') db.db_set('b', 'haha') raise AE except AE: pass self.assertEqual(db.db_get('a'), oa) self.assertEqual(db.db_get('b'), ob) with db.transaction(): db.db_set('a', 'xixi') db.db_set('b', 'haha') self.assertEqual(db.db_get('a'), 'xixi') self.assertEqual(db.db_get('b'), 'haha') db._local.append_beansdb_commands(('error', (), {})) db._do_beansdb_commands()