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

Python app.App类代码示例

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

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



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

示例1: test_traject_consumer_combination

def test_traject_consumer_combination():
    app = App()

    traject = Traject()

    def get_model(foo):
        result = Model()
        result.foo = foo
        return result

    traject.register('special', Special)
    traject.register('{foo}', get_model)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('something'),
                                         Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    assert obj.foo == 'something'
    found, obj, stack = traject_consumer(app, parse_path('special'),
                                         Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
开发者ID:kingel,项目名称:morepath,代码行数:25,代码来源:test_traject.py


示例2: test_view_predicates

def test_view_predicates():
    app = App()

    class Root(object):
        pass

    def get(request, model):
        return 'GET'

    def post(request, model):
        return 'POST'

    c = setup()
    c.configurable(app)
    c.action(app.root(), Root)
    c.action(app.view(model=Root, name='foo', request_method='GET'),
             get)
    c.action(app.view(model=Root, name='foo', request_method='POST'),
             post)
    c.commit()

    c = Client(app, Response)

    response = c.get('/foo')
    assert response.data == 'GET'
    response = c.post('/foo')
    assert response.data == 'POST'
开发者ID:kod3r,项目名称:morepath,代码行数:27,代码来源:test_predicates.py


示例3: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result
    traject.add_pattern('{first_id}', get_model)
    traject.add_pattern('{first_id}/{second_id}', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, 'a')
    assert isinstance(found, Model)
    assert found.first_id == 'a'
    assert not hasattr(found, 'second_id')
    assert request.unconsumed == []

    found, request = consume(app, 'a/b')
    assert isinstance(found, Special)
    assert found.first_id == 'a'
    assert found.second_id == 'b'
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:30,代码来源:test_traject.py


示例4: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.add_pattern('{id}', get_model)
    traject.add_pattern('{id}/sub', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, 'a')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, 'b')
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, 'a/sub')
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:28,代码来源:test_traject.py


示例5: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.add_pattern("{id}", (get_model, paramfac))
    traject.add_pattern("{id}/sub", (get_special, paramfac))
    app.register(generic.traject, [App], lambda base: traject)
    app.register(generic.context, [object], lambda obj: {})

    found, request = consume(app, "a")
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, "b")
    assert isinstance(found, Model)
    assert request.unconsumed == []
    found, request = consume(app, "a/sub")
    assert isinstance(found, Special)
    assert request.unconsumed == []
开发者ID:pombredanne,项目名称:morepath,代码行数:29,代码来源:test_traject.py


示例6: test_notfound

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,代码行数:7,代码来源:test_publish.py


示例7: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result

    traject.add_pattern("{first_id}", (get_model, paramfac))
    traject.add_pattern("{first_id}/{second_id}", (get_special, paramfac))
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, "a")
    assert isinstance(found, Model)
    assert found.first_id == "a"
    assert not hasattr(found, "second_id")
    assert request.unconsumed == []

    found, request = consume(app, "a/b")
    assert isinstance(found, Special)
    assert found.first_id == "a"
    assert found.second_id == "b"
    assert request.unconsumed == []
开发者ID:reinout,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例8: test_traject_nested_with_variable

def test_traject_nested_with_variable():
    app = App()

    traject = Traject()

    def get_model(id):
        result = Model()
        result.id = id
        return result

    def get_special(id):
        result = Special()
        result.id = id
        return result

    traject.register('{id}', get_model)
    traject.register('{id}/sub', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('a'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    found, obj, stack = traject_consumer(app, parse_path('b'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    found, obj, stack = traject_consumer(app, parse_path('a/sub'), Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
开发者ID:kingel,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例9: test_register_model

def test_register_model():
    setup()
    app = App()
    root = Root()
    app.root_model = Root
    app.root_obj = root
    lookup = Lookup(ChainClassLookup(app, global_app))

    def get_model(id):
        model = Model()
        model.id = id
        return model

    register_root(app, Root, lambda: root)
    register_model(app, Model, '{id}', lambda model: {'id': model.id},
                   get_model)

    found, obj, stack = traject_consumer(app, parse_path('a'), lookup)
    assert obj.id == 'a'
    model = Model()
    model.id = 'b'
    request = get_request()
    request.lookup = lookup
    assert generic.path(request, model, lookup=lookup) == 'b'
    assert generic.base(model, lookup=lookup) is app
开发者ID:kingel,项目名称:morepath,代码行数:25,代码来源:test_traject.py


示例10: test_request_view_with_predicates

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,代码行数:26,代码来源:test_publish.py


示例11: test_traject_with_multiple_variables

def test_traject_with_multiple_variables():
    app = App()

    traject = Traject()

    def get_model(first_id):
        result = Model()
        result.first_id = first_id
        return result

    def get_special(first_id, second_id):
        result = Special()
        result.first_id = first_id
        result.second_id = second_id
        return result
    traject.register('{first_id}', get_model)
    traject.register('{first_id}/{second_id}', get_special)
    app.register(generic.traject, [App], lambda base: traject)

    found, obj, stack = traject_consumer(app, parse_path('a'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
    assert obj.first_id == 'a'
    assert not hasattr(obj, 'second_id')
    found, obj, stack = traject_consumer(app, parse_path('a/b'), Lookup(app))
    assert found
    assert isinstance(obj, Special)
    assert stack == []
    assert obj.first_id == 'a'
    assert obj.second_id == 'b'
开发者ID:kingel,项目名称:morepath,代码行数:31,代码来源:test_traject.py


示例12: test_register_path_with_parameters

def test_register_path_with_parameters():
    config = setup()
    app = App(testing_config=config)
    root = Root()
    lookup = app.lookup

    def get_model(id, param='default'):
        model = Model()
        model.id = id
        model.param = param
        return model

    config.commit()

    register_path(app, Root,  '', lambda m: {}, None, None, None, lambda: root)
    register_path(app, Model, '{id}', lambda model: {'id': model.id,
                                                     'param': model.param},
                  None, None, None, get_model)
    app.register(generic.context, [object], lambda obj: {})

    obj, request = consume(app, 'a')
    assert obj.id == 'a'
    assert obj.param == 'default'

    obj, request = consume(app, 'a', {'param': 'value'})
    assert obj.id == 'a'
    assert obj.param == 'value'

    model = Model()
    model.id = 'b'
    model.param = 'other'
    assert generic.path(model, lookup=lookup) == ('b', {'param': ['other']})
开发者ID:fudomunro,项目名称:morepath,代码行数:32,代码来源:test_model.py


示例13: test_extra_predicates

def test_extra_predicates():
    app = App()

    class Model(object):
        def __init__(self, id):
            self.id = id

    def get_a(request, model):
        return 'a'

    def get_b(request, model):
        return 'b'

    def get_id(request, model):
        return model.id

    c = setup()
    c.configurable(app)
    c.action(app.model(path='{id}'), Model)
    c.action(app.view(model=Model, name='foo', id='a'),
             get_a)
    c.action(app.view(model=Model, name='foo', id='b'),
             get_b)
    c.action(app.predicate(name='id', order=2, default=''),
             get_id)
    c.commit()

    c = Client(app, Response)

    response = c.get('/a/foo')
    assert response.data == 'a'
    response = c.post('/b/foo')
    assert response.data == 'b'
开发者ID:kod3r,项目名称:morepath,代码行数:33,代码来源:test_predicates.py


示例14: test_traject_consume

def test_traject_consume():
    app = App()
    traject = Traject()
    traject.add_pattern('sub', Model)
    app.register(generic.traject, [App], lambda base: traject)
    found, request = consume(app, 'sub')
    assert isinstance(found, Model)
    assert request.unconsumed == []
开发者ID:kod3r,项目名称:morepath,代码行数:8,代码来源:test_traject.py


示例15: test_notfound

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,代码行数:9,代码来源:test_publish.py


示例16: test_traject_consumer

def test_traject_consumer():
    app = App()
    traject = Traject()
    traject.register('sub', Model)
    app.register(generic.traject, [App], lambda base: traject)
    found, obj, stack = traject_consumer(app, parse_path('sub'), Lookup(app))
    assert found
    assert isinstance(obj, Model)
    assert stack == []
开发者ID:kingel,项目名称:morepath,代码行数:9,代码来源:test_traject.py


示例17: test_traject_consume

def test_traject_consume():
    app = App()
    traject = Traject()
    traject.add_pattern("sub", (Model, paramfac))
    app.register(generic.traject, [App], lambda base: traject)
    app.register(generic.context, [object], lambda obj: {})

    found, request = consume(app, "sub")
    assert isinstance(found, Model)
    assert request.unconsumed == []
开发者ID:pombredanne,项目名称:morepath,代码行数:10,代码来源:test_traject.py


示例18: test_notfound

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,代码行数:10,代码来源:test_publish.py


示例19: test_traject_root

def test_traject_root():
    app = App()

    traject = Traject()

    traject.add_pattern("", (Root, paramfac))
    app.register(generic.traject, [App], lambda base: traject)

    found, request = consume(app, "")
    assert isinstance(found, Root)
    assert request.unconsumed == []
开发者ID:reinout,项目名称:morepath,代码行数:11,代码来源:test_traject.py


示例20: test_register_root

def test_register_root():
    app = App()
    root = Root()
    app.root_model = Root
    app.root_obj = root
    lookup = Lookup(ChainClassLookup(app, global_app))

    register_root(app, Root, lambda: root)
    request = get_request()
    request.lookup = lookup
    assert generic.path(request, root, lookup=lookup) == ''
    assert generic.base(root, lookup=lookup) is app
开发者ID:kingel,项目名称:morepath,代码行数:12,代码来源:test_traject.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python config.Config类代码示例发布时间:2022-05-27
下一篇:
Python morepath.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