Render resource in a simpler manner

This commit is contained in:
Sajith Sasidharan 2020-08-19 14:52:20 -04:00
parent 320830cf90
commit d2bcebecaa

View File

@ -691,20 +691,27 @@ class MultiFormatResourceTests(TrialTestCase):
:param query_args: The query arguments to put into the request being :param query_args: The query arguments to put into the request being
rendered. A mapping from ``bytes`` to ``list`` of ``bytes``. rendered. A mapping from ``bytes`` to ``list`` of ``bytes``.
:return: The rendered response body as ``bytes``. :return: The rendered response body as ``str``.
""" """
ctx = WebContext(tag=resource)
req = FakeRequest(args=query_args)
ctx.remember(DefaultExceptionHandler(), ICanHandleException)
ctx.remember(req, IRequest)
ctx.remember(None, IData)
d = maybeDeferred(resource.render, ctx) # TODO: probably should: (1) refactor this out of here to a
d.addErrback(processingFailed, req, ctx) # common module (test.common_web maybe?), and (2) replace
res = self.successResultOf(d) # nevow.inevow.IRequest with twisted.web.iweb.IRequest. For
if isinstance(res, bytes): # (2) to happen, we will have to update web.common.get_arg()
return req.v + res # etc first.
return req.v from zope.interface import implementer
from nevow.inevow import IRequest
from twisted.web.server import Request
from twisted.web.test.requesthelper import DummyChannel
@implementer(IRequest)
class FakeRequest(Request):
def __init__(self, args):
Request.__init__(self, DummyChannel())
self.args = args
self.fields = dict()
return resource.render(FakeRequest(args=query_args))
def test_select_format(self): def test_select_format(self):