• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python publish.resolve_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中morepath.publish.resolve_response函数的典型用法代码示例。如果您正苦于以下问题:Python resolve_response函数的具体用法?Python resolve_response怎么用?Python resolve_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_predicates

def test_predicates():
    config = setup()

    class app(App):
        testing_config = config

    config.commit()

    def view(self, request):
        return "all"

    def post_view(self, request):
        return "post"

    registry = app.registry
    register_view(registry, dict(model=Model), view)
    register_view(registry, dict(model=Model, request_method='POST'),
                  post_view)

    model = Model()
    assert resolve_response(
        app().request(get_environ(path='')), model).body == b'all'
    assert (resolve_response(app().
                             request(get_environ(path='', method='POST')),
                             model).body == b'post')
开发者ID:binbrain,项目名称:morepath,代码行数:25,代码来源:test_publish.py


示例2: test_predicates

def test_predicates():
    class app(App):
        pass

    dectate.commit(app)

    def view(self, request):
        return "all"

    def post_view(self, request):
        return "post"

    view_registry = app.config.view_registry

    view_registry.register_view(dict(model=Model), view)
    view_registry.register_view(
        dict(model=Model, request_method='POST'),
        post_view)

    model = Model()
    assert resolve_response(
        model, app().request(get_environ(path=''))).body == b'all'
    assert (
        resolve_response(
            model, app().request(get_environ(path='', method='POST'))).body ==
        b'post')
开发者ID:blaflamme,项目名称:morepath,代码行数:26,代码来源:test_publish.py


示例3: test_notfound_with_predicates

def test_notfound_with_predicates():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        return "view"

    register_view(app, Model, view, predicates=dict(name=''))
    model = Model()
    request = app.request(get_environ())
    request.unconsumed = ['foo']
    with pytest.raises(NotFound):
        resolve_response(request, model)
开发者ID:iapilgrim,项目名称:morepath,代码行数:14,代码来源:test_publish.py


示例4: test_notfound_with_predicates

def test_notfound_with_predicates():
    class app(morepath.App):
        pass

    dectate.commit(app)

    def view(self, request):
        return "view"

    app.config.view_registry.register_view(dict(model=Model), view)

    model = Model()
    request = app().request(get_environ(''))
    request.unconsumed = ['foo']
    with pytest.raises(HTTPNotFound):
        resolve_response(model, request)
开发者ID:blaflamme,项目名称:morepath,代码行数:16,代码来源:test_publish.py


示例5: test_notfound_with_predicates

def test_notfound_with_predicates():
    config = setup()

    class app(morepath.App):
        testing_config = config

    config.commit()

    def view(self, request):
        return "view"

    register_view(app.registry, dict(model=Model), view)
    model = Model()
    request = app().request(get_environ(''))
    request.unconsumed = ['foo']
    with pytest.raises(HTTPNotFound):
        resolve_response(request, model)
开发者ID:binbrain,项目名称:morepath,代码行数:17,代码来源:test_publish.py


示例6: test_predicates

def test_predicates():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        return "all"

    def post_view(self, request):
        return "post"

    register_view(app, Model, view, predicates=dict(name=''))
    register_view(app, Model, post_view,
                  predicates=dict(name='', request_method='POST'))

    model = Model()
    assert resolve_response(
        app.request(get_environ(path='')), model).data == 'all'
    assert (resolve_response(app.request(get_environ(path='', method='POST')),
                             model).data == 'post')
开发者ID:iapilgrim,项目名称:morepath,代码行数:20,代码来源:test_publish.py


示例7: test_response_returned

def test_response_returned():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        return Response('Hello world!')

    register_view(app, Model, view)
    model = Model()
    response = resolve_response(app.request(get_environ(path='')), model)
    assert response.data == 'Hello world!'
开发者ID:iapilgrim,项目名称:morepath,代码行数:12,代码来源:test_publish.py


示例8: test_view

def test_view():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        return "View!"

    register_view(app, Model, view, predicates=dict(name=''))

    model = Model()
    result = resolve_response(app.request(get_environ(path='')), model)
    assert result.data == 'View!'
开发者ID:iapilgrim,项目名称:morepath,代码行数:13,代码来源:test_publish.py


示例9: test_predicates

def test_predicates():
    class app(App):
        pass

    dectate.commit(app)

    def view(self, request):
        return "all"

    def post_view(self, request):
        return "post"

    app.get_view.register(View(view), model=Model)
    app.get_view.register(View(post_view), model=Model, request_method='POST')

    model = Model()
    assert resolve_response(
        model, app().request(get_environ(path=''))).body == b'all'
    assert (
        resolve_response(
            model, app().request(get_environ(path='', method='POST'))).body ==
        b'post')
开发者ID:morepath,项目名称:morepath,代码行数:22,代码来源:test_publish.py


示例10: test_view

def test_view():
    class app(App):
        pass

    dectate.commit(app)

    def view(self, request):
        return "View!"

    app.config.view_registry.register_view(dict(model=Model), view)

    model = Model()
    result = resolve_response(model, app().request(get_environ(path='')))
    assert result.body == b'View!'
开发者ID:blaflamme,项目名称:morepath,代码行数:14,代码来源:test_publish.py


示例11: test_response_returned

def test_response_returned():
    app = App()

    c = setup()
    c.configurable(app)
    c.commit()

    def view(request, model):
        return Response('Hello world!')

    register_view(app, Model, view)
    model = Model()
    response = resolve_response(app.request(get_environ(path='')), model)
    assert response.data == 'Hello world!'
开发者ID:webmaven,项目名称:morepath,代码行数:14,代码来源:test_publish.py


示例12: test_response_returned

def test_response_returned():
    class app(morepath.App):
        pass

    dectate.commit(app)

    def view(self, request):
        return Response('Hello world!')

    app.config.view_registry.register_view(dict(model=Model), view)

    model = Model()
    response = resolve_response(model, app().request(get_environ(path='')))
    assert response.body == b'Hello world!'
开发者ID:blaflamme,项目名称:morepath,代码行数:14,代码来源:test_publish.py


示例13: test_response_returned

def test_response_returned():
    config = setup()

    class app(morepath.App):
        testing_config = config

    config.commit()

    def view(self, request):
        return Response('Hello world!')

    register_view(app.registry, dict(model=Model), view)
    model = Model()
    response = resolve_response(app().request(get_environ(path='')), model)
    assert response.body == b'Hello world!'
开发者ID:binbrain,项目名称:morepath,代码行数:15,代码来源:test_publish.py


示例14: test_render_html

def test_render_html():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        return '<p>Hello world!</p>'

    register_view(app, Model, view, render=render_html)

    request = app.request(get_environ(path=''))
    model = Model()
    response = resolve_response(request, model)
    assert response.data == '<p>Hello world!</p>'
    assert response.content_type == 'text/html'
开发者ID:iapilgrim,项目名称:morepath,代码行数:15,代码来源:test_publish.py


示例15: test_view

def test_view():
    app = App()

    c = setup()
    c.configurable(app)
    c.commit()

    def view(request, model):
        return "View!"

    register_view(app, Model, view, predicates=dict(name=''))

    model = Model()
    result = resolve_response(app.request(get_environ(path='')), model)
    assert result.data == 'View!'
开发者ID:webmaven,项目名称:morepath,代码行数:15,代码来源:test_publish.py


示例16: test_view

def test_view():
    config = setup()

    class app(App):
        testing_config = config

    config.commit()

    def view(self, request):
        return "View!"

    register_view(app.registry, dict(model=Model), view)

    model = Model()
    result = resolve_response(app().request(get_environ(path='')), model)
    assert result.body == b'View!'
开发者ID:binbrain,项目名称:morepath,代码行数:16,代码来源:test_publish.py


示例17: test_render_html

def test_render_html():
    class app(App):
        pass

    dectate.commit(app)

    def view(self, request):
        return '<p>Hello world!</p>'

    app.get_view.register(View(view, render=render_html), model=Model)

    request = app().request(get_environ(path=''))
    model = Model()
    response = resolve_response(model, request)
    assert response.body == b'<p>Hello world!</p>'
    assert response.content_type == 'text/html'
开发者ID:morepath,项目名称:morepath,代码行数:16,代码来源:test_publish.py


示例18: test_view_after

def test_view_after():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        @request.after
        def set_header(response):
            response.headers.add('Foo', 'FOO')
        return "View!"

    register_view(app, Model, view, predicates=dict(name=''))

    model = Model()
    result = resolve_response(app.request(get_environ(path='')), model)
    assert result.data == 'View!'
    assert result.headers.get('Foo') == 'FOO'
开发者ID:iapilgrim,项目名称:morepath,代码行数:17,代码来源:test_publish.py


示例19: test_view_after

def test_view_after():
    class app(morepath.App):
        pass

    dectate.commit(app)

    def view(self, request):
        @request.after
        def set_header(response):
            response.headers.add('Foo', 'FOO')
        return "View!"

    app.get_view.register(View(view), model=Model)

    model = Model()
    result = resolve_response(model, app().request(get_environ(path='')))
    assert result.body == b'View!'
    assert result.headers.get('Foo') == 'FOO'
开发者ID:morepath,项目名称:morepath,代码行数:18,代码来源:test_publish.py


示例20: test_render_html

def test_render_html():
    config = setup()

    class app(App):
        testing_config = config

    config.commit()

    def view(self, request):
        return '<p>Hello world!</p>'

    register_view(app.registry, dict(model=Model), view, render=render_html)

    request = app().request(get_environ(path=''))
    model = Model()
    response = resolve_response(request, model)
    assert response.body == b'<p>Hello world!</p>'
    assert response.content_type == 'text/html'
开发者ID:binbrain,项目名称:morepath,代码行数:18,代码来源:test_publish.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python traject.parse_path函数代码示例发布时间:2022-05-27
下一篇:
Python core.setup函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap