예제 #1
0
 def test_db_set(self):
     db = DataBase(store)
     with self.assertRaises(DataBaseError):
         db.db_set('a', 'b')
     db = DataBase(store, beansdb=beansdb)
     db.db_set('a', 'b')
     self.assertEqual(db.db_get('a'), 'b')
예제 #2
0
 def test_db_set_multi(self):
     db = DataBase(store)
     with self.assertRaises(DataBaseError):
         db.db_set_multi({'a': 1, 'b': 2})
     db = DataBase(store, beansdb=beansdb)
     db.db_set_multi({'a': 1, 'b': 2})
     self.assertEqual(db.db_get('a'), 1)
     self.assertEqual(db.db_get('b'), 2)
예제 #3
0
 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, ())
예제 #4
0
 def test_cancel_transaction(self):
     db = DataBase(store)
     self.assertFalse(db.in_transaction())
     r = db.cancel_transaction()
     self.assertFalse(r)
     with start_transaction(db):
         self.assertTrue(db.in_transaction())
         if is_pg:
             id = db.execute(
                 'insert into foo(name, age, age_str, "key") values(%s, %s, %s, %s)',
                 ('foo', 1, '1', '1'))
         else:
             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)
     with start_transaction(db):
         rv = db.execute('select * from foo where id = %s', (id, ))
     # FIXME(PG)
     if is_pg:
         self.assertEqual(rv, [])
     else:
         self.assertEqual(rv, ())
예제 #5
0
 def test_add_commit_handler(self):
     db = DataBase(store)
     old_report = db.report
     db.report = Mock()
     handler = Mock()
     db.add_commit_handler(handler)
     db.commit()
     self.assertEqual(db.report.call_count, 0)
     self.assertTrue(handler.called)
     self.assertEqual(handler.call_count, 1)
     handler = Mock()
     handler.side_effect = AE()
     db.add_commit_handler(handler)
     db.commit()
     self.assertEqual(db.report.call_count, 1)
     db.report = old_report
예제 #6
0
 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()
예제 #7
0
 def test_db_delete_multi(self):
     db = DataBase(store, beansdb=beansdb)
     db.db_delete_multi(['a', 'b'])
     self.assertIsNone(db.db_get('a'))
     self.assertIsNone(db.db_get('b'))
예제 #8
0
 def test_db_get_multi(self):
     db = DataBase(store)
     with self.assertRaises(DataBaseError):
         db.db_get_multi(['a', 'b'])
     db = DataBase(store, beansdb=beansdb)
     db.db_get_multi(['a', 'b'])
예제 #9
0
 def test_add_lazy_func(self):
     db = DataBase(store)
     old_report = db.report
     db.report = Mock()
     func = Mock()
     db.add_lazy_func(func)
     db.commit()
     self.assertEqual(db.report.call_count, 0)
     self.assertTrue(func.called)
     self.assertEqual(func.call_count, 1)
     func = Mock()
     func.side_effect = AE()
     db.add_lazy_func(func)
     db.commit()
     self.assertEqual(db.report.call_count, 1)
     db.report = old_report