[Zope] Overriding DateTime

Tim Knapp duffyd at kokorice.org
Mon Mar 23 04:42:35 EDT 2009


On Mon, 2009-03-23 at 06:25 +0100, Andreas Jung wrote:
> 
> 
> On Mon, Mar 23, 2009 at 06:21, Tim Knapp <duffyd at kokorice.org> wrote:
>         Hi,
>         
>         I would like to override the DateTime.DateTime class within my
>         functional tests. 
>  I have tried mocking (via mocker) and injecting the
> 
>         subclassed DateTime class into sys.modules (results in a
>         TraversalError). The fartherest I've gotten is to set
>         DateTime.DateTime
>         = MySubclassedDateTime in my tests.py, which does work for the
>         code
>         'within' the package(s) I'm testing but all the Zope core code
>         (i.e. the
>         instance created within PloneTestCase) is still referencing
>         the global
>         DateTime module. Has anyone successfully done this?
> 
> What is the particular usecase?

I have applications that come into the system and fall into an invoicing
period based on the 'created' index. I've managed to override the
datetime in all my tests except in the 'created' index, which is
recording the 'actual' date time. One option is patching the 'created'
method in Archetypes/ExtensibleMetadata.py, which is what I'm favouring
at the moment.

>  Zope has a very strong dependency
> from DateTime in various places. So there is almost no compatible way
> for getting rid of it or for replacing it.
> So why?

This is only in my tests as noted above.
> 
> -aj 

-Tim

> P.S. we don't like cross-postings - posting to  one list is enough

Yeah, sorry about that. I am aware of this but wasn't entirely sure
which list was best given that DateTime is a Zope module but is used
heavily in Plone. I'll stick to the Zope list for questions of this
nature from now on :)



More information about the Zope mailing list