[Zope3-checkins] CVS: Zope3/src/zope/app/browser/tests - test_zodbundomanager.py:1.4

Anthony Baxter anthony@interlink.com.au
Thu, 10 Jul 2003 08:42:19 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv9651/tests

Modified Files:
	test_zodbundomanager.py 
Log Message:
Made the 'Undo' tab considerably more useful. You can choose to see just
your own transactions, or everyone's (default to just your own), you can
see more than the last 20 transactions. zodb's undoInfo supported 
passing through filter specifications, but this wasn't hooked up properly.

There's an outstanding issue with the username that's in the zodb
transaction 'user' field - it's being concatenated together with a 
'path' that's never set and defaults to '/ '. For now, all the 
unpleasantness is isolated in undo_log.pt, along with a comment 
with more details. Will try to fix this properly tomorrow.

A bunch of tests to check that the specification stuff is passed
through correctly. More tests to test_undo.py to provide better 
test coverage are needed.


=== Zope3/src/zope/app/browser/tests/test_zodbundomanager.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/browser/tests/test_zodbundomanager.py:1.3	Wed Apr 30 19:37:58 2003
+++ Zope3/src/zope/app/browser/tests/test_zodbundomanager.py	Thu Jul 10 08:42:15 2003
@@ -26,11 +26,14 @@
 testdata = [
     dict(id='1', user_name='jim', time=time(), description='des 1'),
     dict(id='2', user_name='jim', time=time(), description='des 2'),
-    dict(id='3', user_name='jim', time=time(), description='des 3'),
+    dict(id='3', user_name='anthony', time=time(), description='des 3'),
     dict(id='4', user_name='jim', time=time(), description='des 4'),
-    dict(id='5', user_name='jim', time=time(), description='des 5'),
-    dict(id='6', user_name='jim', time=time(), description='des 6'),
+    dict(id='5', user_name='anthony', time=time(), description='des 5'),
+    dict(id='6', user_name='anthony', time=time(), description='des 6'),
     dict(id='7', user_name='jim', time=time(), description='des 7'),
+    dict(id='8', user_name='anthony', time=time(), description='des 8'),
+    dict(id='9', user_name='jim', time=time(), description='des 9'),
+    dict(id='10', user_name='jim', time=time(), description='des 10'),
     ]
 testdata.reverse()
 
@@ -39,8 +42,29 @@
     def __init__(self):
         self.data = list(testdata)
 
-    def undoInfo(self):
-        return tuple(self.data)
+    def undoInfo(self, first=0, last=-20, specification=None):
+        if last < 0:
+            last = first - last + 1
+        # This code ripped off from zodb.storage.base.BaseStorage.undoInfo
+        if specification:
+            def filter(desc, spec=specification.items()):
+                for k, v in spec:
+                    if desc.get(k) != v:
+                        return False
+                return True
+        else:
+            filter = None
+        if not filter:
+            # handle easy case first
+            data = self.data[first:last]
+        else:
+            data = []
+            for x in self.data[first:]:
+                if filter(x): 
+                    data.append(x)
+                if len(data) >= last:
+                    break
+        return data
 
     def undo(self, id):
         self.data = [d for d in self.data if d['id'] != id]
@@ -53,11 +77,24 @@
 
         self.assertEqual(list(um.getUndoInfo()), testdata)
 
+        txid = [d['id'] for d in um.getUndoInfo(first=0,last=-3)]
+        self.assertEqual(txid, ['10','9','8','7'])
+        txid = [d['id'] for d in um.getUndoInfo(first=0,last=3)]
+        self.assertEqual(txid, ['10','9','8'])
+        txid = [d['id'] 
+                for d in um.getUndoInfo(first=0, last=3, user_name='anthony')]
+        self.assertEqual(txid, ['8','6','5'])
+        txid = [d['id'] for d in um.getUndoInfo(user_name='anthony')]
+        self.assertEqual(txid, ['8','6','5','3'])
+
         um.undoTransaction(('3','4','5'))
-        expected = testdata
-        expected = [d for d in expected if (d['id'] not in ('3','4','5'))]
 
+        expected = [d for d in testdata if (d['id'] not in ('3','4','5'))]
         self.assertEqual(list(um.getUndoInfo()), expected)
+
+        txid = [d['id'] for d in um.getUndoInfo(user_name='anthony')]
+        self.assertEqual(txid, ['8','6'])
+
 
 def test_suite():
     return makeSuite(Test)