• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python morepath.setup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中morepath.setup函数的典型用法代码示例。如果您正苦于以下问题:Python setup函数的具体用法?Python setup怎么用?Python setup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_rescan

def test_rescan():
    config = setup()

    config.scan(basic)

    config.commit()

    config = setup()

    config.scan(basic)

    class Sub(basic.app):
        testing_config = config

    @Sub.view(model=basic.Model, name='extra')
    def extra(self, request):
        return "extra"

    config.commit()

    c = Client(Sub())

    response = c.get('/1/extra')
    assert response.body == b'extra'

    response = c.get('/1')
    assert response.body == b'The view for model: 1'
开发者ID:binbrain,项目名称:morepath,代码行数:27,代码来源:test_directive.py


示例2: test_json_directive

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"}'
开发者ID:kingel,项目名称:morepath,代码行数:28,代码来源:test_directive.py


示例3: test_view_predicates

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'
开发者ID:kingel,项目名称:morepath,代码行数:30,代码来源:test_predicates.py


示例4: test_basic_json

def test_basic_json():
    setup()
    basic.app.clear()

    config = Config()
    config.scan(basic)
    config.commit()

    c = Client(basic.app, Response)

    response = c.get('/foo/json')

    assert response.data == '{"id": "foo"}'
开发者ID:kingel,项目名称:morepath,代码行数:13,代码来源:test_directive.py


示例5: test_unknown_explicit_converter

def test_unknown_explicit_converter():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, d):
            self.d = d

    class Unknown(object):
        pass

    @app.path(model=Model, path='/', converters={'d': Unknown})
    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)

    with pytest.raises(DirectiveReportError):
        config.commit()
开发者ID:binbrain,项目名称:morepath,代码行数:27,代码来源:test_path_directive.py


示例6: test_variable_path_explicit_trumps_implicit

def test_variable_path_explicit_trumps_implicit():
    config = setup()

    class 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 in \
        (b"View: 1 (<type 'int'>)", b"View: 1 (<class 'int'>)")

    response = c.get('/1/link')
    assert response.body == b'http://localhost/1'

    response = c.get('/broken', status=404)
开发者ID:binbrain,项目名称:morepath,代码行数:35,代码来源:test_path_directive.py


示例7: test_simple_path_two_steps

def test_simple_path_two_steps():
    config = setup()

    class 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 == b'View'

    response = c.get('/one/two/link')
    assert response.body == b'http://localhost/one/two'
开发者ID:binbrain,项目名称:morepath,代码行数:31,代码来源:test_path_directive.py


示例8: test_mount_context_parameters

def test_mount_context_parameters():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class mounted(morepath.App):
        testing_config = config

        def __init__(self, mount_id):
            self.mount_id = mount_id

    @mounted.path(path='')
    class MountedRoot(object):
        def __init__(self, app):
            assert isinstance(app.mount_id, int)
            self.mount_id = app.mount_id

    @mounted.view(model=MountedRoot)
    def root_default(self, request):
        return "The root for mount id: %s" % self.mount_id

    @app.mount(path='mounts', app=mounted)
    def get_context(mount_id=0):
        return mounted(mount_id=mount_id)

    config.commit()

    c = Client(app())

    response = c.get('/mounts?mount_id=1')
    assert response.body == b'The root for mount id: 1'
    response = c.get('/mounts')
    assert response.body == b'The root for mount id: 0'
开发者ID:ryanfreckleton,项目名称:morepath,代码行数:34,代码来源:test_mount_directive.py


示例9: test_mount_none_should_fail

def test_mount_none_should_fail():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class mounted(morepath.App):
        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 mount_mounted(id):
        return None

    config.commit()

    c = Client(app())

    c.get('/foo', status=404)
    c.get('/foo/link', status=404)
开发者ID:ryanfreckleton,项目名称:morepath,代码行数:31,代码来源:test_mount_directive.py


示例10: test_type_hints_and_converters

def test_type_hints_and_converters():
    config = setup()

    class 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 == b"View: 2014-01-20"

    response = c.get('/link?d=20140120')
    assert response.body == b'http://localhost/?d=20140120'
开发者ID:binbrain,项目名称:morepath,代码行数:33,代码来源:test_path_directive.py


示例11: test_path_and_url_parameter_converter

def test_path_and_url_parameter_converter():
    config = setup()

    class 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 == b'http://localhost/1'
开发者ID:binbrain,项目名称:morepath,代码行数:31,代码来源:test_path_directive.py


示例12: test_url_parameter_list_but_only_one_allowed

def test_url_parameter_list_but_only_one_allowed():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, item):
            self.item = item

    @app.path(model=Model, path='/', converters={'item': int})
    def get_model(item):
        return Model(item)

    @app.view(model=Model)
    def default(self, request):
        return repr(self.item)

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    c.get('/?item=1&item=2', status=400)

    c.get('/link?item=1&item=2', status=400)
开发者ID:binbrain,项目名称:morepath,代码行数:29,代码来源:test_path_directive.py


示例13: test_extra_parameters

def test_extra_parameters():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self, extra_parameters):
            self.extra_parameters = extra_parameters

    @app.path(model=Model, path='/')
    def get_model(extra_parameters):
        return Model(extra_parameters)

    @app.view(model=Model)
    def default(self, request):
        return repr(sorted(self.extra_parameters.items()))

    @app.view(model=Model, name='link')
    def link(self, request):
        return request.link(self)

    config.commit()

    c = Client(app())

    response = c.get('/?a=A&b=B')
    assert response.body in \
        (b"[(u'a', u'A'), (u'b', u'B')]", b"[('a', 'A'), ('b', 'B')]")
    response = c.get('/link?a=A&b=B')
    assert sorted(response.body[len('http://localhost/?'):].split(b"&")) == [
        b'a=A', b'b=B']
开发者ID:binbrain,项目名称:morepath,代码行数:32,代码来源:test_path_directive.py


示例14: test_basic_auth_forget

def test_basic_auth_forget():
    config = setup()
    app = morepath.App(testing_config=config)

    @app.path(path='{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(content_type='text/plain')
        generic.forget(response, request, 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 == ''

    assert sorted(response.headers.items()) == [
        ('Content-Length', '0'),
        ('Content-Type', 'text/plain; charset=UTF-8'),
        ('WWW-Authenticate', 'Basic realm="Realm"'),
        ]
开发者ID:reinout,项目名称:morepath,代码行数:34,代码来源:test_security.py


示例15: 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


示例16: 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


示例17: test_no_permission

def test_no_permission():
    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.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.status == '401 Unauthorized'
开发者ID:reinout,项目名称:morepath,代码行数:26,代码来源:test_security.py


示例18: test_mount_explicit_converters

def test_mount_explicit_converters():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class mounted(morepath.App):
        testing_config = config

        def __init__(self, id):
            self.id = id

    class MountedRoot(object):
        def __init__(self, id):
            self.id = id

    @mounted.path(path='', model=MountedRoot)
    def get_root(app):
        return MountedRoot(id=app.id)

    @mounted.view(model=MountedRoot)
    def root_default(self, request):
        return "The root for: %s %s" % (self.id, type(self.id))

    @app.mount(path='{id}', app=mounted, converters=dict(id=int))
    def get_context(id):
        return mounted(id=id)

    config.commit()

    c = Client(app())

    response = c.get('/1')
    assert response.body in \
        (b"The root for: 1 <type 'int'>", b"The root for: 1 <class 'int'>")
开发者ID:ryanfreckleton,项目名称:morepath,代码行数:35,代码来源:test_mount_directive.py


示例19: test_variable_path_parameter_required_with_default

def test_variable_path_parameter_required_with_default():
    config = setup()

    class 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 == b"View: a"

    response = c.get('/', status=400)
开发者ID:binbrain,项目名称:morepath,代码行数:30,代码来源:test_path_directive.py


示例20: test_script_name

def test_script_name():
    config = setup()

    class app(morepath.App):
        testing_config = config

    class Model(object):
        def __init__(self):
            pass

    @app.path(model=Model, path='simple')
    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('/prefix/simple',
                     extra_environ=dict(SCRIPT_NAME='/prefix'))
    assert response.body == b'View'

    response = c.get('/prefix/simple/link',
                     extra_environ=dict(SCRIPT_NAME='/prefix'))
    assert response.body == b'http://localhost/prefix/simple'
开发者ID:binbrain,项目名称:morepath,代码行数:33,代码来源:test_path_directive.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python app.App类代码示例发布时间:2022-05-27
下一篇:
Python morepath.redirect函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap