Back to index

plone3  3.1.7
test_events.py
Go to the documentation of this file.
00001 import unittest
00002 import transaction
00003 
00004 from plone.app.redirector.tests.base import RedirectorTestCase
00005 
00006 from zope.component import getUtility
00007 from plone.app.redirector.interfaces import IRedirectionStorage
00008 
00009 class TestRedirectorEvents(RedirectorTestCase):
00010     """Ensure that the redirector event subscribers behave as expected.
00011     """
00012 
00013     @property
00014     def storage(self):
00015         return getUtility(IRedirectionStorage)
00016 
00017     def test_rename_updates_storage(self):
00018         self.folder.invokeFactory('Document', 'p1')
00019         transaction.savepoint(1)
00020         self.folder.manage_renameObject('p1', 'p2')
00021 
00022         fp = '/'.join(self.folder.getPhysicalPath())
00023         self.assertEquals(self.storage.get(fp + '/p1'), fp + '/p2')
00024 
00025     def test_cut_paste_updates_storage(self):
00026         self.folder.invokeFactory('Folder', 'f1')
00027         self.folder.invokeFactory('Document', 'p1')
00028         self.folder.invokeFactory('Document', 'p2')
00029         transaction.savepoint(1)
00030         cp = self.folder.manage_cutObjects(ids=('p1', 'p2',))
00031         self.folder.f1.manage_pasteObjects(cp)
00032 
00033         fp = '/'.join(self.folder.getPhysicalPath())
00034         self.assertEquals(self.storage.get(fp + '/p1'), fp + '/f1/p1')
00035         self.assertEquals(self.storage.get(fp + '/p2'), fp + '/f1/p2')
00036 
00037     def test_cut_paste_rename_updates_storage(self):
00038         self.folder.invokeFactory('Folder', 'f1')
00039         self.folder.invokeFactory('Document', 'p1')
00040         self.folder.invokeFactory('Document', 'p2')
00041         transaction.savepoint(1)
00042         cp = self.folder.manage_cutObjects(ids=('p1', 'p2',))
00043         self.folder.f1.manage_pasteObjects(cp)
00044         transaction.savepoint(1)
00045         self.folder.f1.manage_renameObject('p2', 'p3')
00046 
00047         fp = '/'.join(self.folder.getPhysicalPath())
00048         self.assertEquals(self.storage.get(fp + '/p1'), fp + '/f1/p1')
00049         self.assertEquals(self.storage.get(fp + '/p2'), fp + '/f1/p3')
00050         self.assertEquals(self.storage.get(fp + '/f1/p2'), fp + '/f1/p3')
00051 
00052     def test_delete_destroys_reference(self):
00053         self.folder.invokeFactory('Document', 'p1')
00054         transaction.savepoint(1)
00055         self.folder.manage_renameObject('p1', 'p2')
00056         transaction.savepoint(1)
00057 
00058         fp = '/'.join(self.folder.getPhysicalPath())
00059         self.assertEquals(self.storage.get(fp + '/p1'), fp + '/p2')
00060 
00061         self.folder._delObject('p2')
00062 
00063         self.assertEquals(self.storage.get(fp + '/p1'), None)
00064 
00065     def test_delete_destroys_child_reference(self):
00066         self.folder.invokeFactory('Folder', 'f1')
00067         self.folder.f1.invokeFactory('Document', 'p1')
00068         transaction.savepoint(1)
00069         self.folder.f1.manage_renameObject('p1', 'p2')
00070         transaction.savepoint(1)
00071 
00072         fp = '/'.join(self.folder.getPhysicalPath())
00073         self.assertEquals(self.storage.get(fp + '/f1/p1'), fp + '/f1/p2')
00074 
00075         self.folder._delObject('f1')
00076 
00077         self.assertEquals(self.storage.get(fp + '/f1/p1'), None)
00078 
00079     def test_rename_updates_parent_and_children(self):
00080         self.folder.invokeFactory('Folder', 'f1')
00081         self.folder.f1.invokeFactory('Document', 'p1')
00082         self.folder.f1.invokeFactory('Document', 'p2')
00083         transaction.savepoint(1)
00084         self.folder.manage_renameObject('f1', 'f2')
00085 
00086         fp = '/'.join(self.folder.getPhysicalPath())
00087         self.assertEquals(self.storage.get(fp + '/f1'), fp + '/f2')
00088         self.assertEquals(self.storage.get(fp + '/f1/p1'), fp + '/f2/p1')
00089         self.assertEquals(self.storage.get(fp + '/f1/p2'), fp + '/f2/p2')
00090 
00091     def test_cut_paste_updates_parent_and_children(self):
00092         self.folder.invokeFactory('Folder', 'f1')
00093         self.folder.invokeFactory('Folder', 'f2')
00094         self.folder.f1.invokeFactory('Document', 'p1')
00095         self.folder.f1.invokeFactory('Document', 'p2')
00096         transaction.savepoint(1)
00097         cp = self.folder.manage_cutObjects(ids=('f1',))
00098         self.folder.f2.manage_pasteObjects(cp)
00099 
00100         fp = '/'.join(self.folder.getPhysicalPath())
00101         self.assertEquals(self.storage.get(fp + '/f1'), fp + '/f2/f1')
00102         self.assertEquals(self.storage.get(fp + '/f1/p1'), fp + '/f2/f1/p1')
00103         self.assertEquals(self.storage.get(fp + '/f1/p2'), fp + '/f2/f1/p2')
00104 
00105     def test_rename_updates_parent_and_children_deep(self):
00106         self.folder.invokeFactory('Folder', 'f1')
00107         self.folder.f1.invokeFactory('Folder', 'f11')
00108         self.folder.f1.f11.invokeFactory('Document', 'p1')
00109         self.folder.f1.f11.invokeFactory('Document', 'p2')
00110         transaction.savepoint(1)
00111         self.folder.manage_renameObject('f1', 'f2a')
00112 
00113         fp = '/'.join(self.folder.getPhysicalPath())
00114         self.assertEquals(self.storage.get(fp + '/f1'), fp + '/f2a')
00115         self.assertEquals(self.storage.get(fp + '/f1/f11'), fp + '/f2a/f11')
00116         self.assertEquals(self.storage.get(fp + '/f1/f11/p1'), fp + '/f2a/f11/p1')
00117         self.assertEquals(self.storage.get(fp + '/f1/f11/p2'), fp + '/f2a/f11/p2')
00118 
00119     def test_cut_paste_updates_parent_and_children_deep(self):
00120         self.folder.invokeFactory('Folder', 'f1')
00121         self.folder.invokeFactory('Folder', 'f2a')
00122         self.folder.f1.invokeFactory('Folder', 'f11')
00123         self.folder.f1.f11.invokeFactory('Document', 'p1')
00124         self.folder.f1.f11.invokeFactory('Document', 'p2')
00125         transaction.savepoint(1)
00126         cp = self.folder.manage_cutObjects(ids=('f1',))
00127         self.folder.f2a.manage_pasteObjects(cp)
00128 
00129         fp = '/'.join(self.folder.getPhysicalPath())
00130         self.assertEquals(self.storage.get(fp + '/f1'), fp + '/f2a/f1')
00131         self.assertEquals(self.storage.get(fp + '/f1/f11'), fp + '/f2a/f1/f11')
00132         self.assertEquals(self.storage.get(fp + '/f1/f11/p1'), fp + '/f2a/f1/f11/p1')
00133         self.assertEquals(self.storage.get(fp + '/f1/f11/p2'), fp + '/f2a/f1/f11/p2')
00134 
00135     def test_add_doesnt_create_storage_entry(self):
00136         """ refers https://dev.plone.org/plone/ticket/8260 """
00137         self.assertEqual(list(self.storage), [])
00138         self.folder.invokeFactory('Document', 'p1')
00139         transaction.savepoint(1)
00140         self.assertEqual(list(self.storage), [])
00141 
00142 
00143 def test_suite():
00144     suite = unittest.TestSuite()
00145     suite.addTest(unittest.makeSuite(TestRedirectorEvents))
00146     return suite