Creating contexts for Unit Tests
![](https://secure.gravatar.com/avatar/2326f5e54bb073d5252a23b39708b839.jpg?s=120&d=mm&r=g)
Hi, I've run into a problem related to testing my application. I'm trying to create a test for a method that should return a redirect to another page: def return_upload_success(self, ctx): """ File is uploaded, everyone is happy. We show the results :-) """ self.request = inevow.IRequest(ctx) self.request.setComponent(iformless.IRedirectAfterPost, "/view/" + self.file.get_basename() ) return self.request To test this method I write a unittest that tries to create a context object: def test_return_upload_success(self): self.page.context = PageContext(None, remembrances={inevow.ICurrentSegments: ('rrr'), inevow.IRemainingSegments: ()}) ret = self.page.return_upload_success("sqlrsult") The problem is that when I run this I get a typeerror: TypeError: ('Could not adapt', PageContext(tag=None, remembrances={<InterfaceClass nevow.inevow.ICurrentSegments>: 'rrr', <InterfaceClass nevow.inevow.IRemainingSegments>: ()}), <InterfaceClass nevow.inevow.IRequest>) Does anyone have an idea on how I should set up my test? Kind regards, Tarjei
![](https://secure.gravatar.com/avatar/1ed18178bf3cbe008867479bdc0bf6af.jpg?s=120&d=mm&r=g)
On 24/07/2007 20:10 tarjei wrote:
Hi, I've run into a problem related to testing my application.
I can't quite understand why you're setting page.context. What I do is this.. ctx = context.WebContext(tag=page) ctx.remember(testutil.AccumulatingFakeRequest()) Hope this helps in any way... -- Colin Alston ~ http://www.karnaugh.za.net/ "To the world you may be one person, to one person you may be the world" ~ Rachel Ann Nunes. Terms and conditions: http://www.karnaugh.za.net/email.rpy
![](https://secure.gravatar.com/avatar/2326f5e54bb073d5252a23b39708b839.jpg?s=120&d=mm&r=g)
On 24/07/2007 20:10 tarjei wrote:
Hi, I've run into a problem related to testing my application.
I can't quite understand why you're setting page.context. What I do is this.. Because the method I'm testing does not get context as a parameter in
Colin Alston wrote: the first place :-)
ctx = context.WebContext(tag=page) ctx.remember(testutil.AccumulatingFakeRequest())
Hope this helps in any way... It did, I wasn't aware of testutil. It seems that my Nevow version (0.9.0) was a bit old as well.
Thanks a lot. I'll see if I can add this to the Nevow faq (does it exist?) BTW: Should new apps be written in conformance with this document: http://divmod.org/trac/wiki/DivmodNevow/ContextRemoval ? Regards, Tarjei
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Wed, 25 Jul 2007 12:49:29 +0200, tarjei <tarjei@nu.no> wrote:
[snip]
BTW: Should new apps be written in conformance with this document:
As much as is currently possible. Note, however, that not everything described on that page is implemented, even in current Nevow trunk@HEAD. Jean-Paul
participants (3)
-
Colin Alston
-
Jean-Paul Calderone
-
tarjei