def set_request(self, method, path_str): self.request = wsgi_apps.Request( environ={ 'REQUEST_METHOD': method, 'PATH_INFO': path_str, 'wsgi.file_wrapper': unittest.mock.Mock(), }, context=contexts.Context(), )
def test_context(self): self.assert_context(contexts.Context({'y': 0}), {'y': 0}) ctx = contexts.Context() child_1 = ctx.make({'x': 1}) child_2 = ctx.make({'x': 2}) grandchild = child_1.make({'x': 3}, allow_overwrite=True) self.assert_context(ctx, {}) self.assert_context(child_1, {'x': 1}) self.assert_context(child_2, {'x': 2}) self.assert_context(grandchild, {'x': 3}) with self.assertRaisesRegex(AssertionError, r'expect x.isdisjoint'): child_1.make({'x': 3}) with self.assertRaisesRegex(AssertionError, r'expect \'x\' not in'): child_1.set('x', 3) self.assert_context(child_1, {'x': 1}) child_1.set('x', 3, allow_overwrite=True) self.assert_context(child_1, {'x': 3})
async def __call__(self, environ, start_response): # Running handlers is quite expensive. We should not waste time # on time while server is shutting down. if self._handler_queue.is_closed(): start_response( _Response._format_status(consts.Statuses.SERVICE_UNAVAILABLE), [(consts.HEADER_RETRY_AFTER, '60')], ) return [] request = Request(environ=environ, context=contexts.Context()) file_wrapper = environ.get('wsgi.file_wrapper') response = _Response(start_response, file_wrapper is not None) # Handler task may linger on after application completes. You # could do tricks with this feature. self._handler_queue.spawn(self._run_handler(request, response)) await response.wait_send_mechanism_decided() if response.file is None: return self._iter_content(response) else: return file_wrapper(response.file)
def set_request(self, **kwargs): environ = self.ENVIRON.copy() environ.update(**kwargs) self.request = wsgi_apps.Request(environ=environ, context=contexts.Context())
def make_request(path_str): return wsgi_apps.Request( environ={'PATH_INFO': path_str}, context=contexts.Context() )
def make_request(self, etags_str): environ = self.ENVIRON.copy() environ['HTTP_IF_NONE_MATCH'] = etags_str return wsgi_apps.Request(environ=environ, context=contexts.Context())