Non-testbrowser tests and events

Maurits van Rees m.van.rees at zestsoftware.nl
Wed Apr 4 18:17:05 UTC 2007


Hi,

In a product I have some testbrowser tests and all events that I
expect are fired correctly.

I also have some non testbrowser tests.  Here I find myself firing
some events manually in order to let my event handlers run.

For instance, I have created a utility function for adding a Booking.
I manually fire the ObjectModifiedEvent for the Booking and the
container that it is added to.  The first event is needed to update a
total on the container.  The second event is  needed to update a
total on the parent of the container.


def createBooking(container, id=id, hours=0, minutes=0):
    """Create a Booking and fire the ObjectModifiedEvent.

    The event is fired automatically for you when you press Save in
    the edit form, but in testing we apparently need to take care of
    it ourselves.
    """
    container.invokeFactory('Booking', id=id)
    booking = container[id]
    booking.update(hours=hours, minutes=minutes)
    # In these kinds of tests we need to fire some events ourselves...
    # To do: use testbrowser tests instead.
    notify(ObjectModifiedEvent(booking))
    notify(ObjectModifiedEvent(container))


I think that when I move to testbrowser tests (so really testing the
adding and editing of Bookings through the browser) these manual
notifications are not needed anymore.

I noticed in other tests that 'update(hours=x)' is already a bit
better than 'setHours(x)' so I moved to that in all my tests.

But am I maybe doing something wrong here?  Are there other ways I can
update some fields of an Archetype object that *do* make sure these
events are fired?  Or is there some other more convenient way to trick
the testing environment into firing all proper events?

To say it a bit differently: I am looking for a way to say to Zope: "I
am done editing this object now, so please start doing everything that
you normally do when someone clicks the 'Save' button on an edit
form."

-- 
Maurits van Rees | http://maurits.vanrees.org/ [NL]
            Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
 I can assure you mine are still greater."





More information about the Product-Developers mailing list