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)
    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)
    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)
    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)
Exemple #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)
Exemple #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)
 def fail2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F2');")
         raise HaltCommits
 def fail1(self):
     with SqliteCursor(db1) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F1');")
         self.fail2()
 def success2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('S2');")
 def layer2(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         raise HaltCommits
 def layer1(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         self.layer2()
 def add_two(self):
     with SqliteCursor(DBPATH) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('two')")