Hi, thank you for all that answers, this was really helpful!

On Mon, Jun 22, 2009 at 12:18, Hanno Schlichting <ha...@hannosch.eu> wrote:

> On Tue, Jun 16, 2009 at 10:35 PM, Patrick Gerken<do3cc...@googlemail.com>
> wrote:
> > A testcase in my code fails, and after a lot of digging, I am finding
> that
> > the reason are wrong results from the catalog. The catalog returns bad
> > results because he caches the results in the request.
> > My test consists of a number of steps, for multiple times I do a
> > getMultiAdapter, always with fresh TestRequests. Still it seems, that the
> > catalog always use some other, rotten REQUEST.
> Looking at this again, you are missing an important point about the
> test framework you use.
> In all of ZopeTestCase (CMFTestCase, PloneTestCase) you get a
> convenience request object set up for you, reachable as app.REQUEST.
> This mirrors the way you usually get access to the request object in
> Zope2 via Acquisition down to the application root. It's meant to
> emulate a very minimal request object.
> Now in normal operation, you would get one request object per HTTP
> request. This also works in the functional variants of the test case
> classes.
> In the non-functional test classes you only ever get one request
> object set up, as there's no object publishing or HTTP request
> handling being done. If you or any code you call changes any settings
> on that request object and you want to test things dependent on this
> you have two options:  Either create a fresh request yourself (using
> Testing.makerequest) in your tests or use a functional test case
> instead.

I did excactly that. Since it was a caching issue in code out of my reach, I
had problems with.
Sadly, creating a new request and saving it on self.app.REQUEST was not

The code in question acquires the method that caches something on the
REQUEST from a getSite() call.
It seems like getSite() returns a copy of the site, and that has its own
copy of the request too.

>>> self.app.REQUEST == getSite().REQUEST

>>> self.app = makerequest(self.app)
>>> self.app.REQUEST == getSite().REQUEST

The copy getSite() returns is deleted in an EndRequest Event handler...

I did not use zc.testbrowser for testing, because I did test XMLRPC Methods,
and it seemed easier to just use getMultiAdapter and test the view directly.

I solved my issues but it is a bit inconvenient nowadays...

Best regards and thank you!

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to