[CalendarServer-changes] [9590] CalendarServer/branches/users/glyph/q

source_changes at macosforge.org source_changes at macosforge.org
Sat Aug 11 01:54:33 PDT 2012


Revision: 9590
          http://trac.macosforge.org/projects/calendarserver/changeset/9590
Author:   glyph at apple.com
Date:     2012-08-11 01:54:33 -0700 (Sat, 11 Aug 2012)
Log Message:
-----------
Test to make sure that a normal `Insert` (i.e. one without `Return=`) still works too.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/q/

Modified: CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py	2012-08-11 08:54:32 UTC (rev 9589)
+++ CalendarServer/branches/users/glyph/q/twext/enterprise/dal/test/test_sqlsyntax.py	2012-08-11 08:54:33 UTC (rev 9590)
@@ -39,6 +39,7 @@
 from twisted.trial.unittest import TestCase
 
 
+
 class _FakeTransaction(object):
     """
     An L{IAsyncTransaction} that provides the relevant metadata for SQL
@@ -57,7 +58,25 @@
     TIMESTAMP = 'for timestamps!'
 
 
+class CatchSQL(object):
+    """
+    L{IAsyncTransaction} emulator that records the SQL executed on it.
+    """
+    counter = 0
 
+    def __init__(self, dialect=SQLITE_DIALECT, paramstyle='numeric'):
+        self.execed = []
+        self.dialect = SQLITE_DIALECT
+        self.paramstyle = 'numeric'
+
+
+    def execSQL(self, sql, args, rozrc):
+        self.execed.append([sql, args])
+        self.counter += 1
+        return succeed(self.counter)
+
+
+
 class NullTestingOracleTxn(object):
     """
     Fake transaction for testing oracle NULL behavior.
@@ -961,25 +980,32 @@
             SQLFragment("insert into FOO (BAR, BAZ) values (:1, :2)",
                         [39, 82])
         )
-        execed = []
-        counter = [0]
-        class CatchSQL(object):
-            dialect = SQLITE_DIALECT
-            paramstyle = 'numeric'
-            def execSQL(self, sql, args, rozrc):
-                execed.append([sql, args])
-                counter[0] += 1
-                return succeed(counter[0])
         result = []
-        insertStatement.on(CatchSQL()).addCallback(result.append)
+        csql = CatchSQL()
+        insertStatement.on(csql).addCallback(result.append)
+        self.assertEqual(result, [2])
         self.assertEqual(
-            execed,
+            csql.execed,
             [["insert into FOO (BAR, BAZ) values (:1, :2)", [39, 82]],
              ["select BAR, BAZ from FOO where rowid = last_insert_rowid()", []]]
         )
-        self.assertEqual(result, [2])
 
 
+    def test_insertNoReturnSQLite(self):
+        """
+        Insert a row I{without} a C{Return=} parameter should also work as
+        normal in sqlite.
+        """
+        statement = Insert({self.schema.FOO.BAR: 12,
+                            self.schema.FOO.BAZ: 48})
+        csql = CatchSQL()
+        statement.on(csql)
+        self.assertEqual(
+            csql.execed,
+            [["insert into FOO (BAR, BAZ) values (:1, :2)", [12, 48]]]
+        )
+
+
     def test_insertMismatch(self):
         """
         L{Insert} raises L{TableMismatch} if the columns specified aren't all
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120811/7796f73d/attachment.html>


More information about the calendarserver-changes mailing list