From 1ed74604c7e3fd4fbd02549d24a52707b88ddced Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 21 Oct 2020 07:15:36 -0400 Subject: [PATCH] Use twisted.web.server.Request instead of DummyRequest in the tests Always prefer the real thing if possible --- src/allmydata/test/common_tweb.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/allmydata/test/common_tweb.py b/src/allmydata/test/common_tweb.py index 2af9d4f53..cfaf85c6c 100644 --- a/src/allmydata/test/common_tweb.py +++ b/src/allmydata/test/common_tweb.py @@ -8,7 +8,10 @@ from twisted.internet.defer import ( succeed, ) from twisted.web.test.requesthelper import ( - DummyRequest, + DummyChannel, +) +from twisted.web.server import ( + Request, ) from twisted.web.iweb import ( IRequest, @@ -17,8 +20,6 @@ from twisted.web.server import ( NOT_DONE_YET, ) -classImplements(DummyRequest, IRequest) - def render(resource, query_args): """ Render (in the manner of the Twisted Web Site) a Twisted ``Resource`` @@ -32,7 +33,8 @@ def render(resource, query_args): :return Deferred: A Deferred that fires with the rendered response body as ``bytes``. """ - request = DummyRequest([]) + channel = DummyChannel() + request = Request(channel) request.args = query_args result = resource.render(request) if isinstance(result, bytes): @@ -50,5 +52,9 @@ def render(resource, query_args): result, ), ) - done.addCallback(lambda ignored: b"".join(request.written)) + def get_body(ignored): + complete_response = channel.transport.written.getvalue() + header, body = complete_response.split(b"\r\n\r\n", 1) + return body + done.addCallback(get_body) return done