[Zope] Help writing test where bobobase_modification_time changes

Peter Bengtsson peter at fry-it.com
Fri Apr 11 07:47:39 EDT 2008


Thanks for the tips Chris and Dieter, I actually solved it in a very simple way:


from OFS.Image import File
from time import time
class MockFile(File):
    """ This file works the same as a normal File expect that
    in manage_edit() the internal modification time is set immediately.
    Normally Zope objects get their internal modification set when
    the transaction manager commits.
    """

    def manage_edit(self, title, content_type, precondition='',
                    filedata=None, REQUEST=None):
        # here's the mock hack, we set the _p_mtime NOW instead of letting
        # the transaction manager do it at the end.
        self._p_mtime = time()
        return File.manage_edit(self, title, content_type,
precondition=precondition,
                                filedata=filedata, REQUEST=REQUEST)

This worked beautifully in the integration test. I'm happy.

On 10/04/2008, Chris Withers <chris at simplistix.co.uk> wrote:
> Peter Bengtsson wrote:
>
> > How can I solve this? Make one big transaction two without having to
> > use transaction.get().commit() which I don't think I can use in unit
> > tests as per Dieter's advice.
> >
>
>  I'd suggest monkeypatching bobobase_modification_time on the objects you're
> testing with. You're testing your cache code, not the implementation of
> those objects, so replacing them with (partially) dummy objects is great for
> avoiding this kind of problem and is a pattern I've used frequently...
>
>  cheers,
>
>  Chris
>
>  --
>  Simplistix - Content Management, Zope & Python Consulting
>            - http://www.simplistix.co.uk
>


-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list