Beispiel #1
0
        def addIdevice(id_):
            request = self._request(action='AddIdevice',
                                    object=str(id_),
                                    currentNode=str(id_))
            ctx = RequestContext(request)

            #at start mainpage.authoringPage is None - test will
            #currently fail - Mike Dawson 5/Feb/2014
            from exe.webui.authoringpage import AuthoringPage
            self.mainpage.authoringPage = AuthoringPage(self.mainpage)
            return self.mainpage.authoringPage.render(request)
Beispiel #2
0
def getResource(site, uri, headers={}, cookies={}):
    """
    Retrieve the resource at the given URI from C{site}.

    Return a L{Deferred} which is called back with the request after
    resource traversal and rendering has finished.

    @type site: L{NevowSite}
    @param site: The site object from which to retrieve the resource.

    @type uri: C{str}
    @param uri: The absolute path to the resource to retrieve, eg
        I{/private/12345}.

    @type headers: C{dict}
    @param headers: HTTP headers to include in the request.
    """
    headers = headers.copy()
    cookies = cookies.copy()

    url = URL.fromString(uri)
    path = '/' + url.path

    args = {}
    for (k, v) in url.queryList():
        args.setdefault(k, []).append(v)
    remainingSegments = tuple(url.pathList())
    request = FakeRequest(
        isSecure=url.scheme == 'https', uri=path, args=args, headers=headers,
        cookies=cookies, currentSegments=())
    requestContext = RequestContext(parent=site.context, tag=request)
    requestContext.remember((), ICurrentSegments)
    requestContext.remember(remainingSegments, IRemainingSegments)

    page = site.getPageContextForRequestContext(requestContext)
    page.addCallback(
        renderPage,
        topLevelContext=lambda tag: tag,
        reqFactory=lambda: request)
    page.addCallback(lambda ignored: request)
    return page
Beispiel #3
0
def flatten(stan, ctx=None):
    """Given the stan and the optional context, return a string containing the
    representation of the tree in the given context.
    """
    if ctx is None:
        from nevow.context import RequestContext, PageContext
        from nevow.testutil import FakeRequest
        ctx = PageContext(tag=None, parent=RequestContext(tag=FakeRequest()))
        ctx.remember(None, inevow.IData)
    result = []
    list(iterflatten(stan, ctx, result.append))
    return tags.raw(''.join(result))
Beispiel #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, [])
Beispiel #5
0
def getResource(site, uri, headers={}, cookies={}):
    """
    Retrieve the resource at the given URI from C{site}.

    Return a L{Deferred} which is called back with the request after
    resource traversal and rendering has finished.

    @type site: L{NevowSite}
    @param site: The site object from which to retrieve the resource.

    @type uri: C{str}
    @param uri: The absolute path to the resource to retrieve, eg
        I{/private/12345}.

    @type headers: C{dict}
    @param headers: HTTP headers to include in the request.
    """
    headers = headers.copy()
    cookies = cookies.copy()

    url = URL.fromString(uri)
    path = '/' + url.path

    args = {}
    for (k, v) in url.queryList():
        args.setdefault(k, []).append(v)
    remainingSegments = tuple(url.pathList())
    request = FakeRequest(isSecure=url.scheme == 'https',
                          uri=path,
                          args=args,
                          headers=headers,
                          cookies=cookies,
                          currentSegments=())
    requestContext = RequestContext(parent=site.context, tag=request)
    requestContext.remember((), ICurrentSegments)
    requestContext.remember(remainingSegments, IRemainingSegments)

    page = site.getPageContextForRequestContext(requestContext)
    page.addCallback(renderPage,
                     topLevelContext=lambda tag: tag,
                     reqFactory=lambda: request)
    page.addCallback(lambda ignored: request)
    return page
 def setUp(self):
     self.resource = TestResource()
     self.wrapped = CompressingResourceWrapper(self.resource)
     self.request = FakeRequest()
     self.ctx = RequestContext(tag=self.request)
 def addIdevice(id_):
     request = self._request(action='AddIdevice', object=str(id_))
     ctx = RequestContext(request)
     return self.mainpage.authoringPage.render(request)