[Twisted-web] Creating contexts for Unit Tests

tarjei tarjei at nu.no
Tue Jul 24 14:10:13 EDT 2007

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

     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

Does anyone have an idea on how I should set up my test?

Kind regards,

More information about the Twisted-web mailing list