コード例 #1
0
async def test_passes_request_params_to_request_context(monkeypatch):
    async def mocked__request(self, method, url, **kwargs):
        return kwargs['trace_request_ctx']

    monkeypatch.setattr(aiohttp.ClientSession, '_request', mocked__request)
    sess = session.get_session()
    ctx = await sess.get('url', headers={'key': 'value'}, timeout=42)
    assert ctx == types.SimpleNamespace(allow_redirects=True,
                                        headers={'key': 'value'},
                                        method='GET',
                                        timeout=42,
                                        url='url')
コード例 #2
0
async def execute_request(  # pylint: disable=R0913
        request,
        env=None,
        session=None,
        use_defaults=False,
        cache=True,
        silent=False,
        **kwargs):
    try:
        orig_silent = reporting.SILENT
        if silent:
            reporting.SILENT = True
        env = env if env is not None else get_environment()
        session = session if session is not None else get_session()
        request = find_request(request)
        result = await request(env,
                               session,
                               use_defaults=use_defaults,
                               cache=cache,
                               kwargs=kwargs)
        reporting.report_result(result)
        return result.value
    finally:
        reporting.SILENT = orig_silent
コード例 #3
0
async def test_get_session():
    sess = session.get_session()
    assert isinstance(sess, aiohttp.ClientSession)
    await sess.close()
コード例 #4
0
async def test_close_session():
    sess = session.get_session()
    assert not sess.closed
    await session.close_session()
    assert sess.closed
コード例 #5
0
async def test_get_session_caches():
    sess1 = session.get_session()
    sess2 = session.get_session()
    assert sess1 == sess2
    await sess1.close()