当前位置: 首页>>代码示例>>Python>>正文


Python test_utils.make_mocked_request方法代码示例

本文整理汇总了Python中aiohttp.test_utils.make_mocked_request方法的典型用法代码示例。如果您正苦于以下问题:Python test_utils.make_mocked_request方法的具体用法?Python test_utils.make_mocked_request怎么用?Python test_utils.make_mocked_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.test_utils的用法示例。


在下文中一共展示了test_utils.make_mocked_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_render_not_initialized

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_render_not_initialized():

    async def func(request):
        return aiohttp_jinja2.render_template('template', request, {})

    app = web.Application()

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)
    msg = "Template engine is not initialized, " \
          "call aiohttp_jinja2.setup(..., app_key={}" \
          ") first".format(aiohttp_jinja2.APP_KEY)

    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert msg == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例2: test_template_not_found

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_template_not_found():

    async def func(request):
        return aiohttp_jinja2.render_template('template', request, {})

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader({}))

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)

    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    t = "Template 'template' not found"
    assert t == ctx.value.text
    assert t == ctx.value.reason 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例3: test_render_not_mapping

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_render_not_mapping():

    @aiohttp_jinja2.template('tmpl.jinja2')
    async def func(request):
        return 123

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.DictLoader(
        {'tmpl.jinja2': 'tmpl'}))

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)
    msg = "context should be mapping, not <class 'int'>"
    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert msg == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:20,代码来源:test_simple_renderer.py

示例4: test_get_new_session

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_get_new_session():
    req = make_mocked_request('GET', '/')
    session = Session('identity', data=None, new=False)

    class Storage(AbstractStorage):
        async def load_session(self, request):
            pass

        async def save_session(self, request, response, session):
            pass

    req[SESSION_KEY] = session
    req[STORAGE_KEY] = Storage()

    ret = await new_session(req)
    assert ret is not session 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:18,代码来源:test_get_session.py

示例5: test_default_options

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_default_options(test_client):
    headers = {
        hdrs.ACCESS_CONTROL_REQUEST_HEADERS: hdrs.AUTHORIZATION}
    request = make_request('OPTIONS', '/', headers=headers)
    router = TreeUrlDispatcher()
    mi = await router.resolve(request)
    assert isinstance(mi, MatchInfoError)

    app = web.Application(router=router)
    router.set_cors(app)
    router.add_get('/', lambda request: web.Response())
    mi = await router.resolve(request)
    assert not isinstance(mi, MatchInfoError)
    client = await test_client(app)
    response = await client.options('/', headers=headers)
    assert response.status == 200
    h = response.headers
    assert h[hdrs.ACCESS_CONTROL_ALLOW_ORIGIN] == '*'
    assert h[hdrs.ACCESS_CONTROL_ALLOW_METHODS] == 'GET'
    assert h[hdrs.ACCESS_CONTROL_ALLOW_HEADERS] == hdrs.AUTHORIZATION 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:22,代码来源:test_dispatcher.py

示例6: test_content_receiver

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_content_receiver():
    cr = ContentReceiver()
    l1 = len(cr)
    assert l1
    mime_json = 'application/json'
    assert mime_json in cr
    cr[None] = cr[mime_json]
    assert len(cr) == l1 + 1
    request = make_request('PUT', '/', headers={'Content-Type': mime_json})
    request._read_bytes = json.dumps(2).encode()
    assert 2 == await cr.receive(request)
    del cr[None]

    cr.freeze()
    with pytest.raises(RuntimeError):
        del cr[mime_json]
    with pytest.raises(RuntimeError):
        cr[None] = None

    request = make_request('PUT', '/', headers={'Content-Type': '1'})
    with pytest.raises(TypeError):
        await cr.receive(request)

    assert list(cr) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:26,代码来源:test_dispatcher.py

示例7: test_render_not_initialized

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_render_not_initialized():

    async def func(request):
        return aiohttp_mako.render_template('template', request, {})

    app = web.Application()
    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)

    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert "Template engine is not initialized, " \
        "call aiohttp_mako.setup(app_key={}) first" \
        "".format(aiohttp_mako.APP_KEY) == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-mako,代码行数:18,代码来源:test_simple_renderer.py

示例8: test_template_not_mapping

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_template_not_mapping():

    @aiohttp_mako.template('tmpl.html')
    async def func(request):
        return 'data'

    app = web.Application()
    lookup = aiohttp_mako.setup(app, input_encoding='utf-8',
                                output_encoding='utf-8',
                                default_filters=['decode.utf8'])

    tplt = "<html><body><h1>${head}</h1>${text}</body></html>"
    lookup.put_string('tmpl.html', tplt)

    app.router.add_route('GET', '/', func)

    req = make_mocked_request('GET', '/', app=app)

    with pytest.raises(web.HTTPInternalServerError) as ctx:
        await func(req)

    assert "context should be mapping, not" \
           " <class 'str'>" == ctx.value.text 
开发者ID:aio-libs,项目名称:aiohttp-mako,代码行数:25,代码来源:test_simple_renderer.py

示例9: make_mocked_view_instance

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def make_mocked_view_instance(app, view_cls, method, url, params=None, post=None, *, headers=None,
                                    content_type='application/json') -> Union[BaseView, AbstractSQLView, PeeweeView]:
    if not headers:
        headers = {}

    if content_type:
        headers['Content-Type'] = content_type

    request = _make_mocked_request(method, url, headers=headers, protocol=mock.Mock(), app=app)
    _polyfill_post(request, post)

    view = view_cls(app, request)
    view._params_cache = params
    view._post_data_cache = post

    await view._prepare()
    return view 
开发者ID:fy0,项目名称:slim,代码行数:19,代码来源:test.py

示例10: test_middleware_with_not_skip_route

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_middleware_with_not_skip_route(tracer, fake_transport):

    async def handler(request):
        return web.Response(body=b'data')

    app = web.Application()
    skip_route = app.router.add_get('/', handler)
    az.setup(app, tracer)

    match_info = Mock()
    match_info.route = skip_route

    req = make_mocked_request('GET', '/', headers={'token': 'x'}, app=app)
    req._match_info = match_info
    middleware = middleware_maker(skip_routes=[skip_route])
    await middleware(req, handler)

    assert len(fake_transport.records) == 0 
开发者ID:aio-libs,项目名称:aiozipkin,代码行数:20,代码来源:test_aiohttp_helpers.py

示例11: test_middleware_with_invalid_ip

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_middleware_with_invalid_ip(tracer, version, address):
    app = web.Application()
    az.setup(app, tracer)

    # Fake transport
    transp = Mock()
    transp.get_extra_info.return_value = (address, '0')

    async def handler(request):
        return web.Response(body=b'data')

    req = make_mocked_request('GET', '/',
                              headers={'token': 'x'},
                              transport=transp, app=app)

    middleware = middleware_maker()
    with patch('aiozipkin.span.Span.remote_endpoint') as mocked_remote_ep:
        await middleware(req, handler)
        assert mocked_remote_ep.call_count == 0 
开发者ID:aio-libs,项目名称:aiozipkin,代码行数:21,代码来源:test_aiohttp_helpers.py

示例12: test_get_stored_session

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_get_stored_session():
    req = make_mocked_request('GET', '/')
    session = Session('identity', data=None, new=False)
    req[SESSION_KEY] = session

    ret = await get_session(req)
    assert session is ret 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:9,代码来源:test_get_session.py

示例13: test_session_is_not_stored

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_session_is_not_stored():
    req = make_mocked_request('GET', '/')

    with pytest.raises(RuntimeError):
        await get_session(req) 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:7,代码来源:test_get_session.py

示例14: test_storage_returns_not_session_on_load_session

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_storage_returns_not_session_on_load_session():
    req = make_mocked_request('GET', '/')

    class Storage():
        async def load_session(self, request):
            return None

    req[STORAGE_KEY] = Storage()

    with pytest.raises(RuntimeError):
        await get_session(req) 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:13,代码来源:test_get_session.py

示例15: test_get_new_session_no_storage

# 需要导入模块: from aiohttp import test_utils [as 别名]
# 或者: from aiohttp.test_utils import make_mocked_request [as 别名]
def test_get_new_session_no_storage():
    req = make_mocked_request('GET', '/')
    session = Session('identity', data=None, new=False)
    req[SESSION_KEY] = session

    with pytest.raises(RuntimeError):
        await new_session(req) 
开发者ID:aio-libs,项目名称:aiohttp-session,代码行数:9,代码来源:test_get_session.py


注:本文中的aiohttp.test_utils.make_mocked_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。