コード例 #1
0
 def setUp(self):
     self.isq = InlineSQLite()
     self.isq.runOperation(
         "create table foobar_test (val1 string, val2 string)")
     self.isq.runOperation('insert into foobar_test values ("a", "b")')
コード例 #2
0
class InlineSQLiteTest(unittest.TestCase):
    def setUp(self):
        self.isq = InlineSQLite()
        self.isq.runOperation(
            "create table foobar_test (val1 string, val2 string)")
        self.isq.runOperation('insert into foobar_test values ("a", "b")')

    def test_init(self):
        self.assertTrue(hasattr(self.isq, "autoCommit"))
        self.assertTrue(hasattr(self.isq, "conn"))
        self.assertTrue(hasattr(self.isq, "curs"))

    def test_runQuery(self):
        self.isq.curs = Mock()
        self.isq.curs.__iter__ = Mock(return_value=iter([1, 2, 3]))
        res = self.isq.runQuery("a query")
        self.assertEqual(res, [1, 2, 3])

    def test_runOperation(self):
        self.isq.runOperation('insert into foobar_test values ("c", "d")')
        res = self.isq.runQuery("select count(*) from foobar_test")
        self.assertEqual(res[0][0], 2)

    def test_runOperationMany(self):
        self.isq.runOperationMany('insert into foobar_test values (?, ?)',
                                  [["a", "b"], ["c", "d"]])
        res = self.isq.runQuery("select count(*) from foobar_test")
        self.assertEqual(res[0][0], 3)

    def test_commit(self):
        self.isq.conn = Mock()
        self.isq.commit()
        self.isq.conn.commit.assert_called_with()

    def test_rollback(self):
        self.isq.conn = Mock()
        self.isq.rollback()
        self.isq.conn.rollback.assert_called_with()

    def test_close(self):
        self.isq.conn = Mock()
        self.isq.close()
        self.isq.conn.close.assert_called_with()
コード例 #3
0
ファイル: test_db.py プロジェクト: VRGhost/cyclone
 def setUp(self):
     self.isq = InlineSQLite()
     self.isq.runOperation(
         "create table nothing (val1 string, val2 string)")
     self.isq.runOperation('insert into nothing values ("a", "b")')
コード例 #4
0
ファイル: test_db.py プロジェクト: ygl-rg/cyclone
 def setUp(self):
     self.isq = InlineSQLite()
     self.isq.runOperation(
         "create table `nothing` (val1 string, val2 string)")
     self.isq.runOperation('insert into `nothing` values ("a", "b")')
コード例 #5
0
ファイル: test_db.py プロジェクト: VRGhost/cyclone
class InlineSQLiteTest(unittest.TestCase):
    def setUp(self):
        self.isq = InlineSQLite()
        self.isq.runOperation(
            "create table nothing (val1 string, val2 string)")
        self.isq.runOperation('insert into nothing values ("a", "b")')

    def test_init(self):
        self.assertTrue(hasattr(self.isq, "autoCommit"))
        self.assertTrue(hasattr(self.isq, "conn"))
        self.assertTrue(hasattr(self.isq, "curs"))

    def test_runQuery(self):
        self.isq.curs = Mock()
        self.isq.curs.__iter__ = Mock(return_value=iter([1, 2, 3]))
        res = self.isq.runQuery("a query")
        self.assertEqual(res, [1, 2, 3])

    def test_runOperation(self):
        self.isq.runOperation('insert into nothing values ("c", "d")')
        res = self.isq.runQuery("select count(*) from nothing")
        self.assertEqual(res[0][0], 2)

    def test_runOperationMany(self):
        self.isq.runOperationMany(
            'insert into nothing values (?, ?)',
            [["a", "b"], ["c", "d"]]
        )
        res = self.isq.runQuery("select count(*) from nothing")
        self.assertEqual(res[0][0], 3)

    def test_commit(self):
        self.isq.conn = Mock()
        self.isq.commit()
        self.isq.conn.commit.assert_called_with()

    def test_rollback(self):
        self.isq.conn = Mock()
        self.isq.rollback()
        self.isq.conn.rollback.assert_called_with()

    def test_close(self):
        self.isq.conn = Mock()
        self.isq.close()
        self.isq.conn.close.assert_called_with()