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
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 wrote:
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 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
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