Exemplo n.º 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    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)
Exemplo n.º 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, [])
Exemplo n.º 5
0
    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)
Exemplo n.º 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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
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('/')
Exemplo n.º 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('/')
Exemplo n.º 11
0
    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,
            )
        )
Exemplo n.º 12
0
    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,
            ))
Exemplo n.º 13
0
 def child_element(self, ctx):
     return Page(docFactory=stan(self.element))
Exemplo n.º 14
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 17
0
 def child_fragment(self, ctx):
     return Page(docFactory=stan(self.fragment))
Exemplo n.º 18
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)