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


Python App.request方法代码示例

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


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

示例1: test_request_view_with_predicates

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_request_view_with_predicates():
    app = App()

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

    def view(request, model):
        return {'hey': 'hey'}

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

    request = app.request(get_environ(path=''))
    request.mounts = [app]  # XXX should do this centrally

    model = Model()
    # since the name is set to foo, we get nothing here
    assert request.view(model) is None
    # we have to pass the name predicate ourselves
    assert request.view(model, name='foo') == {'hey': 'hey'}
    # the predicate information in the request is ignored when we do a
    # manual view lookup using request.view
    request = app.request(get_environ(path='foo'))
    request.mounts = [app]  # XXX should do this centrally
    assert request.view(model) is None
开发者ID:webmaven,项目名称:morepath,代码行数:28,代码来源:test_publish.py

示例2: test_notfound

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_notfound():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    response = publish(app.request(get_environ(path='')), app.mounted())
    assert response.status == '404 NOT FOUND'
开发者ID:iapilgrim,项目名称:morepath,代码行数:9,代码来源:test_publish.py

示例3: test_notfound

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_notfound():
    app = App()

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

    response = publish(app.request(get_environ(path='')), app.mounted())
    assert response.status == '404 NOT FOUND'
开发者ID:webmaven,项目名称:morepath,代码行数:11,代码来源:test_publish.py

示例4: test_notfound

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_notfound():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    request = app.request(get_environ(path=''))
    request.mounts.append(app.mounted())

    with pytest.raises(HTTPNotFound):
        publish(request)
开发者ID:fudomunro,项目名称:morepath,代码行数:12,代码来源:test_publish.py

示例5: test_predicates

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:22,代码来源:test_publish.py

示例6: test_response_returned

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:14,代码来源:test_publish.py

示例7: test_view

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:15,代码来源:test_publish.py

示例8: test_notfound_with_predicates

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:16,代码来源:test_publish.py

示例9: test_response_returned

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:16,代码来源:test_publish.py

示例10: test_render_html

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:17,代码来源:test_publish.py

示例11: test_view

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:17,代码来源:test_publish.py

示例12: test_view_raises_http_error

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_view_raises_http_error():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    from werkzeug.exceptions import BadRequest
    def view(self, request):
        raise BadRequest()

    register_path(app, Model, 'foo', None, None, None, Model)
    register_view(app, Model, view)

    response = publish(app.request(get_environ(path='foo')), app.mounted())

    assert response.status == '400 BAD REQUEST'
开发者ID:iapilgrim,项目名称:morepath,代码行数:17,代码来源:test_publish.py

示例13: test_view_raises_http_error

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_view_raises_http_error():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        raise HTTPBadRequest()

    register_path(app, Model, 'foo', None, None, None, None, Model)
    register_view(app, Model, view)

    request = app.request(get_environ(path='foo'))
    request.mounts.append(app.mounted())

    with pytest.raises(HTTPBadRequest):
        publish(request)
开发者ID:fudomunro,项目名称:morepath,代码行数:18,代码来源:test_publish.py

示例14: test_view_raises_http_error

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
def test_view_raises_http_error():
    app = App()

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

    from werkzeug.exceptions import BadRequest
    def view(request, model):
        raise BadRequest()

    register_model(app, Model, 'foo', None, Model)
    register_view(app, Model, view)

    response = publish(app.request(get_environ(path='foo')), app.mounted())

    assert response.status == '400 BAD REQUEST'
开发者ID:webmaven,项目名称:morepath,代码行数:19,代码来源:test_publish.py

示例15: test_view_after

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import request [as 别名]
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,代码行数:19,代码来源:test_publish.py


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