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

Python shake.Shake类代码示例

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

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



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

示例1: test_default_error

def test_default_error():
    app = Shake(__file__)
    app.add_url('/', fail)
    
    c = app.test_client()
    with pytest.raises(AssertionError):
        c.get('/')
开发者ID:nbpalomino,项目名称:Shake,代码行数:7,代码来源:test_app.py


示例2: test_fallback_error_code

def test_fallback_error_code():
    errors = {
        400: BadRequest,
        401: Unauthorized,
        403: Forbidden,
        404: NotFound,
        405: MethodNotAllowed,
        406: NotAcceptable,
        408: RequestTimeout,
        410: Gone,
        411: LengthRequired,
        412: PreconditionFailed,
        413: RequestEntityTooLarge,
        414: RequestURITooLarge,
        415: UnsupportedMediaType,
        500: InternalServerError,
        501: NotImplemented,
        502: BadGateway,
        503: ServiceUnavailable,
    }
    settings = {'PAGE_ERROR': error, 'DEBUG': False}
    app = Shake(__file__, settings)

    @app.route('/<int:code>/')
    def index(request, code):
        print code
        raise errors[code]

    c = app.test_client()
    for code in errors:
        if code in app.error_handlers:
            continue
        resp = c.get('/%i/' % code)
        assert resp.status_code == code
        assert resp.data == 'error'
开发者ID:nbpalomino,项目名称:Shake,代码行数:35,代码来源:test_app.py


示例3: test_url_for

def test_url_for():
    app = Shake(__file__)
    c = app.test_client()

    def index(request):
        expected = '/hello/world/'
        url = url_for(endpoint, name='world')
        assert url == expected

        expected = 'http://0.0.0.0:5000/hello/world/'
        url = url_for(endpoint, name='world', external=True)
        assert url == expected

        expected = '/hello/world/#awesome'
        url = url_for(endpoint, name='world', anchor='awesome')
        assert url == expected

        expected = 'http://0.0.0.0:5000/hello/world/#awesome'
        url = url_for(endpoint, name='world', anchor='awesome', external=True)
        assert url == expected

    app.add_urls([
        Rule('/', index),
        Rule('/hello/<name>/', endpoint),
    ])

    c.get('/')
开发者ID:ttym7993,项目名称:Shake,代码行数:27,代码来源:test_helpers.py


示例4: test_processors_order

def test_processors_order():
    app = Shake(__file__)
    r = []
    
    @app.route('/')
    def index(request):
        r.append('view')
    
    @app.before_request
    def br1(request):
        r.append('br1')
    
    @app.before_request
    def br2(request):
        r.append('br2')
    
    @app.after_request
    def ar1(response):
        r.append('ar1')
        return response
    
    @app.after_request
    def ar2(response):
        r.append('ar2')
        return response
    
    @app.on_exception
    def error(e):
        r.append('error')
    
    c = app.test_client()
    c.get('/')
    assert r == 'br1 br2 view ar1 ar2'.split()
开发者ID:nbpalomino,项目名称:Shake,代码行数:33,代码来源:test_app.py


示例5: test_send_file_attachment

def test_send_file_attachment():
    app = Shake(__file__)
    c = app.test_client()

    @app.route('/')
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html',
                as_attachment=True)
            cd_header = resp.headers['Content-Disposition']
            value, options = parse_options_header(cd_header)
            assert value == 'attachment'

        resp = send_file(request, filename, as_attachment=True)
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'index.html'

        f = StringIO('Test')
        resp = send_file(request, f, attachment_filename='readme.txt',
            as_attachment=True)
        assert resp.mimetype == 'text/plain'
        cd_header = resp.headers['Content-Disposition']
        value, options = parse_options_header(cd_header)
        assert value == 'attachment'
        assert options['filename'] == 'readme.txt'

    c.get('/')
开发者ID:ttym7993,项目名称:Shake,代码行数:31,代码来源:test_helpers.py


示例6: test_flash_messagesech

def test_flash_messagesech():
    
    def t1(request):
        msgs = get_messages()
        assert msgs == []
    
    def t2(request):
        flash(request, 'foo')
        flash(request, 'bar', 'error', extra='blub')
        msgs = get_messages()
        assert len(msgs) == 2
        assert (msgs[0]['msg'], msgs[0]['cat'], msgs[0]['extra']) == \
            ('foo', 'info', None)
        assert (msgs[1]['msg'], msgs[1]['cat'], msgs[1]['extra']) == \
            ('bar', 'error', 'blub')
        msgs2 = get_messages()
        assert msgs2 == msgs
    
    urls = [
        Rule('/t1', t1),
        Rule('/t2', t2),
        ]
    settings = {'SECRET_KEY': 'abc'*20}
    app = Shake(urls, settings)
    c = app.test_client()
    c.get('/t1')
    c.get('/t2')
开发者ID:ccarruitero,项目名称:Shake,代码行数:27,代码来源:test_views.py


示例7: test_i18n

def test_i18n():
    render = Render(i18n=views_dir)
    
    def ok(request):
        return render.from_string('{{ i18n.HELLO }}')
    
    def fail(request):
        return render.from_string('{{ i18n.FOOBAR }}')
    
    urls = [
        Rule('/ok/', ok),
        Rule('/fail/', fail),
    ]
    app = Shake(urls)
    c = app.test_client()

    resp = c.get('/ok/?lang=en-US')
    assert resp.status_code == HTTP_OK
    assert resp.data == 'Hello World'

    resp = c.get('/ok/?lang=en_US')
    assert resp.status_code == HTTP_OK
    assert resp.data == 'Hello World'

    resp = c.get('/ok/?lang=es-AR')
    assert resp.data == 'Hola mundo'

    resp = c.get('/fail/?lang=en-US')
    assert resp.data == ''
开发者ID:ccarruitero,项目名称:Shake,代码行数:29,代码来源:test_views.py


示例8: test_url_for

def test_url_for():
    
    def index(request):
        expected = '/hello/world/'
        url = url_for(endpoint, name='world')
        assert url == expected

        expected = 'http://localhost/hello/world/'
        url = url_for(endpoint, name='world', external=True)
        assert url == expected

        expected = '/hello/world/#awesome'
        url = url_for(endpoint, name='world', anchor='awesome')
        assert url == expected

        expected = 'http://localhost/hello/world/#awesome'
        url = url_for(endpoint, name='world', anchor='awesome', external=True)
        assert url == expected
    
    urls = [
        Rule('/', index),
        Rule('/hello/<name>/', endpoint),
        ]
    app = Shake(urls)
    c = app.test_client()
    resp = c.get('/')
开发者ID:ccarruitero,项目名称:Shake,代码行数:26,代码来源:test_helpers.py


示例9: test_send_file_object

def test_send_file_object():
    app = Shake(__file__)
    c = app.test_client()

    @app.route('/')
    def index(request):
        filename = path_join(__file__, 'static/index.html')

        with io.open(filename) as f:
            with pytest.raises(AssertionError):
                resp = send_file(request, f)

        with io.open(filename) as f:
            resp = send_file(request, f, mimetype='text/html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'

        with io.open(filename) as f:
            resp = send_file(request, f, attachment_filename='foo.html')
            assert resp.direct_passthrough
            assert resp.mimetype == 'text/html'

        f = StringIO('Test')
        resp = send_file(request, f, attachment_filename='test')
        assert resp.mimetype == 'application/octet-stream'

        f = StringIO('Test')
        resp = send_file(request, f, mimetype='text/plain')
        assert resp.mimetype == 'text/plain'

    c.get('/')
开发者ID:ttym7993,项目名称:Shake,代码行数:31,代码来源:test_helpers.py


示例10: test_default_not_found

def test_default_not_found():
    app = Shake(__file__)
    app.add_url('/', index)
    
    c = app.test_client()
    resp = c.get('/bla')
    assert resp.status_code == HTTP_NOT_FOUND
    assert '<title>Page not found</title>' in resp.data
开发者ID:nbpalomino,项目名称:Shake,代码行数:8,代码来源:test_app.py


示例11: test_string_endpoint

def test_string_endpoint():
    app = Shake(__file__)
    app.add_url('/', 'tests.test_app.index')

    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_OK
    assert resp.data == 'hello'
开发者ID:nbpalomino,项目名称:Shake,代码行数:8,代码来源:test_app.py


示例12: test_callable_endpoint

def test_callable_endpoint():
    app = Shake(__file__)
    app.add_url('/', index)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_OK
    assert resp.data == 'hello'
开发者ID:nbpalomino,项目名称:Shake,代码行数:8,代码来源:test_app.py


示例13: test_default_not_allowed

def test_default_not_allowed():
    app = Shake(__file__)
    app.add_url('/', no_pass)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_FORBIDDEN
    assert '<title>Access Denied</title>' in resp.data
开发者ID:nbpalomino,项目名称:Shake,代码行数:8,代码来源:test_app.py


示例14: test_render_template_view

def test_render_template_view():
    app = Shake(__file__)
    c = app.test_client()
    app.add_url('/', render_template, 
        defaults={'template': 'tmpl.html', 'render': render})
    
    resp = c.get('/')
    assert resp.data == '<h1>Hello World</h1>'
    assert resp.mimetype == 'text/html'
开发者ID:nbpalomino,项目名称:Shake,代码行数:9,代码来源:test_views.py


示例15: test_default_error

def test_default_error():
    urls = [
        Rule('/', fail),
        ]
    app = Shake(urls)
    
    c = app.test_client()
    with pytest.raises(AssertionError):
        c.get('/')
开发者ID:ccarruitero,项目名称:Shake,代码行数:9,代码来源:test_app.py


示例16: test_custom_not_found

def test_custom_not_found():
    settings = {'PAGE_NOT_FOUND': not_found, 'DEBUG': True}
    app = Shake(__file__, settings)
    app.add_url('/', index)
    
    c = app.test_client()
    resp = c.get('/bla')
    assert resp.status_code == HTTP_NOT_FOUND
    assert resp.data == 'not found'
开发者ID:nbpalomino,项目名称:Shake,代码行数:9,代码来源:test_app.py


示例17: test_custom_error

def test_custom_error():
    settings = {'PAGE_ERROR': error, 'DEBUG': False}
    app = Shake(__file__, settings)
    app.add_url('/', fail)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_ERROR
    assert resp.data == 'error'
开发者ID:nbpalomino,项目名称:Shake,代码行数:9,代码来源:test_app.py


示例18: test_custom_not_allowed

def test_custom_not_allowed():
    settings = {'PAGE_NOT_ALLOWED': not_allowed}
    app = Shake(__file__, settings)
    app.add_url('/', no_pass)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_FORBIDDEN
    assert resp.data == 'access denied'
开发者ID:nbpalomino,项目名称:Shake,代码行数:9,代码来源:test_app.py


示例19: test_callable_endpoint

def test_callable_endpoint():
    urls = [
        Rule('/', index),
        ]
    app = Shake(urls)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_OK
    assert resp.data == 'hello'
开发者ID:ccarruitero,项目名称:Shake,代码行数:10,代码来源:test_app.py


示例20: test_default_not_allowed

def test_default_not_allowed():
    urls = [
        Rule('/', no_pass),
        ]
    app = Shake(urls)
    
    c = app.test_client()
    resp = c.get('/')
    assert resp.status_code == HTTP_FORBIDDEN
    assert '<title>Access Denied</title>' in resp.data
开发者ID:ccarruitero,项目名称:Shake,代码行数:10,代码来源:test_app.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shake_event.ShakeEvent类代码示例发布时间:2022-05-27
下一篇:
Python shakaBuildHelpers.get_source_base函数代码示例发布时间: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