changeset 101:0ae9a10f9d88

More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
author cmlenz
date Tue, 19 Jul 2005 08:05:25 +0000
parents bb5bcf5939f6
children c6bc84b0b159
files bitten/model.py bitten/tests/model.py bitten/trac_ext/tests/web_ui.py
diffstat 3 files changed, 29 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/model.py
+++ b/bitten/model.py
@@ -173,10 +173,12 @@
         cursor = db.cursor()
         cursor.execute("INSERT INTO bitten_platform (config,name) "
                        "VALUES (%s,%s)", (self.config, self.name))
-        self.id = db.get_last_id('bitten_platform')
-        cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
-                           [(self.id, propname, pattern, idx) for
-                            idx, (propname, pattern) in enumerate(self.rules)])
+        self.id = db.get_last_id(cursor, 'bitten_platform')
+        if self.rules:
+            cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
+                               [(self.id, propname, pattern, idx)
+                                for idx, (propname, pattern)
+                                in enumerate(self.rules)])
 
         if handle_ta:
             db.commit()
@@ -195,10 +197,12 @@
         cursor = db.cursor()
         cursor.execute("UPDATE bitten_platform SET name=%s WHERE id=%s",
                        (self.name, self.id))
-        cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id))
-        cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
-                           [(self.id, propname, pattern, idx) for
-                            idx, (propname, pattern) in enumerate(self.rules)])
+        cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id,))
+        if self.rules:
+            cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
+                               [(self.id, propname, pattern, idx)
+                                for idx, (propname, pattern)
+                                in enumerate(self.rules)])
 
         if handle_ta:
             db.commit()
@@ -328,10 +332,11 @@
                        (self.config, self.rev, self.rev_time, self.platform,
                         self.slave or '', self.started or 0, self.stopped or 0,
                         self.status))
-        self.id = db.get_last_id('bitten_build')
-        cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)",
-                           [(self.id, name, value) for name, value
-                            in self.slave_info.items()])
+        self.id = db.get_last_id(cursor, 'bitten_build')
+        if self.slave_info:
+            cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)",
+                               [(self.id, name, value) for name, value
+                                in self.slave_info.items()])
 
         if handle_ta:
             db.commit()
--- a/bitten/tests/model.py
+++ b/bitten/tests/model.py
@@ -31,7 +31,8 @@
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         for table in BuildConfig._schema:
-            cursor.execute(db.to_sql(table))
+            for stmt in db.to_sql(table):
+                cursor.execute(stmt)
         db.commit()
 
     def test_new_config(self):
@@ -72,7 +73,8 @@
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         for table in TargetPlatform._schema:
-            cursor.execute(db.to_sql(table))
+            for stmt in db.to_sql(table):
+                cursor.execute(stmt)
         db.commit()
 
     def test_new(self):
@@ -102,7 +104,7 @@
         cursor = db.cursor()
         cursor.execute("INSERT INTO bitten_platform (config,name) "
                        "VALUES (%s,%s)", ('test', 'Windows'))
-        id = db.get_last_id('bitten_platform')
+        id = db.get_last_id(cursor, 'bitten_platform')
         platform = TargetPlatform.fetch(self.env, id)
         assert platform.exists
         self.assertEqual('test', platform.config)
@@ -125,7 +127,8 @@
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         for table in Build._schema:
-            cursor.execute(db.to_sql(table))
+            for stmt in db.to_sql(table):
+                cursor.execute(stmt)
         db.commit()
 
     def test_new(self):
@@ -195,7 +198,7 @@
                        "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
                        ('test', '42', 12039, 1, 'tehbox', 15006, 16007,
                         Build.SUCCESS))
-        build_id = db.get_last_id('bitten_build')
+        build_id = db.get_last_id(cursor, 'bitten_build')
         cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)",
                            [(build_id, Build.IP_ADDRESS, '127.0.0.1'),
                             (build_id, Build.MAINTAINER, 'joe@example.org')])
@@ -213,7 +216,8 @@
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         for table in BuildStep._schema:
-            cursor.execute(db.to_sql(table))
+            for stmt in db.to_sql(table):
+                cursor.execute(stmt)
         db.commit()
 
     def test_new(self):
--- a/bitten/trac_ext/tests/web_ui.py
+++ b/bitten/trac_ext/tests/web_ui.py
@@ -19,7 +19,8 @@
         db = self.env.get_db_cnx()
         cursor = db.cursor()
         for table in schema:
-            cursor.execute(db.to_sql(table))
+            for stmt in db.to_sql(table):
+                cursor.execute(stmt)
 
         # Set up permissions
         self.env.config.set('trac', 'permission_store',
Copyright (C) 2012-2017 Edgewall Software