async def test_session_is_passed_through_to_request(fake_vault, resp_mocker, aresponses, hostname, resource): result = {} get_mock = resp_mocker(return_value=aiohttp.web.json_response(result)) aresponses.add(hostname, resource.get_url(namespace=None, name='xyz'), 'get', get_mock) explicit_context = APIContext(ConnectionInfo(server='http://irrelevant/')) context, result = await request_fn(1, context=explicit_context) assert context is explicit_context assert result == 101
async def enforced_context(fake_vault, mocker): """ Patchable context/session for some tests, e.g. with local exceptions. The local exceptions are supposed to simulate either the code issues, or the connection issues. `aresponses` does not allow to raise arbitrary exceptions on the client side, but only to return the erroneous responses. This test forces the re-authenticating decorators to always use one specific session for the duration of the test, so that the patches would have effect. """ _, item = fake_vault.select() context = APIContext(item.info) mocker.patch(f'{APIContext.__module__}.{APIContext.__name__}', return_value=context) async with context.session: yield context
async def test_session_is_passed_through_to_stream(fake_vault, resp_mocker, aresponses, hostname, resource, namespace): result = {} get_mock = resp_mocker(return_value=aiohttp.web.json_response(result)) aresponses.add(hostname, resource.get_url(namespace=namespace, name='xyz'), 'get', get_mock) explicit_context = APIContext(ConnectionInfo(server='http://irrelevant/')) counter = 0 async for context, result in stream_fn(1, context=explicit_context): counter += 1 async with context.session: assert context is explicit_context assert result == 101 assert counter == 1