Ejemplo n.º 1
0
    def test_failure(self):
        self.fail1()
        with SqliteCursor(db1) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='F1';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 0)

        with SqliteCursor(db2) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='F2';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 0)
Ejemplo n.º 2
0
    def test_cascade_halt(self):
        with SqliteCursor() as cur:
            cur.execute("INSERT INTO test_table(field) VALUES('X');")
            self.layer1()

        with SqliteCursor() as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='X';")
            row = cur.fetchone()
            self.assertEqual(row['COUNT(*)'], 0)
Ejemplo n.º 3
0
    def test_success(self):
        self.success1()
        with SqliteCursor(db1) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='S1';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 1)

        with SqliteCursor(db2) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='S2';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 1)
Ejemplo n.º 4
0
    def test_nest(self):
        with SqliteCursor(DBPATH) as cur:
            self.add_one()
            cur.execute(
                "INSERT INTO test_table(field) VALUES('one point five')")
            self.add_two()

        with SqliteCursor(DBPATH) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='two'")
            row = cur.fetchone()
            self.assertEqual(row["COUNT(*)"], 1)
Ejemplo n.º 5
0
def seed(dbpath=DBPATH):
    with SqliteCursor(dbpath) as cur:
        SQL = """ DELETE FROM test_table; """
        cur.execute(SQL)

        SQL = """ INSERT INTO test_table (field) VALUES (?); """
        vals = [('A', ), ('B', ), ('C', )]
        for val in vals:
            cur.execute(SQL, val)
Ejemplo n.º 6
0
def schema(dbpath=DBPATH):
    with SqliteCursor(dbpath) as cur:
        SQL = "DROP TABLE IF EXISTS test_table;"
        cur.execute(SQL)
        SQL = """ CREATE TABLE test_table(
            pk INTEGER PRIMARY KEY AUTOINCREMENT,
            field TEXT
            ); """
        cur.execute(SQL)
Ejemplo n.º 7
0
 def fail2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F2');")
         raise HaltCommits
Ejemplo n.º 8
0
 def fail1(self):
     with SqliteCursor(db1) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F1');")
         self.fail2()
Ejemplo n.º 9
0
 def success2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('S2');")
Ejemplo n.º 10
0
 def layer2(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         raise HaltCommits
Ejemplo n.º 11
0
 def layer1(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         self.layer2()
Ejemplo n.º 12
0
 def add_two(self):
     with SqliteCursor(DBPATH) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('two')")