Пример #1
0
 def test_cmd_all(self):
     res = Util.safe_call(self.dbm.add_driver, 1,
                          DbManagerTestCase.TestDriver(1))
     self.assertTrue(not isinstance(res, Exception),
                     "Exception adding new driver: %s" % res)
     arg = 1
     exp_vals = range(arg, len(self.dbm) + arg)
     res = Util.safe_call(self.dbm.cmd_all, lambda db: db.echo(arg))
     self.assertTrue(not isinstance(res, Exception), "Exception: %s" % res)
     self.assertTrue(not Util.list_diff(res, exp_vals),
                     "Got %s, expected %s" % (res, exp_vals))
Пример #2
0
 def test_add_fail(self):
     res = Util.safe_call(self.dbm.add_driver, 1, {})
     self.assertTrue(
         isinstance(res, DbException),
         "Expected exception when adding invalid driver, got %s" % res)
     # check that we can't insert driver with existing id
     res = Util.safe_call(self.dbm.add_driver, 0,
                          DbManagerTestCase.TestDriver(0))
     self.assertTrue(isinstance(res, DbException),
                     "Expected exception, but got %s" % res)
     self.assertEqual(len(self.dbm), 1, "DB manager size changed")
Пример #3
0
 def test_cmd_one(self):
     test_val = 5
     res = Util.safe_call(self.dbm.cmd_one, 0, lambda db: db.echo(test_val))
     self.assertTrue(not isinstance(res, Exception),
                     "Exception calling method: %s" % res)
     self.assertEqual(res, test_val,
                      "Got %s, expected %d" % (res, test_val))
Пример #4
0
 def test_add(self):
     self.assertEqual(len(self.dbm), 0, "DB Manager not empty")
     res = Util.safe_call(self.dbm.add_driver, 0,
                          DbManagerTestCase.TestDriver(0))
     self.assertTrue(not isinstance(res, Exception),
                     "Exception adding driver: %s" % res)
     self.assertEqual(len(self.dbm), 1, "DB Manager is still empty")
Пример #5
0
    def test_add(self):
        db_name = 'test'
        res = Util.safe_call(self.modb.add_db, db_name)
        self.assertTrue(not isinstance(res, Exception),
                        "Exception adding database: %s" % res)
        # try adding DB with same name again
        res = Util.safe_call(self.modb.add_db, db_name)
        self.assertTrue(isinstance(res, DbException),
                        "Didn't get exception adding same DB name twice")
        # try accessing database that wasn't added
        try:
            self.modb.active_db = 'test1'
        except Exception as e:
            self.assertTrue(isinstance(e, DbException),
                            "Expected DB error, but got %s" % e)
        else:
            self.assertTrue(False)

        self.modb.active_db = db_name
        cnt = self.modb.active_db.count()
        self.assertEqual(cnt, 1, "Expected 1 table, got %d" % cnt)
Пример #6
0
    def test_fill_random(self):
        self._init_db('test')

        exp_cnt = 5
        res = Util.safe_call(self.modb.fill_random, 'check', self.test_temp,
                             exp_cnt)
        self.assertTrue(not isinstance(res, DbException),
                        "Exception filling DB: %s" % res)

        cnt = self.modb.active_db['check'].count()
        self.assertEqual(cnt, exp_cnt + 1,
                         "Expected %d entries, got %d" % (exp_cnt + 1, cnt))