コード例 #1
0
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
コード例 #2
0
ファイル: rendertools.py プロジェクト: fusionapp/mantissa
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
コード例 #3
0
ファイル: test_appserver.py プロジェクト: schwabe/nevow
    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)
コード例 #4
0
 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, [])
コード例 #5
0
ファイル: test_appserver.py プロジェクト: twisted/nevow
    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)
コード例 #6
0
 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)
コード例 #7
0
ファイル: test_appserver.py プロジェクト: schwabe/nevow
    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)
コード例 #8
0
ファイル: test_appserver.py プロジェクト: twisted/nevow
    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)
コード例 #9
0
ファイル: signup.py プロジェクト: fusionapp/mantissa
    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('/')
コード例 #10
0
    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('/')
コード例 #11
0
ファイル: test_appserver.py プロジェクト: twisted/nevow
    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,
            )
        )
コード例 #12
0
ファイル: test_appserver.py プロジェクト: schwabe/nevow
    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,
            ))
コード例 #13
0
 def child_element(self, ctx):
     return Page(docFactory=stan(self.element))
コード例 #14
0
ファイル: webapp.py プロジェクト: fusionapp/mantissa
 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)
コード例 #15
0
 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)
コード例 #16
0
 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)
コード例 #17
0
 def child_fragment(self, ctx):
     return Page(docFactory=stan(self.fragment))
コード例 #18
0
ファイル: webapp.py プロジェクト: fusionapp/mantissa
 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)