def __init__(self, context: BolinetteContext, loop: AbstractEventLoop): abc.WithContext.__init__(self, context) WithDataContext.__init__(self, context.registry.get(DataContext)) server = test_utils.TestServer(context.registry.get(Application), loop=loop) self.client = test_utils.TestClient(server, loop=loop) self.mock = Mock(context) self.cookies = {}
async def proxy_server_mock(server_port, loop): app = aiohttp.web.Application() app['calls'] = [] app.router.add_route('post', '/', proxy_server_handler_mock) server = test_utils.TestServer(app, port=server_port) client = test_utils.TestClient(server) await server.start_server(loop) try: yield app finally: await client.close() await server.close()
async def jaeger_mock_server(jaeger_port): app = WaitingApp() app.router.add_route("POST", "/api/traces", handler) server = test_utils.TestServer(app, port=jaeger_port) client = test_utils.TestClient(server) await client.start_server() try: yield app finally: await client.close() await server.close()
async def client(loop, aiohttp_app): aiohttp_app.router.add_route("GET", "/data", get_data) aiohttp_app.middlewares.append(compress_middleware) test_server = test_utils.TestServer(aiohttp_app, port=8090) test_client = test_utils.TestClient(test_server) await test_client.start_server() try: yield test_client finally: await test_server.close() await test_client.close()
async def client(loop, asgi_resource, aiohttp_app): aiohttp_app.router.register_resource(asgi_resource) asgi_resource.lifespan_mount( aiohttp_app, startup=True, shutdown=True, ) test_server = test_utils.TestServer(aiohttp_app) test_client = test_utils.TestClient(test_server) await test_client.start_server() try: yield test_client finally: await test_server.close() await test_client.close()
async def test_normalize_path_middleware(asgi_resource, middlewares): aiohttp_app = web.Application(middlewares=middlewares) aiohttp_app.router.register_resource(asgi_resource) asgi_resource.lifespan_mount( aiohttp_app, startup=True, shutdown=True, ) async with test_utils.TestServer(aiohttp_app) as test_server: async with test_utils.TestClient(test_server) as client: async with client.get("/asgi") as response: response.raise_for_status() body = await response.json() assert body == {'message': 'Hello World', 'root_path': ''} async with client.get("/not-found") as response: with pytest.raises(aiohttp.ClientError) as err: response.raise_for_status() assert err.value.status == 404
def test_client(self) -> test_utils.TestClient: return test_utils.TestClient(test_utils.TestServer(self.get_app()), loop=asyncio.get_event_loop())
def get_session(self, *args, **kwargs): return test_utils.TestClient(self._server, *args, response_class=self.response_cls, **kwargs)
async def __aenter__(self): await self.server.start_server(loop=asyncio.get_event_loop()) self.client = test_utils.TestClient(self.server, loop=asyncio.get_event_loop()) return self.client
async def client(app): async with test_utils.TestClient(test_utils.TestServer(app)) as client: yield client
def session_maker(_): return test_utils.TestClient( api.server, loop=loop, headers=librarian.github.GitHub.make_default_headers( gh_token)).session
async def cli(mocker): mocker.patch('application.app.setup_rabbit', new=setup_rabbit_mock) application = app.create_app() async with test_utils.TestClient(test_utils.TestServer(application)) as client: yield client