async def task(i): responses = [] kwargs = { "url_bytes": "http://localhost/context-check/{i}".format(i=i).encode( "ascii" ), "headers": {}, "version": "1.1", "method": "GET", "transport": None, } if SANIC_VERSION >= (19,): kwargs["app"] = app if SANIC_VERSION >= (21, 3): try: app.router.reset() app.router.finalize() except AttributeError: ... class MockAsyncStreamer: def __init__(self, request_body): self.request_body = request_body self.iter = iter(self.request_body) self.response = b"success" def respond(self, response): responses.append(response) patched_response = HTTPResponse() patched_response.send = lambda end_stream: asyncio.sleep(0.001) return patched_response def __aiter__(self): return self async def __anext__(self): try: return next(self.iter) except StopIteration: raise StopAsyncIteration patched_request = request.Request(**kwargs) patched_request.stream = MockAsyncStreamer([b"hello", b"foo"]) await app.handle_request( patched_request, ) else: await app.handle_request( request.Request(**kwargs), write_callback=responses.append, stream_callback=responses.append, ) (r,) = responses assert r.status == 200
async def task(i): responses = [] kwargs = { "url_bytes": "http://localhost/context-check/{i}".format(i=i).encode("ascii"), "headers": {}, "version": "1.1", "method": "GET", "transport": None, } if SANIC_VERSION >= (19, ): kwargs["app"] = app await app.handle_request( request.Request(**kwargs), write_callback=responses.append, stream_callback=responses.append, ) (r, ) = responses assert r.status == 200
async def task(i): responses = [] await app.handle_request( request.Request( url_bytes="http://localhost/context-check/{i}".format( i=i).encode("ascii"), headers={}, version="1.1", method="GET", transport=None, ), write_callback=responses.append, stream_callback=responses.append, ) r, = responses assert r.status == 200