[Zope3-checkins] CVS: Zope3/src/zope/app/browser/tests - test_undo.py:1.1.2.1 test_zodbundomanager.py:1.1.2.1
Jim Fulton
jim@zope.com
Tue, 24 Dec 2002 18:58:00 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv1437/src/zope/app/browser/tests
Added Files:
Tag: NameGeddon-branch
test_undo.py test_zodbundomanager.py
Log Message:
Moved undo view to browser tree and fixed some more zcml files
=== Added File Zope3/src/zope/app/browser/tests/test_undo.py ===
##############################################################################
#
# 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: test_undo.py,v 1.1.2.1 2002/12/24 23:57:59 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.interfaces.undo import IUndoManager
from zope.app.browser.undo import Undo
from zope.app.services.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.component 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 makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/app/browser/tests/test_zodbundomanager.py ===
##############################################################################
#
# 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: test_zodbundomanager.py,v 1.1.2.1 2002/12/24 23:57:59 jim Exp $
"""
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.browser.undo 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 makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')