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


Python App.lookup方法代码示例

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


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

示例1: test_register_path_with_parameters

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import lookup [as 别名]
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, lambda: root)
    register_path(app, Model, '{id}', lambda model: {'id': model.id,
                                                     'param': model.param },
                  None, None, get_model)

    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'})
    assert generic.app(model, lookup=lookup) is app
开发者ID:iapilgrim,项目名称:morepath,代码行数:34,代码来源:test_model.py

示例2: test_register_root

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

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

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

示例3: test_imperative

# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import lookup [as 别名]
def test_imperative():
    class Foo(object):
        pass

    @reg.generic
    def target():
        pass

    app = App()

    c = setup()
    foo = Foo()
    c.configurable(app)
    c.action(app.function(target), foo)
    c.commit()

    assert target.component(lookup=app.lookup()) is foo
开发者ID:webmaven,项目名称:morepath,代码行数:19,代码来源:test_directive.py

示例4: test_register_path

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

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

    config.commit()

    register_path(app, Root, '', lambda m: {}, None, None, lambda: root)
    register_path(app, Model, '{id}', lambda model: {'id': model.id},
                  None, None, get_model)

    obj, request = consume(app, 'a')
    assert obj.id == 'a'
    model = Model()
    model.id = 'b'
    assert generic.path(model, lookup=lookup) == ('b', {})
    assert generic.app(model, lookup=lookup) is app
开发者ID:iapilgrim,项目名称:morepath,代码行数:25,代码来源:test_model.py

示例5: test_register_model

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

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

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

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

    obj, request = consume(app, 'a')
    assert obj.id == 'a'
    model = Model()
    model.id = 'b'
    assert generic.path(model, lookup=lookup) == 'b'
    assert generic.base(model, lookup=lookup) is app
开发者ID:kod3r,项目名称:morepath,代码行数:26,代码来源:test_model.py


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