当前位置: 首页>>代码示例>>Python>>正文


Python app.test_request_context方法代码示例

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


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

示例1: test_default_static_cache_timeout

# 需要导入模块: from blueprintapp import app [as 别名]
# 或者: from blueprintapp.app import test_request_context [as 别名]
def test_default_static_cache_timeout(self):
        app = flask.Flask(__name__)
        class MyBlueprint(flask.Blueprint):
            def get_send_file_max_age(self, filename):
                return 100

        blueprint = MyBlueprint('blueprint', __name__, static_folder='static')
        app.register_blueprint(blueprint)

        # try/finally, in case other tests use this app for Blueprint tests.
        max_age_default = app.config['SEND_FILE_MAX_AGE_DEFAULT']
        try:
            with app.test_request_context():
                unexpected_max_age = 3600
                if app.config['SEND_FILE_MAX_AGE_DEFAULT'] == unexpected_max_age:
                    unexpected_max_age = 7200
                app.config['SEND_FILE_MAX_AGE_DEFAULT'] = unexpected_max_age
                rv = blueprint.send_static_file('index.html')
                cc = parse_cache_control_header(rv.headers['Cache-Control'])
                self.assert_equal(cc.max_age, 100)
                rv.close()
        finally:
            app.config['SEND_FILE_MAX_AGE_DEFAULT'] = max_age_default 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:25,代码来源:blueprints.py

示例2: test_default_endpoint_name

# 需要导入模块: from blueprintapp import app [as 别名]
# 或者: from blueprintapp.app import test_request_context [as 别名]
def test_default_endpoint_name(self):
        app = flask.Flask(__name__)
        mod = flask.Module(__name__, 'frontend')
        def index():
            return 'Awesome'
        mod.add_url_rule('/', view_func=index)
        app.register_module(mod)
        rv = app.test_client().get('/')
        self.assert_equal(rv.data, b'Awesome')
        with app.test_request_context():
            self.assert_equal(flask.url_for('frontend.index'), '/') 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:13,代码来源:blueprints.py

示例3: test_templates_and_static

# 需要导入模块: from blueprintapp import app [as 别名]
# 或者: from blueprintapp.app import test_request_context [as 别名]
def test_templates_and_static(self):
        app = moduleapp
        app.testing = True
        c = app.test_client()

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

        with app.test_request_context():
            self.assert_equal(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 as e:
                self.assert_equal(e.name, 'missing.html')
            else:
                self.assert_true(0, 'expected exception')

        with flask.Flask(__name__).test_request_context():
            self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested') 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:34,代码来源:blueprints.py

示例4: test_safe_access

# 需要导入模块: from blueprintapp import app [as 别名]
# 或者: from blueprintapp.app import test_request_context [as 别名]
def test_safe_access(self):
        app = moduleapp

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

            try:
                f('/etc/passwd')
            except NotFound:
                pass
            else:
                self.assert_true(0, 'expected exception')
            try:
                f('../__init__.py')
            except NotFound:
                pass
            else:
                self.assert_true(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:
                    self.assert_true(0, 'expected exception')
            finally:
                os.path = old_path 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:35,代码来源:blueprints.py


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