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

Python app.test_request_context函数代码示例

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

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



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

示例1: test_attachment

    def test_attachment(self):
        app = flask.Flask(__name__)
        with catch_warnings() as captured:
            with app.test_request_context():
                f = open(os.path.join(app.root_path, 'static/index.html'))
                rv = flask.send_file(f, as_attachment=True)
                value, options = parse_options_header(rv.headers['Content-Disposition'])
                assert value == 'attachment'
            # mimetypes + etag
            assert len(captured) == 2

        with app.test_request_context():
            assert options['filename'] == 'index.html'
            rv = flask.send_file('static/index.html', as_attachment=True)
            value, options = parse_options_header(rv.headers['Content-Disposition'])
            assert value == 'attachment'
            assert options['filename'] == 'index.html'

        with app.test_request_context():
            rv = flask.send_file(StringIO('Test'), as_attachment=True,
                                 attachment_filename='index.txt',
                                 add_etags=False)
            assert rv.mimetype == 'text/plain'
            value, options = parse_options_header(rv.headers['Content-Disposition'])
            assert value == 'attachment'
            assert options['filename'] == 'index.txt'
开发者ID:dharmeshpatel,项目名称:flask,代码行数:26,代码来源:flask_tests.py


示例2: test_templates_and_static

    def test_templates_and_static(self):
        from moduleapp import app
        c = app.test_client()

        rv = c.get('/')
        assert rv.data == 'Hello from the Frontend'
        rv = c.get('/admin/')
        assert rv.data == 'Hello from the Admin'
        rv = c.get('/admin/index2')
        assert rv.data == 'Hello from the Admin'
        rv = c.get('/admin/static/test.txt')
        assert rv.data.strip() == 'Admin File'
        rv = c.get('/admin/static/css/test.css')
        assert rv.data.strip() == '/* nested file */'

        with app.test_request_context():
            assert flask.url_for('admin.static', filename='test.txt') \
                == '/admin/static/test.txt'

        with app.test_request_context():
            try:
                flask.render_template('missing.html')
            except TemplateNotFound, e:
                assert e.name == 'missing.html'
            else:
开发者ID:dharmeshpatel,项目名称:flask,代码行数:25,代码来源:flask_tests.py


示例3: test_templates_and_static

    def test_templates_and_static(self):
        from moduleapp import app

        c = app.test_client()

        rv = c.get("/")
        assert rv.data == "Hello from the Frontend"
        rv = c.get("/admin/")
        assert rv.data == "Hello from the Admin"
        rv = c.get("/admin/index2")
        assert rv.data == "Hello from the Admin"
        rv = c.get("/admin/static/test.txt")
        assert rv.data.strip() == "Admin File"
        rv = c.get("/admin/static/css/test.css")
        assert rv.data.strip() == "/* nested file */"

        with app.test_request_context():
            assert flask.url_for("admin.static", filename="test.txt") == "/admin/static/test.txt"

        with app.test_request_context():
            try:
                flask.render_template("missing.html")
            except TemplateNotFound, e:
                assert e.name == "missing.html"
            else:
开发者ID:smalls,项目名称:flask,代码行数:25,代码来源:flask_tests.py


示例4: test_send_file_object

    def test_send_file_object(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            f = open(os.path.join(app.root_path, 'static/index.html'))
            rv = flask.send_file(f)
            with app.open_resource('static/index.html') as f:
                assert rv.data == f.read()
            assert rv.mimetype == 'text/html'

        app.use_x_sendfile = True
        with app.test_request_context():
            f = open(os.path.join(app.root_path, 'static/index.html'))
            rv = flask.send_file(f)
            assert rv.mimetype == 'text/html'
            assert 'x-sendfile' in rv.headers
            assert rv.headers['x-sendfile'] == \
                os.path.join(app.root_path, 'static/index.html')

        app.use_x_sendfile = False
        with app.test_request_context():
            f = StringIO('Test')
            rv = flask.send_file(f)
            assert rv.data == 'Test'
            assert rv.mimetype == 'application/octet-stream'
            f = StringIO('Test')
            rv = flask.send_file(f, mimetype='text/plain')
            assert rv.data == 'Test'
            assert rv.mimetype == 'text/plain'

        app.use_x_sendfile = True
        with app.test_request_context():
            f = StringIO('Test')
            rv = flask.send_file(f)
            assert 'x-sendfile' not in rv.headers
开发者ID:hm1021,项目名称:webbattle,代码行数:34,代码来源:flask_tests.py


示例5: test_send_file_object

    def test_send_file_object(self):
        app = flask.Flask(__name__)
        with catch_warnings() as captured:
            with app.test_request_context():
                f = open(os.path.join(app.root_path, "static/index.html"))
                rv = flask.send_file(f)
                with app.open_resource("static/index.html") as f:
                    assert rv.data == f.read()
                assert rv.mimetype == "text/html"
            # mimetypes + etag
            assert len(captured) == 2

        app.use_x_sendfile = True
        with catch_warnings() as captured:
            with app.test_request_context():
                f = open(os.path.join(app.root_path, "static/index.html"))
                rv = flask.send_file(f)
                assert rv.mimetype == "text/html"
                assert "x-sendfile" in rv.headers
                assert rv.headers["x-sendfile"] == os.path.join(app.root_path, "static/index.html")
            # mimetypes + etag
            assert len(captured) == 2

        app.use_x_sendfile = False
        with app.test_request_context():
            with catch_warnings() as captured:
                f = StringIO("Test")
                rv = flask.send_file(f)
                assert rv.data == "Test"
                assert rv.mimetype == "application/octet-stream"
            # etags
            assert len(captured) == 1
            with catch_warnings() as captured:
                f = StringIO("Test")
                rv = flask.send_file(f, mimetype="text/plain")
                assert rv.data == "Test"
                assert rv.mimetype == "text/plain"
            # etags
            assert len(captured) == 1

        app.use_x_sendfile = True
        with catch_warnings() as captured:
            with app.test_request_context():
                f = StringIO("Test")
                rv = flask.send_file(f)
                assert "x-sendfile" not in rv.headers
            # etags
            assert len(captured) == 1
开发者ID:smalls,项目名称:flask,代码行数:48,代码来源:flask_tests.py


示例6: test_safe_access

    def test_safe_access(self):
        from moduleapp import app

        with app.test_request_context():
            f = app.view_functions["admin.static"]

            try:
                f("/etc/passwd")
            except NotFound:
                pass
            else:
                assert 0, "expected exception"
            try:
                f("../__init__.py")
            except NotFound:
                pass
            else:
                assert 0, "expected exception"

            # testcase for a security issue that may exist on windows systems
            import os
            import ntpath

            old_path = os.path
            os.path = ntpath
            try:
                try:
                    f("..\\__init__.py")
                except NotFound:
                    pass
                else:
                    assert 0, "expected exception"
            finally:
                os.path = old_path
开发者ID:smalls,项目名称:flask,代码行数:34,代码来源:flask_tests.py


示例7: test_send_file_regular

 def test_send_file_regular(self):
     app = flask.Flask(__name__)
     with app.test_request_context():
         rv = flask.send_file('static/index.html')
         assert rv.direct_passthrough
         assert rv.mimetype == 'text/html'
         with app.open_resource('static/index.html') as f:
             assert rv.data == f.read()
开发者ID:dharmeshpatel,项目名称:flask,代码行数:8,代码来源:flask_tests.py


示例8: test_send_file_xsendfile

 def test_send_file_xsendfile(self):
     app = flask.Flask(__name__)
     app.use_x_sendfile = True
     with app.test_request_context():
         rv = flask.send_file("static/index.html")
         assert rv.direct_passthrough
         assert "x-sendfile" in rv.headers
         assert rv.headers["x-sendfile"] == os.path.join(app.root_path, "static/index.html")
         assert rv.mimetype == "text/html"
开发者ID:smalls,项目名称:flask,代码行数:9,代码来源:flask_tests.py


示例9: test_send_file_xsendfile

 def test_send_file_xsendfile(self):
     app = flask.Flask(__name__)
     app.use_x_sendfile = True
     with app.test_request_context():
         rv = flask.send_file('static/index.html')
         assert rv.direct_passthrough
         assert 'x-sendfile' in rv.headers
         assert rv.headers['x-sendfile'] == \
             os.path.join(app.root_path, 'static/index.html')
         assert rv.mimetype == 'text/html'
开发者ID:dharmeshpatel,项目名称:flask,代码行数:10,代码来源:flask_tests.py


示例10: test_static_path_without_url_prefix

 def test_static_path_without_url_prefix(self):
     app = flask.Flask(__name__)
     app.config['SERVER_NAME'] = 'example.com'
     from testmodule import mod
     app.register_module(mod)
     c = app.test_client()
     f = 'hello.txt'
     rv = c.get('/static/' + f, 'http://example.com/')
     assert rv.data.strip() == 'Hello Maindomain'
     with app.test_request_context(base_url='http://example.com'):
         assert flask.url_for('static', filename=f) == '/static/' + f
         assert flask.url_for('static', filename=f, _external=True) \
             == 'http://example.com/static/' + f
开发者ID:sublee,项目名称:flask,代码行数:13,代码来源:flask_tests.py


示例11: test_attachment

    def test_attachment(self):
        app = flask.Flask(__name__)
        with catch_warnings() as captured:
            with app.test_request_context():
                f = open(os.path.join(app.root_path, "static/index.html"))
                rv = flask.send_file(f, as_attachment=True)
                value, options = parse_options_header(rv.headers["Content-Disposition"])
                assert value == "attachment"
            # mimetypes + etag
            assert len(captured) == 2

        with app.test_request_context():
            assert options["filename"] == "index.html"
            rv = flask.send_file("static/index.html", as_attachment=True)
            value, options = parse_options_header(rv.headers["Content-Disposition"])
            assert value == "attachment"
            assert options["filename"] == "index.html"

        with app.test_request_context():
            rv = flask.send_file(StringIO("Test"), as_attachment=True, attachment_filename="index.txt", add_etags=False)
            assert rv.mimetype == "text/plain"
            value, options = parse_options_header(rv.headers["Content-Disposition"])
            assert value == "attachment"
            assert options["filename"] == "index.txt"
开发者ID:smalls,项目名称:flask,代码行数:24,代码来源:flask_tests.py


示例12: test_safe_access

    def test_safe_access(self):
        from moduleapp import app

        with app.test_request_context():
            f = app.view_functions['admin.static']

            try:
                f('/etc/passwd')
            except NotFound:
                pass
            else:
                assert 0, 'expected exception'
            try:
                f('../__init__.py')
            except NotFound:
                pass
            else:
                assert 0, 'expected exception'
开发者ID:dharmeshpatel,项目名称:flask,代码行数:18,代码来源:flask_tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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