def renderPlainFragment(fragment): """ same as L{render}, but expects an L{nevow.rend.Fragment} or any other L{nevow.inevow.IRenderer} """ page = Page(docFactory=stan(fragment)) (request, context) = _makeContext() page.renderHTTP(context) return request.v
def test_child(self): """ A request for a direct child of the guarded resource results in that child of the avatar returned by cred. """ root = Page() root.child_guarded = self.guard actual = self.successResultOf( renderResourceReturnTransport( root, b"/guarded/child", b"GET", ), ) self.assertIn(self.child_content, actual)
def test_emptyPostPath(self): """ If more path segments are consumed than remain in the request's I{postpath}, L{NevowSite.handleSegment} should silently not update I{prepath}. """ request = FakeRequest(currentSegments=('', )) context = RequestContext(tag=request) rootResource = Page() childResource = Page() site = NevowSite(rootResource) result = site.handleSegment((childResource, ()), request, ('foo', 'bar'), context) self.assertEqual(request.prepath, ['']) self.assertEqual(request.postpath, [])
def _render(self, fragment): """ Test helper which tries to render the given fragment. """ ctx = WovenContext() req = FakeRequest() ctx.remember(req, IRequest) return Page(docFactory=stan(fragment)).renderString(ctx)
def test_grandchild(self): """ A request for a grandchild of the guarded resource results in that grandchild of the avatar returned by cred. Ideally this test would be redundant with L{test_child} but the implementation of L{IResource} support results in different codepaths for the 1st descendant vs the Nth descendant. """ root = Page() root.child_guarded = self.guard actual = self.successResultOf( renderResourceReturnTransport( root, b"/guarded/child/grandchild", b"GET", ), ) self.assertIn(self.grandchild_content, actual)
def renderHTTP(self, ctx): req = inevow.IRequest(ctx) password = req.args.get('password', [None])[0] if password is None: return Page.renderHTTP(self, ctx) self.original.store.transact(self.original.setPassword, unicode(password)) # XXX TODO: select # proper decoding # strategy. return URL.fromString('/')
def _deferredResourceTest(self, makeResource, pathSuffix): """ Test the result of rendering some L{DeferredResource}-containing hierarchy. @param makeResource: A one-argument callable that returns a L{twisted.web.resource.IResource} provider to place into the resource hierarchy. There should be a L{DeferredResource} somewhere in this hierarchy. The argument is a byte string which should be included in the response to a request for the resource targetted by C{pathSuffix}. @pathSuffix: An absolute path into the resource returned by C{makeResource} identifying the resource to request and test the rendering of. @raise: A test-failing exception if the resource beneath C{makeResource(expected)} identified by C{pathSuffix} does not contain C{expected}. """ expected = b"success" deferredResource = makeResource(expected) rootPage = Page() rootPage.child_deferredresource = deferredResource actual = self.successResultOf( renderResourceReturnTransport( rootPage, b"/deferredresource" + pathSuffix, b"GET", ), ) self.assertTrue( actual.endswith(b"\r\n\r\n" + expected), "{!r} did not include expected response body {!r}".format( actual, expected, ) )
def _deferredResourceTest(self, makeResource, pathSuffix): """ Test the result of rendering some L{DeferredResource}-containing hierarchy. @param makeResource: A one-argument callable that returns a L{twisted.web.resource.IResource} provider to place into the resource hierarchy. There should be a L{DeferredResource} somewhere in this hierarchy. The argument is a byte string which should be included in the response to a request for the resource targetted by C{pathSuffix}. @pathSuffix: An absolute path into the resource returned by C{makeResource} identifying the resource to request and test the rendering of. @raise: A test-failing exception if the resource beneath C{makeResource(expected)} identified by C{pathSuffix} does not contain C{expected}. """ expected = b"success" deferredResource = makeResource(expected) rootPage = Page() rootPage.child_deferredresource = deferredResource actual = self.successResultOf( renderResourceReturnTransport( rootPage, b"/deferredresource" + pathSuffix, b"GET", ), ) self.assertTrue( actual.endswith(b"\r\n\r\n" + expected), "{!r} did not include expected response body {!r}".format( actual, expected, ))
def child_element(self, ctx): return Page(docFactory=stan(self.element))
def __init__(self, webapp, pageComponents, username, webViewer): self.username = username self.webViewer = webViewer Page.__init__(self, docFactory=webapp.getDocFactory('shell')) _ShellRenderingMixin.__init__(self, webapp, pageComponents, username)
def __init__(self, webapp, fragment, pageComponents, username): Page.__init__(self, docFactory=webapp.getDocFactory('shell')) _ShellRenderingMixin.__init__(self, webapp, pageComponents, username) _FragmentWrapperMixin.__init__(self, fragment, pageComponents)
def child_fragment(self, ctx): return Page(docFactory=stan(self.fragment))