From: Tomek <tom...@us...> - 2005-02-23 19:11:25
|
Update of /cvsroot/collective/CMFEditions/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20725/tests Modified Files: DummyTools.py test_ArchivistTool.py test_ZVCStorageTool.py Log Message: adapted interface, so that we use in storage tests the same klasses as archivist uses. In tests/test_ZVCStorageTool there are two tests now, one for Memory Storage, one for ZVCStorage Index: test_ZVCStorageTool.py =================================================================== RCS file: /cvsroot/collective/CMFEditions/tests/test_ZVCStorageTool.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- test_ZVCStorageTool.py 23 Feb 2005 17:09:31 -0000 1.10 +++ test_ZVCStorageTool.py 23 Feb 2005 19:10:21 -0000 1.11 @@ -39,12 +39,16 @@ from Products.CMFEditions.Extensions import Install from Products.CMFEditions.interfaces.IStorage import IStorage +from Products.CMFEditions.interfaces.IStorage import StorageUnregisteredError from Products.CMFEditions import UniqueIdHandlerTool from Products.CMFEditions import ModifierRegistryTool from Products.CMFEditions import ArchivistTool +from Products.CMFEditions.ArchivistTool import ObjectData from Products.CMFEditions import ZVCStorageTool from Products.CMFEditions import CopyModifyMergeRepositoryTool +from DummyTools import MemoryStorage +from DummyTools import Dummy as Dummy # install additional products CMFTestCase.installProduct('CMFUid') @@ -53,10 +57,6 @@ # Create a CMF site in the test (demo-) storage CMFTestCase.setupCMFSite() -class DummyObject(SimpleItem): - def ModificationDate(self): - return self.bobobase_modification_time().ISO() - class DummyOM(ObjectManager): pass @@ -103,109 +103,115 @@ def test01_saveAfterRegisteringDoesNotRaiseException(self): portal_storage = self.portal.portal_historiesstorage - obj = DummyObject() + obj = Dummy() - portal_storage.register(1, obj, metadata=self.buildMetadata('saved')) - portal_storage.save(1, obj, metadata=self.buildMetadata('saved')) + portal_storage.register(1, ObjectData(obj), metadata=self.buildMetadata('saved')) + portal_storage.save(1, ObjectData(obj), metadata=self.buildMetadata('saved')) def test02_saveUnregisteredObjectRaisesException(self): portal_storage = self.portal.portal_historiesstorage - obj = DummyObject() + obj = Dummy() - self.assertRaises(portal_storage.StorageError, + self.assertRaises(StorageUnregisteredError, portal_storage.save, - 1, obj, metadata=self.buildMetadata('saved')) + 1, ObjectData(obj), metadata=self.buildMetadata('saved')) def test03_saveAndRetrieve(self): portal_storage = self.portal.portal_historiesstorage - obj1 = DummyObject() + obj1 = Dummy() obj1.text = 'v1 of text' - portal_storage.register(1, obj1, metadata=self.buildMetadata('saved v1')) + portal_storage.register(1, ObjectData(obj1), metadata=self.buildMetadata('saved v1')) - obj2 = DummyObject() + obj2 = Dummy() obj2.text = 'v2 of text' - portal_storage.save(1, obj2, metadata=self.buildMetadata('saved v2')) + portal_storage.save(1, ObjectData(obj2), metadata=self.buildMetadata('saved v2')) retrieved_obj = portal_storage.retrieve(history_id=1, selector=0) - self.assertEqual(retrieved_obj.object.text, 'v1 of text') + self.assertEqual(retrieved_obj.object.object.text, 'v1 of text') self.assertEqual(self.getComment(retrieved_obj.metadata), 'saved v1') # just check if first save wasn't a double save retrieved_obj = portal_storage.retrieve(history_id=1, selector=1) - self.assertEqual(retrieved_obj.object.text, 'v2 of text') + self.assertEqual(retrieved_obj.object.object.text, 'v2 of text') self.assertEqual(self.getComment(retrieved_obj.metadata), 'saved v2') def test04_getHistory(self): portal_storage = self.portal.portal_historiesstorage - obj1 = DummyObject() + obj1 = Dummy() obj1.text = 'v1 of text' - portal_storage.register(1, obj1, metadata=self.buildMetadata('saved v1')) + portal_storage.register(1, ObjectData(obj1), metadata=self.buildMetadata('saved v1')) - obj2 = DummyObject() + obj2 = Dummy() obj2.text = 'v2 of text' - portal_storage.save(1, obj2, metadata=self.buildMetadata('saved v2')) + portal_storage.save(1, ObjectData(obj2), metadata=self.buildMetadata('saved v2')) - obj3 = DummyObject() + obj3 = Dummy() obj3.text = 'v3 of text' - portal_storage.save(1, obj3, metadata=self.buildMetadata('saved v3')) + portal_storage.save(1, ObjectData(obj3), metadata=self.buildMetadata('saved v3')) # XXX need to test for history[selector].data and history[selector].metadata history = portal_storage.getHistory(history_id=1) self.assertEquals(len(history), 3) - self.assertEquals(history[0].object.text, obj1.text) + self.assertEquals(history[0].object.object.text, obj1.text) self.assertEqual(self.getComment(history[0].metadata), 'saved v1') - self.assertEquals(history[1].object.text, obj2.text) + self.assertEquals(history[1].object.object.text, obj2.text) self.assertEqual(self.getComment(history[1].metadata), 'saved v2') - self.assertEquals(history[2].object.text, obj3.text) + self.assertEquals(history[2].object.object.text, obj3.text) self.assertEqual(self.getComment(history[2].metadata), 'saved v3') def test05_iterateOverHistory(self): portal_storage = self.portal.portal_historiesstorage - obj1 = DummyObject() + obj1 = Dummy() obj1.text = 'v1 of text' - portal_storage.register(1, obj1, metadata=self.buildMetadata('saved v1')) + portal_storage.register(1, ObjectData(obj1), metadata=self.buildMetadata('saved v1')) - obj2 = DummyObject() + obj2 = Dummy() obj2.text = 'v2 of text' - portal_storage.save(1, obj2, metadata=self.buildMetadata('saved v2')) + portal_storage.save(1, ObjectData(obj2), metadata=self.buildMetadata('saved v2')) - obj3 = DummyObject() + obj3 = Dummy() obj3.text = 'v3 of text' - portal_storage.save(1, obj3, metadata=self.buildMetadata('saved v3')) + portal_storage.save(1, ObjectData(obj3), metadata=self.buildMetadata('saved v3')) counter = 0 for vdata in portal_storage.getHistory(history_id=1): counter += 1 - self.assertEqual(vdata.object.text, 'v%s of text' % counter) + self.assertEqual(vdata.object.object.text, 'v%s of text' % counter) self.assertEqual(self.getComment(vdata.metadata), 'saved v%s' % counter) def test06_checkObjectManagerIntegrity(self): portal_storage = self.portal.portal_historiesstorage om = DummyOM() - sub1 = DummyObject() - sub2 = DummyObject() + sub1 = Dummy() + sub2 = Dummy() om._setObject('sub1', sub1) om._setObject('sub2', sub2) self.assertEqual(len(om.objectIds()), 2) - portal_storage.register(1, om, metadata=self.buildMetadata('saved v1')) + portal_storage.register(1, ObjectData(om), metadata=self.buildMetadata('saved v1')) vdata = portal_storage.retrieve(history_id=1, selector=0) retrieved_om = vdata.object - self.assertEqual(len(retrieved_om.objectIds()), 2) + self.assertEqual(len(retrieved_om.object.objectIds()), 2) def test07_getModificationDate(self): portal_storage = self.portal.portal_historiesstorage - obj = DummyObject() - portal_storage.register(history_id=1, object=obj, metadata=self.buildMetadata('saved')) + obj = Dummy() + portal_storage.register(history_id=1, object=ObjectData(obj), metadata=self.buildMetadata('saved')) self.failUnless(obj.ModificationDate()) self.failUnless(portal_storage.getModificationDate(history_id=1)) self.assertEqual(obj.ModificationDate(), portal_storage.getModificationDate(history_id=1)) - + + +class TestMemoryStorage(TestZVCStorageTool): + + def installStorageTool(self): + tool = MemoryStorage() + setattr(self.portal, tool.getId(), tool) if __name__ == '__main__': framework() @@ -214,4 +220,5 @@ def test_suite(): suite = TestSuite() suite.addTest(makeSuite(TestZVCStorageTool)) + suite.addTest(makeSuite(TestMemoryStorage)) return suite Index: DummyTools.py =================================================================== RCS file: /cvsroot/collective/CMFEditions/tests/DummyTools.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DummyTools.py 23 Feb 2005 17:09:28 -0000 1.1 +++ DummyTools.py 23 Feb 2005 19:10:18 -0000 1.2 @@ -10,6 +10,8 @@ from Products.CMFEditions.interfaces.IArchivist import IArchivist from Products.CMFEditions.interfaces.IModifier import IModifier from Products.CMFEditions.interfaces.IStorage import IStreamableReference +from Products.CMFEditions.interfaces.IStorage import IStorage +from Products.CMFEditions.interfaces.IStorage import StorageUnregisteredError from Products.CMFCore.utils import getToolByName from cPickle import Pickler, Unpickler from pickle import dumps, loads @@ -382,29 +384,31 @@ selector = -1 return types.ListType.__getitem__(self, selector) -class StreamableReferencedPart: - __implements__ = (IStreamableReference, ) - - def __init__(self, obj): - self._obj = obj - - def getObject(self): - return self._obj - +class MemoryStorage(DummyBaseTool): -class DummyStorage(DummyBaseTool): + __implements__ = IStorage id = 'portal_historiesstorage' + def __init__(self): self._histories = {} def register(self, history_id, object, referenced_data={}, metadata=None): histories = self._histories - if history_id in histories.keys(): - return - return self.save(history_id, object, referenced_data, metadata) + if history_id not in histories.keys(): + return self._save(history_id, object, referenced_data, metadata) def save(self, history_id, object, referenced_data={}, metadata=None): + if not self._histories.has_key(history_id): + raise StorageUnregisteredError( + "Saving or retrieving an unregistered object is not " + "possible. Register the object with history id '%s' first. " + % history_id) + + return self._save(history_id, object, referenced_data, metadata) + + + def _save(self, history_id, object, referenced_data={}, metadata=None): histories = self._histories cloned_referenced_data = {} @@ -444,7 +448,6 @@ histories = self._histories[history_id] except KeyError: return default - return histories return HistoryList(histories) def isRegistered(self, history_id): @@ -452,5 +455,6 @@ def getModificationDate(self, history_id, selector=None): vdata = self.retrieve(history_id, selector) + #import pdb; pdb.set_trace() return vdata.object.object.ModificationDate() Index: test_ArchivistTool.py =================================================================== RCS file: /cvsroot/collective/CMFEditions/tests/test_ArchivistTool.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- test_ArchivistTool.py 23 Feb 2005 17:09:29 -0000 1.7 +++ test_ArchivistTool.py 23 Feb 2005 19:10:18 -0000 1.8 @@ -49,7 +49,7 @@ from DummyTools import DummyModifier from DummyTools import DummyHistoryIdHandler -from DummyTools import DummyStorage +from DummyTools import MemoryStorage from DummyTools import FolderishContentObjectModifier @@ -78,7 +78,7 @@ tools = ( DummyModifier(), DummyHistoryIdHandler(), - DummyStorage() + MemoryStorage() ) for tool in tools: self._setDummyTool(tool) |