blob: f40876a8e7eb869f9d41f78c1b70a0fbb13e50c7 [file] [log] [blame]
Gerhard Häringb1b93822008-03-29 00:41:18 +00001# Author: Paul Kippes <kippesp@gmail.com>
2
3import unittest
4import sqlite3 as sqlite
5
6class DumpTests(unittest.TestCase):
7 def setUp(self):
8 self.cx = sqlite.connect(":memory:")
9 self.cu = self.cx.cursor()
10
11 def tearDown(self):
12 self.cx.close()
13
14 def CheckTableDump(self):
15 expected_sqls = [
16 "CREATE TABLE t1(id integer primary key, s1 text, " \
17 "t1_i1 integer not null, i2 integer, unique (s1), " \
18 "constraint t1_idx1 unique (i2));"
19 ,
20 "INSERT INTO \"t1\" VALUES(1,'foo',10,20);"
21 ,
22 "INSERT INTO \"t1\" VALUES(2,'foo2',30,30);"
23 ,
24 "CREATE TABLE t2(id integer, t2_i1 integer, " \
25 "t2_i2 integer, primary key (id)," \
26 "foreign key(t2_i1) references t1(t1_i1));"
27 ,
28 "CREATE TRIGGER trigger_1 update of t1_i1 on t1 " \
29 "begin " \
30 "update t2 set t2_i1 = new.t1_i1 where t2_i1 = old.t1_i1; " \
31 "end;"
32 ,
33 "CREATE VIEW v1 as select * from t1 left join t2 " \
34 "using (id);"
35 ]
36 [self.cu.execute(s) for s in expected_sqls]
37 i = self.cx.iterdump()
38 actual_sqls = [s for s in i]
39 expected_sqls = ['BEGIN TRANSACTION;'] + expected_sqls + \
40 ['COMMIT;']
41 [self.assertEqual(expected_sqls[i], actual_sqls[i])
42 for i in range(len(expected_sqls))]
43
44def suite():
45 return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
46
47def test():
48 runner = unittest.TextTestRunner()
49 runner.run(suite())
50
51if __name__ == "__main__":
52 test()