本文整理汇总了Python中morepath.app.App.root_obj方法的典型用法代码示例。如果您正苦于以下问题:Python App.root_obj方法的具体用法?Python App.root_obj怎么用?Python App.root_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类morepath.app.App
的用法示例。
在下文中一共展示了App.root_obj方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_model
# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import root_obj [as 别名]
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
示例2: test_register_root
# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import root_obj [as 别名]
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
示例3: test_traject_path_with_leading_slash
# 需要导入模块: from morepath.app import App [as 别名]
# 或者: from morepath.app.App import root_obj [as 别名]
def test_traject_path_with_leading_slash():
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, '/foo/{id}', lambda model: {'id': model.id},
get_model)
found, obj, stack = traject_consumer(app, parse_path('foo/a'), lookup)
assert obj.id == 'a'
found, obj, stack = traject_consumer(app, parse_path('/foo/a'), lookup)
assert obj.id == 'a'