Back to index

plone3  3.1.7
Public Member Functions
Archetypes.tests.test_event.ValidationEventTests Class Reference
Inheritance diagram for Archetypes.tests.test_event.ValidationEventTests:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_event.ValidationEventTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def testPreValidatingEvent
def testPostValidatingEvent
def testInitializedAndEditedEvent

Detailed Description

Definition at line 65 of file test_event.py.


Member Function Documentation

Definition at line 132 of file test_event.py.

00132 
00133     def testInitializedAndEditedEvent(self):
00134         
00135         component.provideHandler(created_handler, (IObject1, IObjectCreatedEvent,))
00136         component.provideHandler(initialized_handler, (IObject1, IObjectInitializedEvent,))
00137         component.provideHandler(edited_handler, (IObject1, IObjectEditedEvent,))
00138         
00139         ob = Dummy('dummy')
00140         directlyProvides(ob, IObject1)
00141         self.folder._setObject('dummy', ob)
00142         ob = self.folder.dummy
00143         
00144         ob._initializedCaught = False
00145         ob._editedCaught = False
00146         
00147         # Simulate first edit
00148         ob._at_creation_flag = True
00149         ob.processForm(REQUEST=TestRequest())
00150         
00151         self.assertEquals(True, ob._initializedCaught)
00152         self.assertEquals(False, ob._editedCaught)
00153         
00154         # Simulate subsequent edit
00155         ob.processForm(REQUEST=TestRequest())
00156         self.assertEquals(True, ob._editedCaught)
00157         
00158         sm = component.getSiteManager()
00159         sm.unregisterHandler(created_handler, (IObject1, IObjectCreatedEvent,))
00160         sm.unregisterHandler(initialized_handler, (IObject1, IObjectCreatedEvent,))
00161         sm.unregisterHandler(edited_handler, (IObject1, IObjectCreatedEvent,))
00162         

Here is the call graph for this function:

Definition at line 100 of file test_event.py.

00100 
00101     def testPostValidatingEvent(self):
00102         
00103         # This test is similar to the test for pre-validation above. The
00104         # difference is that the post validation works after main schema
00105         # validation, whilst the pre-validation works before, and may
00106         # short-circuit schema validation.
00107         
00108         component.provideSubscriptionAdapter(PostValidation, adapts=(IObject2,))
00109         component.provideSubscriptionAdapter(PostValidation, adapts=(IObject3,))
00110         
00111         ob = Dummy('dummy')
00112         directlyProvides(ob, IObject1)
00113         errors = ob.validate()
00114         self.failIf(errors.has_key('bar'))
00115         del ob
00116         
00117         ob = Dummy('dummy')
00118         directlyProvides(ob, IObject2)
00119         errors = ob.validate()
00120         self.failUnless(errors['bar'])
00121         del ob
00122         
00123         ob = Dummy('dummy')
00124         directlyProvides(ob, IObject3)
00125         errors = ob.validate()
00126         self.failUnless(errors.has_key('bar'))
00127         del ob
00128         
00129         sm = component.getSiteManager()
00130         sm.unregisterSubscriptionAdapter(PostValidation, required=(IObject2,))
00131         sm.unregisterSubscriptionAdapter(PostValidation, required=(IObject3,))
        

Here is the call graph for this function:

Definition at line 67 of file test_event.py.

00067 
00068     def testPreValidatingEvent(self):
00069         
00070         # Register some subscription adapters for different types of objects
00071         # These will be called during validation
00072 
00073         component.provideSubscriptionAdapter(PreValidation, adapts=(IObject1,))
00074         component.provideSubscriptionAdapter(PreValidation, adapts=(IObject3,))
00075         
00076         # Verify that they are called only on the right type of object,
00077         # and that their return values are included in the error output
00078 
00079         ob = Dummy('dummy')
00080         directlyProvides(ob, IObject1)
00081         errors = ob.validate()
00082         self.failUnless(errors['foo'])
00083         del ob
00084         
00085         ob = Dummy('dummy')
00086         directlyProvides(ob, IObject2)
00087         errors = ob.validate()
00088         self.failIf(errors.has_key('foo'))
00089         del ob
00090         
00091         ob = Dummy('dummy')
00092         directlyProvides(ob, IObject3)
00093         errors = ob.validate()
00094         self.failUnless(errors['foo'])
00095         del ob
00096         
00097         sm = component.getSiteManager()
00098         sm.unregisterSubscriptionAdapter(PreValidation, required=(IObject1,))
00099         sm.unregisterSubscriptionAdapter(PreValidation, required=(IObject3,))

Here is the call graph for this function:


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