Back to index

plone3  3.1.7
Public Member Functions
CMFEditions.tests.test_ModifierRegistryTool.TestModifierRegistryTool Class Reference

List of all members.

Public Member Functions

def afterSetUp
def test00_interface
def test01_modifiersNotCalled
def test02_enabledModifierCalled
def test03_unregisteredModifiersNotCalled
def test04_conditionEvaluated
def test05_registerANonModifier
def test06_modifierAddedToTheCorrectPosition
def test07_unregisterModifer
def test08_getModifiers
def test09_conditionContextSetUpCorretcly
def test10_callingOrder

Detailed Description

Definition at line 152 of file test_ModifierRegistryTool.py.


Member Function Documentation

Definition at line 154 of file test_ModifierRegistryTool.py.

00154 
00155     def afterSetUp(self):
00156         # we need to have the Manager role to be able to add things
00157         # to the portal root
00158         self.setRoles(['Manager',])
00159 
00160         # add an additional user
00161         self.portal.acl_users.userFolderAddUser('reviewer', 'reviewer',
00162                                                 ['Manager'], '')
00163         # add a document
00164         self.portal.invokeFactory('Document', 'doc')
00165 
00166         # just unregister the standard modifiers for the unit tests
00167         portal_modifier = getToolByName(self.portal, 'portal_modifier')
00168         modifiers = portal_modifier.modules.StandardModifiers.modifiers
00169         for m in modifiers:
00170             portal_modifier.unregister(m['id'])

Here is the call graph for this function:

Definition at line 171 of file test_ModifierRegistryTool.py.

00171 
00172     def test00_interface(self):
00173         portal_modifier = self.portal.portal_modifier
00174 
00175         # test interface conformance
00176         #verifyObject(IModifier, portal_modifier)
00177         verifyObject(IModifierRegistrySet, portal_modifier)
00178         verifyObject(IModifierRegistryQuery, portal_modifier)
00179 #        verifyObject(IBulkEditableSubscriberRegistry, portal_modifier)

Definition at line 180 of file test_ModifierRegistryTool.py.

00180 
00181     def test01_modifiersNotCalled(self):
00182         portal_modifier = self.portal.portal_modifier
00183         doc = self.portal.doc
00184         doc_copy = deepcopy(aq_base(doc))
00185 
00186         portal_modifier.register('1', SimpleModifier1())
00187         portal_modifier.edit('1', condition='python:True')
00188         portal_modifier.beforeSaveModifier(doc, doc_copy)
00189         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00190         self.assertRaises(AttributeError, getattr, doc_copy, 'beforeSave1')
00191         self.assertRaises(AttributeError, getattr, doc_copy, 'afterRetrieve1')

Here is the call graph for this function:

Definition at line 192 of file test_ModifierRegistryTool.py.

00192 
00193     def test02_enabledModifierCalled(self):
00194         portal_modifier = self.portal.portal_modifier
00195         doc = self.portal.doc
00196         doc_copy = deepcopy(aq_base(doc))
00197 
00198         portal_modifier.register('1', SimpleModifier1())
00199         portal_modifier.edit('1', enabled=True, condition='python:True')
00200         portal_modifier.beforeSaveModifier(doc, doc_copy)
00201         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00202 
00203         portal_modifier.beforeSaveModifier(doc, doc_copy)
00204         self.assertEqual(doc_copy.beforeSave1, 2)
00205         self.assertEqual(doc_copy.afterRetrieve1, 1)

Here is the call graph for this function:

Definition at line 206 of file test_ModifierRegistryTool.py.

00206 
00207     def test03_unregisteredModifiersNotCalled(self):
00208         portal_modifier = self.portal.portal_modifier
00209         doc = self.portal.doc
00210         doc_copy = deepcopy(aq_base(doc))
00211 
00212         portal_modifier.register('1', SimpleModifier1())
00213         portal_modifier.edit('1', enabled=True, condition='python:True')
00214         portal_modifier.beforeSaveModifier(doc, doc_copy)
00215         self.assertEqual(doc_copy.beforeSave1, 1)
00216         self.assertRaises(AttributeError, getattr, doc_copy, 'afterRetrieve1')
00217         portal_modifier.unregister('1')
00218         portal_modifier.beforeSaveModifier(doc, doc_copy)
00219         self.assertEqual(doc_copy.beforeSave1, 1)
00220         self.assertRaises(AttributeError, getattr, doc_copy, 'afterRetrieve1')

Here is the call graph for this function:

Definition at line 221 of file test_ModifierRegistryTool.py.

00221 
00222     def test04_conditionEvaluated(self):
00223         portal_modifier = self.portal.portal_modifier
00224         doc = self.portal.doc
00225         doc_copy = deepcopy(aq_base(doc))
00226 
00227         portal_modifier.register('1', SimpleModifier1())
00228         portal_modifier.edit('1', enabled=True, condition='python:False')
00229         portal_modifier.beforeSaveModifier(doc, doc_copy)
00230         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00231         self.assertRaises(AttributeError, getattr, doc_copy, 'beforeSave1')
00232         self.assertRaises(AttributeError, getattr, doc_copy, 'afterRetrieve1')

Here is the call graph for this function:

Definition at line 233 of file test_ModifierRegistryTool.py.

00233 
00234     def test05_registerANonModifier(self):
00235         portal_modifier = self.portal.portal_modifier
00236         doc = self.portal.doc
00237         doc_copy = deepcopy(aq_base(doc))
00238 
00239         portal_modifier._setObject('doc', NonModifier())
00240         portal_modifier.beforeSaveModifier(doc, doc_copy)
00241         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00242         self.assertRaises(AttributeError, getattr, doc_copy, 'beforeSave1')
00243         self.assertRaises(AttributeError, getattr, doc_copy, 'afterRetrieve1')

Here is the call graph for this function:

Definition at line 244 of file test_ModifierRegistryTool.py.

00244 
00245     def test06_modifierAddedToTheCorrectPosition(self):
00246         portal_modifier = self.portal.portal_modifier
00247 
00248         m1 = SimpleModifier1()
00249         m2 = SimpleModifier2()
00250         m3 = SimpleModifier3()
00251 
00252         portal_modifier.register('1', m1)
00253         portal_modifier.register('2', m2)
00254         portal_modifier.register('3', m3, pos=0)
00255 
00256         modifiers = [m.getModifier() for m in portal_modifier.objectValues()]
00257         self.assertEqual(modifiers, [m3, m1, m2])

Definition at line 258 of file test_ModifierRegistryTool.py.

00258 
00259     def test07_unregisterModifer(self):
00260         portal_modifier = self.portal.portal_modifier
00261 
00262         m1 = SimpleModifier1()
00263         m2 = SimpleModifier2()
00264         m3 = SimpleModifier3()
00265 
00266         portal_modifier.register('1', m1)
00267         portal_modifier.register('2', m2)
00268         portal_modifier.register('3', m3, pos=0)
00269 
00270         portal_modifier.unregister('1')
00271 
00272         modifiers = [m.getModifier() for m in portal_modifier.objectValues()]
00273         self.assertEqual(modifiers, [m3, m2])

Definition at line 274 of file test_ModifierRegistryTool.py.

00274 
00275     def test08_getModifiers(self):
00276         portal_modifier = self.portal.portal_modifier
00277 
00278         m1 = SimpleModifier1()
00279         m2 = SimpleModifier2()
00280         m3 = SimpleModifier3()
00281 
00282         portal_modifier.register('1', m1)
00283         portal_modifier.register('2', m2)
00284         portal_modifier.register('3', m3, pos=0)
00285 
00286         portal_modifier.unregister('1')
00287 
00288         self.assertEqual(portal_modifier.get('2').getModifier(), m2)
00289         self.assertEqual(portal_modifier.query('2').getModifier(), m2)
00290         self.assertRaises(AttributeError, portal_modifier.get, '1')
00291         self.assertEqual(portal_modifier.query('1', None), None)

Definition at line 292 of file test_ModifierRegistryTool.py.

00292 
00293     def test09_conditionContextSetUpCorretcly(self):
00294         portal_modifier = self.portal.portal_modifier
00295         doc = self.portal.doc
00296         doc_copy = deepcopy(aq_base(doc))
00297 
00298         # just check if variables got defined
00299         condition = 'python:"%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s" % (' \
00300                     'object_url, ' \
00301                     'folder_url, ' \
00302                     'portal_url, ' \
00303                     'object, ' \
00304                     'folder, ' \
00305                     'portal, ' \
00306                     'nothing, ' \
00307                     'request, ' \
00308                     'modules, ' \
00309                     'member,' \
00310                     ')'
00311         portal_modifier.register('1', SimpleModifier1())
00312         portal_modifier.edit('1', enabled=True, condition=condition)
00313 
00314         portal_modifier.beforeSaveModifier(doc, doc_copy)
00315         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00316         self.assertEqual(doc_copy.beforeSave1, 1)
00317         self.assertEqual(doc_copy.afterRetrieve1, 1)

Here is the call graph for this function:

Definition at line 318 of file test_ModifierRegistryTool.py.

00318 
00319     def test10_callingOrder(self):
00320         global mlog
00321         portal_modifier = self.portal.portal_modifier
00322         doc = self.portal.doc
00323         doc_copy = deepcopy(aq_base(doc))
00324 
00325         mlog = []
00326         counter = 0
00327         for m in loggingModifiers:
00328             counter += 1
00329             portal_modifier.register(str(counter), m)
00330             portal_modifier.edit(str(counter),
00331                                  enabled=True,
00332                                  condition='python:True')
00333 
00334         mlog.append('<save>')
00335         referenced_data = portal_modifier.getReferencedAttributes(doc)
00336         portal_modifier.getOnCloneModifiers(doc)
00337         portal_modifier.beforeSaveModifier(doc, doc_copy)
00338         mlog.append('<retrieve>')
00339 
00340         portal_modifier.afterRetrieveModifier(doc, doc_copy)
00341         mlog.append('<end>')
00342 
00343         mlog_str = '\n'.join(mlog).replace('__main__', 'CMFEditions.tests.test_ModifierRegistryTool')
00344         expected_result = \
00345 """<save>
00346 %(class)s_A.getReferencedAttributes: k1 = v1:%(class)s_A, k2 = v2:%(class)s_A
00347 %(class)s_B.getReferencedAttributes: k1 = v1:%(class)s_B, k2 = v2:%(class)s_B
00348 %(class)s_C.getReferencedAttributes: k1 = v1:%(class)s_C, k2 = v2:%(class)s_C
00349 %(class)s_D.getReferencedAttributes: k1 = v1:%(class)s_D, k2 = v2:%(class)s_D
00350 %(class)s_A.getOnCloneModifiers
00351 %(class)s_B.getOnCloneModifiers
00352 %(class)s_C.getOnCloneModifiers
00353 %(class)s_D.getOnCloneModifiers
00354 %(class)s_A.beforeSaveModifier
00355 %(class)s_B.beforeSaveModifier
00356 %(class)s_C.beforeSaveModifier
00357 %(class)s_D.beforeSaveModifier
00358 <retrieve>
00359 %(class)s_D.afterRetrieveModifier
00360 %(class)s_C.afterRetrieveModifier
00361 %(class)s_B.afterRetrieveModifier
00362 %(class)s_A.afterRetrieveModifier
00363 <end>"""%{'class':'LoggingModifier'}
00364         self.assertEqual(mlog_str, expected_result)
00365 

Here is the call graph for this function:


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