本文整理汇总了Python中webobtoolkit.client.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_variable_path_explicit_trumps_implicit
def test_variable_path_explicit_trumps_implicit():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id):
self.id = id
@app.path(model=Model, path='{id}',
converters=dict(id=Converter(int)))
def get_model(id='foo'):
return Model(id)
@app.view(model=Model)
def default(self, request):
return "View: %s (%s)" % (self.id, type(self.id))
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('1')
assert response.body == "View: 1 (<type 'int'>)"
response = c.get('/1/link')
assert response.body == '/1'
response = c.get('broken')
assert response.status == '404 Not Found'
开发者ID:reinout,项目名称:morepath,代码行数:33,代码来源:test_path_directive.py
示例2: test_basic_auth_remember
def test_basic_auth_remember():
config = setup()
app = morepath.App(testing_config=config)
@app.path(path='{id}',
variables=lambda model: {'id': model.id})
class Model(object):
def __init__(self, id):
self.id = id
@app.view(model=Model)
def default(self, request):
# will not actually do anything as it's a no-op for basic
# auth, but at least won't crash
response = Response()
generic.remember(response, request, Identity('foo'),
lookup=request.lookup)
return response
@app.identity_policy()
def policy():
return BasicAuthIdentityPolicy()
config.commit()
c = Client(app)
response = c.get('/foo')
assert response.status == '200 OK'
assert response.body == ''
开发者ID:reinout,项目名称:morepath,代码行数:30,代码来源:test_security.py
示例3: test_permission_directive_no_identity
def test_permission_directive_no_identity():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id):
self.id = id
class Permission(object):
pass
@app.path(model=Model, path='{id}',
variables=lambda model: {'id': model.id})
def get_model(id):
return Model(id)
@app.permission(model=Model, permission=Permission, identity=None)
def get_permission(identity, model, permission):
if model.id == 'foo':
return True
else:
return False
@app.view(model=Model, permission=Permission)
def default(self, request):
return "Model: %s" % self.id
config.commit()
c = Client(app)
response = c.get('/foo')
assert response.body == 'Model: foo'
response = c.get('/bar')
assert response.status == '401 Unauthorized'
开发者ID:reinout,项目名称:morepath,代码行数:35,代码来源:test_security.py
示例4: test_mount
def test_mount():
config = setup()
app = morepath.App('app', testing_config=config)
mounted = morepath.App('mounted', testing_config=config)
@mounted.path(path='')
class MountedRoot(object):
pass
@mounted.view(model=MountedRoot)
def root_default(self, request):
return "The root"
@mounted.view(model=MountedRoot, name='link')
def root_link(self, request):
return request.link(self)
@app.mount(path='{id}', app=mounted)
def get_context():
return {}
config.commit()
c = Client(app)
response = c.get('/foo')
assert response.body == 'The root'
response = c.get('/foo/link')
assert response.body == '/foo'
开发者ID:reinout,项目名称:morepath,代码行数:30,代码来源:test_directive.py
示例5: test_extra_predicates
def test_extra_predicates():
config = setup()
app = App(testing_config=config)
@app.path(path="{id}")
class Model(object):
def __init__(self, id):
self.id = id
@app.view(model=Model, name="foo", id="a")
def get_a(self, request):
return "a"
@app.view(model=Model, name="foo", id="b")
def get_b(self, request):
return "b"
@app.predicate(name="id", order=2, default="")
def get_id(self, request):
return self.id
config.commit()
c = Client(app)
response = c.get("/a/foo")
assert response.body == "a"
response = c.get("/b/foo")
assert response.body == "b"
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_predicates.py
示例6: test_link_to_unknown_model
def test_link_to_unknown_model():
config = setup()
app = morepath.App(testing_config=config)
@app.path(path='')
class Root(object):
def __init__(self):
self.value = 'ROOT'
class Model(object):
def __init__(self, id):
self.id = id
@app.view(model=Root)
def root_link(self, request):
try:
return request.link(Model('foo'))
except LinkError:
return "Link error"
@app.view(model=Root, name='default')
def root_link_with_default(self, request):
try:
return request.link(Model('foo'), default='hey')
except LinkError:
return "Link Error"
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'Link error'
response = c.get('/default')
assert response.body == 'Link Error'
开发者ID:reinout,项目名称:morepath,代码行数:35,代码来源:test_directive.py
示例7: test_root_link_with_parameters
def test_root_link_with_parameters():
config = setup()
app = morepath.App(testing_config=config)
@app.path(path='')
class Root(object):
def __init__(self, param=0):
assert isinstance(param, int)
self.param = param
@app.view(model=Root)
def default(self, request):
return "The view for root: %s" % self.param
@app.view(model=Root, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'The view for root: 0'
response = c.get('/link')
assert response.body == '/?param=0'
response = c.get('/?param=1')
assert response.body == 'The view for root: 1'
response = c.get('/link?param=1')
assert response.body == '/?param=1'
开发者ID:reinout,项目名称:morepath,代码行数:33,代码来源:test_directive.py
示例8: test_path_and_url_parameter_converter
def test_path_and_url_parameter_converter():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id, param):
self.id = id
self.param = param
from datetime import date
@app.path(model=Model, path='/{id}', converters=dict(param=date))
def get_model(id=0, param=None):
return Model(id, param)
@app.view(model=Model)
def default(self, request):
return "View: %s %s" % (self.id, self.param)
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/1/link')
assert response.body == '/1'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py
示例9: test_variable_path_one_step
def test_variable_path_one_step():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, name):
self.name = name
@app.path(model=Model, path='{name}')
def get_model(name):
return Model(name)
@app.view(model=Model)
def default(self, request):
return "View: %s" % self.name
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/foo')
assert response.body == 'View: foo'
response = c.get('/foo/link')
assert response.body == '/foo'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py
示例10: test_type_hints_and_converters
def test_type_hints_and_converters():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, d):
self.d = d
from datetime import date
@app.path(model=Model, path='', converters=dict(d=date))
def get_model(d):
return Model(d)
@app.view(model=Model)
def default(self, request):
return "View: %s" % self.d
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/?d=20140120')
assert response.body == "View: 2014-01-20"
response = c.get('/link?d=20140120')
assert response.body == '/?d=20140120'
开发者ID:reinout,项目名称:morepath,代码行数:31,代码来源:test_path_directive.py
示例11: test_link_for_none_means_no_parameter
def test_link_for_none_means_no_parameter():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id):
self.id = id
@app.path(model=Model, path='')
def get_model(id):
return Model(id)
@app.view(model=Model)
def default(self, request):
return "View: %s" % self.id
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == "View: None"
response = c.get('/link')
assert response.body == '/'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py
示例12: test_variable_path_parameter_required_with_default
def test_variable_path_parameter_required_with_default():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id):
self.id = id
@app.path(model=Model, path='', required=['id'])
def get_model(id='b'):
return Model(id)
@app.view(model=Model)
def default(self, request):
return "View: %s" % self.id
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/?id=a')
assert response.body == "View: a"
response = c.get('/')
assert response.status == '400 Bad Request'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py
示例13: test_simple_path_two_steps
def test_simple_path_two_steps():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self):
pass
@app.path(model=Model, path='one/two')
def get_model():
return Model()
@app.view(model=Model)
def default(self, request):
return "View"
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/one/two')
assert response.body == 'View'
response = c.get('/one/two/link')
assert response.body == '/one/two'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py
示例14: test_url_parameter_implicit_converter
def test_url_parameter_implicit_converter():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
def __init__(self, id):
self.id = id
@app.path(model=Model, path='/')
def get_model(id=0):
return Model(id)
@app.view(model=Model)
def default(self, request):
return "View: %s (%s)" % (self.id, type(self.id))
@app.view(model=Model, name='link')
def link(self, request):
return request.link(self)
config.commit()
c = Client(app)
response = c.get('/?id=1')
assert response.body == "View: 1 (<type 'int'>)"
response = c.get('/link?id=1')
assert response.body == '/?id=1'
response = c.get('/?id=broken')
assert response.status == '400 Bad Request'
response = c.get('/')
assert response.body == "View: 0 (<type 'int'>)"
开发者ID:reinout,项目名称:morepath,代码行数:35,代码来源:test_path_directive.py
示例15: test_mount_repr
def test_mount_repr():
config = setup()
app = morepath.App('app', testing_config=config)
mounted = morepath.App('mounted', variables=['mount_id'],
testing_config=config)
@mounted.path(path='models/{id}')
class Model(object):
def __init__(self, id):
self.id = id
@app.path(path='')
class Root(object):
pass
@app.view(model=Root)
def app_root_default(self, request):
return repr(request.mounted().child(mounted, id='foo'))
@app.mount(path='{id}', app=mounted)
def get_context(id):
return {
'mount_id': id
}
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == (
"<morepath.Mount of <morepath.App 'mounted'> with "
"variables: id='foo', "
"parent=<morepath.Mount of <morepath.App 'app'>>>")
开发者ID:reinout,项目名称:morepath,代码行数:34,代码来源:test_directive.py
示例16: test_implicit_disabled
def test_implicit_disabled():
morepath.disable_implicit()
config = morepath.setup()
app = morepath.App(testing_config=config)
@app.path(path='')
class Model(object):
def __init__(self):
pass
@reg.generic
def one():
return "default one"
@app.view(model=Model)
def default(self, request):
try:
return one()
except reg.NoImplicitLookupError:
return "No implicit found"
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'No implicit found'
开发者ID:reinout,项目名称:morepath,代码行数:27,代码来源:test_implicit.py
示例17: test_abbr_imperative
def test_abbr_imperative():
config = setup()
app = morepath.App(testing_config=config)
class Model(object):
pass
@app.path(path='/', model=Model)
def get_model():
return Model()
with app.view(model=Model) as view:
@view()
def default(self, request):
return "Default view"
@view(name='edit')
def edit(self, request):
return "Edit view"
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'Default view'
response = c.get('/edit')
assert response.body == 'Edit view'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_directive.py
示例18: test_implicit_function
def test_implicit_function():
config = morepath.setup()
app = morepath.App(testing_config=config)
@app.path(path='')
class Model(object):
def __init__(self):
pass
@reg.generic
def one():
return "Default one"
@reg.generic
def two():
return "Default two"
@app.function(one)
def one_impl():
return two()
@app.function(two)
def two_impl():
return "The real two"
@app.view(model=Model)
def default(self, request):
return one()
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'The real two'
开发者ID:reinout,项目名称:morepath,代码行数:35,代码来源:test_implicit.py
示例19: test_link_to_none
def test_link_to_none():
config = setup()
app = morepath.App(testing_config=config)
@app.path(path='')
class Root(object):
def __init__(self):
self.value = 'ROOT'
class Model(object):
def __init__(self, id):
self.id = id
@app.view(model=Root)
def root_link(self, request):
return str(request.link(None) is None)
@app.view(model=Root, name='default')
def root_link_with_default(self, request):
return request.link(None, default='unknown')
config.commit()
c = Client(app)
response = c.get('/')
assert response.body == 'True'
response = c.get('/default')
assert response.body == 'unknown'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_directive.py
示例20: test_mount_context
def test_mount_context():
config = setup()
app = morepath.App('app', testing_config=config)
mounted = morepath.App('mounted', variables=['mount_id'],
testing_config=config)
@mounted.path(path='')
class MountedRoot(object):
def __init__(self, mount_id):
self.mount_id = mount_id
@mounted.view(model=MountedRoot)
def root_default(self, request):
return "The root for mount id: %s" % self.mount_id
@app.mount(path='{id}', app=mounted)
def get_context(id):
return {
'mount_id': id
}
config.commit()
c = Client(app)
response = c.get('/foo')
assert response.body == 'The root for mount id: foo'
response = c.get('/bar')
assert response.body == 'The root for mount id: bar'
开发者ID:reinout,项目名称:morepath,代码行数:29,代码来源:test_directive.py
注:本文中的webobtoolkit.client.Client类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论