本文整理汇总了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
示例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
示例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
示例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
示例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