Back to index

plone3  3.1.7
Public Member Functions
CMFEditions.tests.test_ZVCStorageTool.TestMemoryStorage Class Reference
Inheritance diagram for CMFEditions.tests.test_ZVCStorageTool.TestMemoryStorage:
Inheritance graph
[legend]
Collaboration diagram for CMFEditions.tests.test_ZVCStorageTool.TestMemoryStorage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def installStorageTool
def afterSetUp
def installPurgePolicyTool
def buildMetadata
def getComment
def test00_interface
def test01_saveAfterRegisteringDoesNotRaiseException
def test02_saveUnregisteredObjectRaisesException
def test03_saveAndRetrieve
def test05_getHistory
def test06_checkObjectManagerIntegrity
def test07_getModificationDate
def test08_lengthAfterHavingPurgedAVersion
def test09_retrievePurgedVersionsNoPolicyInstalled
def test10_retrievePurgedVersionsWithPolicyInstalled
def test11_purgeOnSave
def test12_retrieveNonExistentVersion
def test13_saveWithUnicodeComment

Detailed Description

Definition at line 434 of file test_ZVCStorageTool.py.


Member Function Documentation

Definition at line 49 of file test_ZVCStorageTool.py.

00049 
00050     def afterSetUp(self):
00051         # we need to have the Manager role to be able to add things
00052         # to the portal root
00053         self.setRoles(['Manager',])
00054 
00055         # add an additional user
00056         self.portal.acl_users.userFolderAddUser('reviewer', 'reviewer',
00057                                                 ['Manager'], '')
00058         
00059         # eventually install another storage 
00060         self.installStorageTool()
00061 
00062         # delete purge policy if there is one installed
00063         try:
00064             del self.portal.portal_purgepolicy
00065         except AttributeError:
00066             pass

Here is the call graph for this function:

Definition at line 77 of file test_ZVCStorageTool.py.

00077 
00078     def buildMetadata(self, comment):
00079         return {'sys_metadata': {'comment': comment}}

Here is the caller graph for this function:

Definition at line 80 of file test_ZVCStorageTool.py.

00080 
00081     def getComment(self, vdata):
00082         return vdata.metadata["sys_metadata"]["comment"]

Here is the caller graph for this function:

Definition at line 71 of file test_ZVCStorageTool.py.

00071 
00072     def installPurgePolicyTool(self):
00073         self._setDummyTool(DummyPurgePolicy())

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from CMFEditions.tests.test_ZVCStorageTool.TestZVCStorageTool.

Definition at line 436 of file test_ZVCStorageTool.py.

00436 
00437     def installStorageTool(self):
00438         # install the memory storage
00439         tool = MemoryStorage()
00440         setattr(self.portal, tool.getId(), tool)

Here is the call graph for this function:

Definition at line 83 of file test_ZVCStorageTool.py.

00083 
00084     def test00_interface(self):
00085         portal_storage = self.portal.portal_historiesstorage
00086 
00087         # test interface conformance
00088         verifyObject(IStorage, portal_storage)
00089         verifyObject(IPurgeSupport, portal_storage)

Definition at line 90 of file test_ZVCStorageTool.py.

00090 
00091     def test01_saveAfterRegisteringDoesNotRaiseException(self):
00092         portal_storage = self.portal.portal_historiesstorage
00093         obj = Dummy()
00094         
00095         sel = portal_storage.register(1, ObjectData(obj), 
00096                                       metadata=self.buildMetadata('saved'))
00097         self.assertEqual(sel, 0)
00098         sel = portal_storage.save(1, ObjectData(obj), 
00099                                   metadata=self.buildMetadata('saved'))
00100         self.assertEqual(sel, 1)

Here is the call graph for this function:

Definition at line 101 of file test_ZVCStorageTool.py.

00101 
00102     def test02_saveUnregisteredObjectRaisesException(self):
00103         portal_storage = self.portal.portal_historiesstorage
00104         obj = Dummy()
00105 
00106         self.assertRaises(StorageUnregisteredError,
00107                           portal_storage.save,
00108                           1, ObjectData(obj), metadata=self.buildMetadata('saved'))

Here is the call graph for this function:

Definition at line 109 of file test_ZVCStorageTool.py.

00109 
00110     def test03_saveAndRetrieve(self):
00111         portal_storage = self.portal.portal_historiesstorage
00112 
00113         obj1 = Dummy()
00114         obj1.text = 'v1 of text'
00115         portal_storage.register(1, ObjectData(obj1), metadata=self.buildMetadata('saved v1'))
00116 
00117         obj2 = Dummy()
00118         obj2.text = 'v2 of text'
00119         portal_storage.save(1, ObjectData(obj2), metadata=self.buildMetadata('saved v2'))
00120 
00121         # retrieve the state at registration time
00122         retrieved_obj = portal_storage.retrieve(history_id=1, selector=0)
00123         self.assertEqual(retrieved_obj.object.object.text, 'v1 of text')
00124         self.assertEqual(self.getComment(retrieved_obj), 'saved v1')
00125 
00126         # just check if first save wasn't a double save
00127         retrieved_obj = portal_storage.retrieve(history_id=1, selector=1)
00128         self.assertEqual(retrieved_obj.object.object.text, 'v2 of text')
00129         self.assertEqual(self.getComment(retrieved_obj), 'saved v2')

Here is the call graph for this function:

Definition at line 130 of file test_ZVCStorageTool.py.

00130 
00131     def test05_getHistory(self):
00132         portal_storage = self.portal.portal_historiesstorage
00133         
00134         obj1 = Dummy()
00135         obj1.text = 'v1 of text'
00136         portal_storage.register(1, ObjectData(obj1), 
00137                                 metadata=self.buildMetadata('saved v1'))
00138         
00139         obj2 = Dummy()
00140         obj2.text = 'v2 of text'
00141         portal_storage.save(1, ObjectData(obj2), 
00142                             metadata=self.buildMetadata('saved v2'))
00143         
00144         obj3 = Dummy()
00145         obj3.text = 'v3 of text'
00146         portal_storage.save(1, ObjectData(obj3), 
00147                             metadata=self.buildMetadata('saved v3'))
00148         
00149         history = portal_storage.getHistory(history_id=1)
00150         length = len(history)
00151         
00152         # check length
00153         self.assertEquals(length, 3)
00154         
00155         # iterating over the history
00156         for i, vdata in enumerate(history):
00157             expected_test = 'v%s of text' % (i+1)
00158             self.assertEquals(vdata.object.object.text, expected_test)
00159             self.assertEquals(history[i].object.object.text, expected_test)
00160             
00161             expected_comment = 'saved v%s' % (i+1)
00162             self.assertEqual(self.getComment(vdata), expected_comment)
00163             self.assertEqual(self.getComment(history[i]), expected_comment)
00164             
00165         # accessing the versions
00166         self.assertEquals(history[0].object.object.text, "v1 of text")
00167         self.assertEqual(self.getComment(history[0]), "saved v1")
00168         self.assertEquals(history[1].object.object.text, "v2 of text")
00169         self.assertEqual(self.getComment(history[1]), "saved v2")
00170         self.assertEquals(history[2].object.object.text, "v3 of text")
00171         self.assertEqual(self.getComment(history[2]), "saved v3")

Here is the call graph for this function:

Definition at line 172 of file test_ZVCStorageTool.py.

00172 
00173     def test06_checkObjectManagerIntegrity(self):
00174         portal_storage = self.portal.portal_historiesstorage
00175         
00176         om = DummyOM()
00177         sub1 = Dummy()
00178         sub2 = Dummy()
00179         om._setObject('sub1', sub1)
00180         om._setObject('sub2', sub2)
00181         self.assertEqual(len(om.objectIds()), 2)
00182         portal_storage.register(1, ObjectData(om), metadata=self.buildMetadata('saved v1'))
00183         vdata = portal_storage.retrieve(history_id=1, selector=0)
00184         retrieved_om = vdata.object
00185         self.assertEqual(len(retrieved_om.object.objectIds()), 2)

Here is the call graph for this function:

Definition at line 186 of file test_ZVCStorageTool.py.

00186 
00187     def test07_getModificationDate(self):
00188         portal_storage = self.portal.portal_historiesstorage
00189         obj = Dummy()
00190         v1_modified = obj.modified()
00191         v1 = portal_storage.register(history_id=1, object=ObjectData(obj), metadata=self.buildMetadata('saved v1'))
00192         
00193         self.assertEqual(v1_modified, portal_storage.getModificationDate(history_id=1))
00194         self.assertEqual(v1_modified, portal_storage.getModificationDate(history_id=1, selector=v1))
00195 
00196         #storage never gets the same object twice, because the archivist always generates another copy on save,
00197         #which then have a diffrent python id.
00198 
00199         #simulate object copy
00200         notifyModified(obj)
00201         obj = Dummy()
00202         v2_modified = obj.modified()
00203         v2 = portal_storage.save(history_id=1, object=ObjectData(obj), metadata=self.buildMetadata('saved v2'))
00204         self.assertNotEquals(v1, v2)
00205         self.assertEqual(v2_modified, portal_storage.getModificationDate(history_id=1))
00206         self.assertEqual(v2_modified, portal_storage.getModificationDate(history_id=1, selector=v2))
00207         self.assertEqual(v1_modified, portal_storage.getModificationDate(history_id=1, selector=v1))

Here is the call graph for this function:

Definition at line 227 of file test_ZVCStorageTool.py.

00227 
00228     def test08_lengthAfterHavingPurgedAVersion(self):
00229         self._setupMinimalHistory()
00230         portal_storage = self.portal.portal_historiesstorage
00231         
00232         # purge a version
00233         portal_storage.purge(1, 1, metadata=self.buildMetadata("purged v2"))
00234         
00235         # check length
00236         lenWith = len(portal_storage.getHistory(1, countPurged=True))
00237         self.assertEqual(lenWith, 4)
00238         lenWithout = len(portal_storage.getHistory(1, countPurged=False))
00239         self.assertEqual(lenWithout, 3)
00240         
00241         # purge again the same version (should not change the purge count)
00242         portal_storage.purge(1, 1, metadata=self.buildMetadata("purged v2"))
00243         
00244         # check again getLength (unchanged behaviour)
00245         lenWith = len(portal_storage.getHistory(1, countPurged=True))
00246         self.assertEqual(lenWith, 4)
00247         lenWithout = len(portal_storage.getHistory(1, countPurged=False))
00248         self.assertEqual(lenWithout, 3)

Here is the call graph for this function:

Definition at line 249 of file test_ZVCStorageTool.py.

00249 
00250     def test09_retrievePurgedVersionsNoPolicyInstalled(self):
00251         self._setupMinimalHistory()
00252         portal_storage = self.portal.portal_historiesstorage
00253         
00254         # purge a version
00255         portal_storage.purge(1, 2, metadata=self.buildMetadata("purged v3"))
00256         
00257         # ``retrieve`` returns the removed info because there is no purge 
00258         # policy installed
00259         retrieved_obj = portal_storage.retrieve(history_id=1, selector=2)
00260         self.failIf(retrieved_obj.isValid())
00261         self.assertEqual(retrieved_obj.object.reason, "purged")
00262         self.assertEqual(self.getComment(retrieved_obj), "purged v3")
00263         
00264         retrieved_obj = portal_storage.retrieve(history_id=1, selector=2, 
00265                                                 substitute=False)
00266         self.failIf(retrieved_obj.isValid())
00267         self.assertEqual(retrieved_obj.object.reason, "purged")
00268         self.assertEqual(self.getComment(retrieved_obj), "purged v3")
00269 
00270         retrieved_obj = portal_storage.retrieve(history_id=1, selector=2, 
00271                                                 countPurged=False)
00272         self.failUnless(retrieved_obj.isValid())
00273         self.assertEqual(retrieved_obj.object.object.text, 'v4 of text')
00274         self.assertEqual(self.getComment(retrieved_obj), 'saved v4')
        

Here is the call graph for this function:

Definition at line 275 of file test_ZVCStorageTool.py.

00275 
00276     def test10_retrievePurgedVersionsWithPolicyInstalled(self):
00277         self._setupMinimalHistory()
00278         portal_storage = self.portal.portal_historiesstorage
00279         
00280         # install the purge policy that returns the next older not removed
00281         self.installPurgePolicyTool()
00282         
00283         # purge
00284         portal_storage.purge(1, 1, metadata=self.buildMetadata("purged v2"))
00285         lenAll = len(portal_storage.getHistory(1))
00286         lenEff = len(portal_storage.getHistory(1, countPurged=False))
00287         self.assertEqual(lenAll, 4)
00288         self.assertEqual(lenEff, 3)
00289         
00290         # purge
00291         portal_storage.purge(1, 2, metadata=self.buildMetadata("purged v3"))
00292         lenAll = len(portal_storage.getHistory(1))
00293         lenEff = len(portal_storage.getHistory(1, countPurged=False))
00294         self.assertEqual(lenAll, 4)
00295         self.assertEqual(lenEff, 2)
00296         
00297         # ``retrieve`` returns the next older object 
00298         retrieved_obj = portal_storage.retrieve(history_id=1, selector=1)
00299         self.failUnless(retrieved_obj.isValid())
00300         self.assertEqual(retrieved_obj.object.object.text, 'v1 of text')
00301         self.assertEqual(self.getComment(retrieved_obj), 'saved v1')
00302         
00303         retrieved_obj = portal_storage.retrieve(history_id=1, selector=2)
00304         self.failUnless(retrieved_obj.isValid())
00305         self.assertEqual(retrieved_obj.object.object.text, 'v1 of text')
00306         self.assertEqual(self.getComment(retrieved_obj), 'saved v1')
00307         
00308         # ``retrieve`` returns existing object
00309         retrieved_obj = portal_storage.retrieve(history_id=1, selector=3)
00310         self.failUnless(retrieved_obj.isValid())
00311         self.assertEqual(retrieved_obj.object.object.text, 'v4 of text')
00312         self.assertEqual(self.getComment(retrieved_obj), 'saved v4')
00313         
00314         # check with substitute=False: should return the removed info
00315         retrieved_obj = portal_storage.retrieve(history_id=1, selector=1, 
00316                                                 substitute=False)
00317         self.failIf(retrieved_obj.isValid())
00318         self.assertEqual(retrieved_obj.object.reason, "purged")
00319         self.assertEqual(self.getComment(retrieved_obj), "purged v2")
00320         retrieved_obj = portal_storage.retrieve(history_id=1, selector=2,
00321                                                 substitute=False)
00322         self.failIf(retrieved_obj.isValid())
00323         self.assertEqual(retrieved_obj.object.reason, "purged")
00324         self.assertEqual(self.getComment(retrieved_obj), "purged v3")

Here is the call graph for this function:

Definition at line 325 of file test_ZVCStorageTool.py.

00325 
00326     def test11_purgeOnSave(self):
00327         # install the purge policy that removes all except the current and 
00328         # previous objects
00329         self.installPurgePolicyTool()
00330         portal_storage = self.portal.portal_historiesstorage
00331         
00332         # save no 1
00333         obj1 = Dummy()
00334         obj1.text = 'v1 of text'
00335         
00336         sel = portal_storage.register(1, ObjectData(obj1), 
00337                                       metadata=self.buildMetadata('saved v1'))
00338         history = portal_storage.getHistory(1, countPurged=False)
00339         
00340         self.assertEquals(sel, 0)
00341         self.assertEquals(len(history), 1)
00342         self.assertEqual(history[0].object.object.text, 'v1 of text')
00343         self.assertEqual(self.getComment(history[0]), 'saved v1')
00344         
00345         # save no 2
00346         obj2 = Dummy()
00347         obj2.text = 'v2 of text'
00348         sel = portal_storage.save(1, ObjectData(obj2), 
00349                                   metadata=self.buildMetadata('saved v2'))
00350         history = portal_storage.getHistory(1, countPurged=False)
00351         
00352         self.assertEquals(sel, 1)
00353         self.assertEquals(len(history), 2)
00354         self.assertEqual(history[0].object.object.text, 'v1 of text')
00355         self.assertEqual(self.getComment(history[0]), 'saved v1')
00356         self.assertEqual(history[1].object.object.text, 'v2 of text')
00357         self.assertEqual(self.getComment(history[1]), 'saved v2')
00358         
00359         # save no 3: purged oldest version
00360         obj3 = Dummy()
00361         obj3.text = 'v3 of text'
00362         sel = portal_storage.save(1, ObjectData(obj3), 
00363                                   metadata=self.buildMetadata('saved v3'))
00364         history = portal_storage.getHistory(1, countPurged=False)
00365         length = len(history)
00366         
00367         # iterating over the history
00368         for i, vdata in enumerate(history):
00369             self.assertEquals(vdata.object.object.text, 
00370                               'v%s of text' % (i+2))
00371             self.assertEqual(self.getComment(vdata), 
00372                              'saved v%s' % (i+2))
00373             
00374         self.assertEquals(sel, 2)
00375         self.assertEquals(length, 2)
00376         self.assertEqual(history[0].object.object.text, 'v2 of text')
00377         self.assertEqual(self.getComment(history[0]), 'saved v2')
00378         self.assertEqual(history[1].object.object.text, 'v3 of text')
00379         self.assertEqual(self.getComment(history[1]), 'saved v3')
00380         
00381         # save no 4: purged oldest version
00382         obj4 = Dummy()
00383         obj4.text = 'v4 of text'
00384         sel = portal_storage.save(1, ObjectData(obj4), 
00385                                   metadata=self.buildMetadata('saved v4'))
00386         history = portal_storage.getHistory(1, countPurged=False)
00387         length = len(history)
00388         
00389         # iterating over the history
00390         for i, vdata in enumerate(history):
00391             self.assertEquals(vdata.object.object.text, 
00392                               'v%s of text' % (i+3))
00393             self.assertEqual(self.getComment(vdata), 
00394                              'saved v%s' % (i+3))
00395             
00396         self.assertEquals(sel, 3)
00397         self.assertEquals(length, 2)
00398         self.assertEqual(history[0].object.object.text, 'v3 of text')
00399         self.assertEqual(self.getComment(history[0]), 'saved v3')
00400         self.assertEqual(history[1].object.object.text, 'v4 of text')
00401         self.assertEqual(self.getComment(history[1]), 'saved v4')

Here is the call graph for this function:

Definition at line 402 of file test_ZVCStorageTool.py.

00402 
00403     def test12_retrieveNonExistentVersion(self):
00404         portal_storage = self.portal.portal_historiesstorage
00405 
00406         obj1 = Dummy()
00407         obj1.text = 'v1 of text'
00408         portal_storage.register(1, ObjectData(obj1), metadata=self.buildMetadata('saved v1'))
00409 
00410         obj2 = Dummy()
00411         obj2.text = 'v2 of text'
00412         portal_storage.save(1, ObjectData(obj2), metadata=self.buildMetadata('saved v2'))
00413 
00414         # purge
00415         portal_storage.purge(1, 0, metadata=self.buildMetadata("purged v1"))
00416         
00417         # retrieve non existing version
00418         self.assertRaises(StorageRetrieveError,
00419                           portal_storage.retrieve, history_id=1, selector=2, 
00420                           countPurged=True, substitute=True)
00421 
00422         self.assertRaises(StorageRetrieveError,
00423                           portal_storage.retrieve, history_id=1, selector=1, 
00424                           countPurged=False)

Here is the call graph for this function:

Definition at line 425 of file test_ZVCStorageTool.py.

00425 
00426     def test13_saveWithUnicodeComment(self):
00427         portal_storage = self.portal.portal_historiesstorage
00428         obj1 = Dummy()
00429         obj1.text = 'v1 of text'
00430         portal_storage.register(1, ObjectData(obj1),
00431                                 metadata=self.buildMetadata('saved v1'))
00432         portal_storage.save(1, ObjectData(obj1),
00433                             metadata=self.buildMetadata(u'saved v1\xc3\xa1'))

Here is the call graph for this function:


The documentation for this class was generated from the following file: