[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Undo/tests - __init__.py:1.2 testUndo.py:1.2 testZODBUndoManager.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:28:49 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Undo/tests
In directory cvs.zope.org:/tmp/cvs-serv17445/lib/python/Zope/App/Undo/tests
Added Files:
__init__.py testUndo.py testZODBUndoManager.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/App/Undo/tests/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+# empty __init__.py to make this into a package
=== Zope3/lib/python/Zope/App/Undo/tests/testUndo.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from Zope.App.Undo.IUndoManager import IUndoManager
+from Zope.App.Undo.Undo import Undo
+from Zope.App.OFS.Services.ServiceManager.tests.PlacefulSetup\
+ import PlacefulSetup
+
+class TestIUndoManager:
+ __implements__ = IUndoManager
+
+ def __init__(self):
+ dict1 = {'id': '1', 'user_name': 'monkey', 'description': 'thing1',
+ 'time': 'today'}
+ dict2 = {'id': '2', 'user_name': 'monkey', 'description': 'thing2',
+ 'time': 'today'}
+ dict3 = {'id': '3', 'user_name': 'monkey', 'description': 'thing3',
+ 'time': 'today'}
+
+ self.dummy_db = [dict1, dict2, dict3]
+
+ def getUndoInfo(self):
+ return self.dummy_db
+
+ def undoTransaction(self, id_list):
+ # just remove an element for now
+ temp_dict = {}
+ for db_record in self.dummy_db:
+ if db_record['id'] not in id_list:
+ temp_dict[db_record['id']] = db_record
+
+ self.dummy_db = []
+ for key in temp_dict.keys():
+ self.dummy_db.append(temp_dict[key])
+
+
+class Test(PlacefulSetup, TestCase):
+
+ def setUp(self):
+ PlacefulSetup.setUp(self)
+ from Zope.ComponentArchitecture import getService
+ getService(None,'Utilities').provideUtility(IUndoManager,
+ TestIUndoManager())
+
+ def testGetUndoInfo(self):
+ view = Undo(None, None)
+
+ self.assertEqual(view.getUndoInfo(), TestIUndoManager().getUndoInfo())
+
+
+ def testUndoSingleTransaction(self):
+ view = Undo(None, None)
+ id_list = ['1']
+ view.action(id_list)
+
+ testum = TestIUndoManager()
+ testum.undoTransaction(id_list)
+
+ self.assertEqual(view.getUndoInfo(), testum.getUndoInfo())
+
+ def testUndoManyTransactions(self):
+ view = Undo(None, None)
+ id_list = ['1','2','3']
+ view.action(id_list)
+
+ testum = TestIUndoManager()
+ testum.undoTransaction(id_list)
+
+ self.assertEqual(view.getUndoInfo(), testum.getUndoInfo())
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
=== Zope3/lib/python/Zope/App/Undo/tests/testZODBUndoManager.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from time import time
+
+def dict(**kw): return kw
+
+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='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='7', user_name='jim', time=time(), description='des 7'),
+ ]
+testdata.reverse()
+
+class StubDB:
+
+ def __init__(self):
+ self.data = list(testdata)
+
+ def undoInfo(self):
+ return tuple(self.data)
+
+ def undo(self, id):
+ self.data = [d for d in self.data if d['id'] != id]
+
+class Test(CleanUp, TestCase):
+
+ def test(self):
+ from Zope.App.Undo.ZODBUndoManager import ZODBUndoManager
+ um = ZODBUndoManager(StubDB())
+
+ self.assertEqual(list(um.getUndoInfo()), testdata)
+
+ um.undoTransaction(('3','4','5'))
+ expected = testdata
+ expected = [d for d in expected if (d['id'] not in ('3','4','5'))]
+
+ self.assertEqual(list(um.getUndoInfo()), expected)
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')