本文整理汇总了Python中morepath.config.Config.get方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get方法的具体用法?Python Config.get怎么用?Python Config.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类morepath.config.Config
的用法示例。
在下文中一共展示了Config.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_json_directive
# 需要导入模块: from morepath.config import Config [as 别名]
# 或者: from morepath.config.Config import get [as 别名]
def test_json_directive():
setup()
app = morepath.App()
class Model(object):
def __init__(self, id):
self.id = id
def default(request, model):
return "The view for model: %s" % model.id
def json(request, model):
return {'id': model.id}
c = Config()
c.action(app, app)
c.action(app.model(path='{id}',
variables=lambda model: {'id': model.id}),
Model)
c.action(app.json(model=Model),
json)
c.commit()
c = Client(app, Response)
response = c.get('/foo')
assert response.data == '{"id": "foo"}'
示例2: test_view_predicates
# 需要导入模块: from morepath.config import Config [as 别名]
# 或者: from morepath.config.Config import get [as 别名]
def test_view_predicates():
setup()
app = App()
class Root(object):
pass
def get(request, model):
return 'GET'
def post(request, model):
return 'POST'
c = Config()
c.action(app, 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'
示例3: test_redirect
# 需要导入模块: from morepath.config import Config [as 别名]
# 或者: from morepath.config.Config import get [as 别名]
def test_redirect():
setup()
app = morepath.App()
class Root(object):
def __init__(self):
pass
def default(request, model):
return morepath.redirect('/')
c = Config()
c.action(app, app)
c.action(app.root(),
Root)
c.action(app.view(model=Root, render=render_html),
default)
c.commit()
c = Client(app, Response)
response = c.get('/')
assert response.status == '302 FOUND'
示例4: test_basic_imperative
# 需要导入模块: from morepath.config import Config [as 别名]
# 或者: from morepath.config.Config import get [as 别名]
def test_basic_imperative():
setup()
app = morepath.App()
class Root(object):
def __init__(self):
self.value = 'ROOT'
class Model(object):
def __init__(self, id):
self.id = id
def get_model(id):
return Model(id)
def default(request, model):
return "The view for model: %s" % model.id
def link(request, model):
return request.link(model)
def json(request, model):
return {'id': model.id}
def root_default(request, model):
return "The root: %s" % model.value
def root_link(request, model):
return request.link(model)
c = Config()
c.action(app, app)
c.action(app.root(), Root)
c.action(app.model(model=Model, path='{id}',
variables=lambda model: {'id': model.id}),
get_model)
c.action(app.view(model=Model),
default)
c.action(app.view(model=Model, name='link'),
link)
c.action(app.view(model=Model, name='json',
render=morepath.render_json),
json)
c.action(app.view(model=Root),
root_default)
c.action(app.view(model=Root, name='link'),
root_link)
c.commit()
c = Client(app, Response)
response = c.get('/foo')
assert response.data == 'The view for model: foo'
response = c.get('/foo/link')
assert response.data == 'foo'
response = c.get('/foo/json')
assert response.data == '{"id": "foo"}'
response = c.get('/')
assert response.data == 'The root: ROOT'
# @@ is to make sure we get the view, not the sub-model
response = c.get('/@@link')
assert response.data == ''
示例5: test_base
# 需要导入模块: from morepath.config import Config [as 别名]
# 或者: from morepath.config.Config import get [as 别名]
def test_base():
setup()
class Root(object):
pass
class Container(object):
def __init__(self, id):
self.id = id
self.items = {}
def add_item(self, item_id):
result = Item(item_id, self)
self.items[item_id] = result
return result
class Item(object):
def __init__(self, id, parent):
self.id = id
self.parent = parent
alpha = Container('alpha')
beta = Container('beta')
alpha.add_item('a')
alpha.add_item('b')
c = alpha.add_item('c')
beta.add_item('d')
e = beta.add_item('e')
app = App()
c = Config()
c.action(app, app)
c.action(app.root(), Root)
def get_container(container_id):
if container_id == 'alpha':
return alpha
elif container_id == 'beta':
return beta
return None
c.action(
app.model(
model=Container,
path="{container_id}",
variables=lambda container: {'container_id': container.id}),
get_container)
def get_item(base, item_id):
return base.items.get(item_id)
c.action(
app.model(model=Item,
path="{item_id}",
variables=lambda item: {'item_id': item.id},
base=Container,
get_base=lambda item: item.parent),
get_item)
c.action(
app.view(model=Container),
lambda request, model: 'container: %s' % model.id)
c.action(
app.view(model=Container, name='link'),
lambda request, model: request.link(model))
c.action(
app.view(model=Item),
lambda request, model: 'item: %s' % model.id)
c.action(
app.view(model=Item, name='link'),
lambda request, model: request.link(model))
c.action(
app.view(model=Item, name='otherlink'),
lambda request, model: request.link(e))
c.commit()
c = Client(app, Response)
response = c.get('/alpha')
assert response.data == 'container: alpha'
response = c.get('/beta')
assert response.data == 'container: beta'
response = c.get('/alpha/a')
assert response.data == 'item: a'
response = c.get('/beta/e')
assert response.data == 'item: e'
response = c.get('/alpha/e')
assert response.status == '404 NOT FOUND'
response = c.get('/alpha/@@link')
assert response.data == 'alpha'
response = c.get('/alpha/a/link')
assert response.data == 'alpha/a'
response = c.get('/alpha/a/otherlink')
assert response.data == 'beta/e'