[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/SQLScript/tests - testSQLScript.py:1.4
Erik
ersab@codeworks.lt
Thu, 8 Aug 2002 11:06:00 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/SQLScript/tests
In directory cvs.zope.org:/tmp/cvs-serv29083/tests
Modified Files:
testSQLScript.py
Log Message:
Ported SQL caching support from Zope 2.
=== Zope3/lib/python/Zope/App/OFS/Content/SQLScript/tests/testSQLScript.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/OFS/Content/SQLScript/tests/testSQLScript.py:1.3 Thu Aug 1 14:42:10 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/SQLScript/tests/testSQLScript.py Thu Aug 8 11:05:59 2002
@@ -36,11 +36,18 @@
__implements__ = IZopeCursor
- description = (('name', 'string'),)
+ description = (('name', 'string'), ('counter', 'int'))
+ count = 0
def execute(self, operation, parameters=None):
- self.result = {"SELECT name FROM Table WHERE id = 1":
- (('stephan',),)}[operation]
+ CursorStub.count += 1
+ self.result = {"SELECT name, counter FROM Table WHERE id = 1":
+ (('stephan', CursorStub.count),),
+ "SELECT name, counter FROM Table WHERE id = 2":
+ (('marius', CursorStub.count),),
+ "SELECT name, counter FROM Table WHERE id = 3":
+ (('erik', CursorStub.count),)
+ }[operation]
def fetchall(self):
return self.result
@@ -74,7 +81,7 @@
def _getScript(self):
return SQLScript("my_connection",
- "SELECT name FROM Table WHERE <dtml-sqltest id type=int>",
+ "SELECT name, counter FROM Table WHERE <dtml-sqltest id type=int>",
'id')
@@ -103,7 +110,7 @@
def testGetSource(self):
self.assertEqual(
- "SELECT name FROM Table WHERE <dtml-sqltest id type=int>",
+ "SELECT name, counter FROM Table WHERE <dtml-sqltest id type=int>",
self._getScript().getSource())
@@ -116,12 +123,31 @@
def testGetConnectionName(self):
self.assertEqual('my_connection',
self._getScript().getConnectionName())
-
+
def testSQLScript(self):
result = self._getScript()(id=1)
- self.assertEqual(result.names, ('name',))
+ self.assertEqual(result.names, ('name','counter'))
self.assertEqual(result[0].name, 'stephan')
+
+ def testSQLScriptCaching(self):
+ script = self._getScript()
+ CursorStub.count = 0
+ # turn off caching and check that the counter grows
+ script.setCacheTime(0)
+ result = script(id=1)
+ self.assertEqual(result[0].counter, 1)
+ result = script(id=1)
+ self.assertEqual(result[0].counter, 2)
+ # turn on caching and check that the counter stays still
+ script.setCacheTime(100000)
+ script.setMaxCache(100)
+ result = script(id=1)
+ self.assertEqual(result[0].counter, 3)
+ result = script(id=1)
+ self.assertEqual(result[0].counter, 3)
+ result = script(id=2)
+ self.assertEqual(result[0].counter, 4)
def test_suite():