當前位置: 首頁>>代碼示例>>Python>>正文


Python app.test_client方法代碼示例

本文整理匯總了Python中blueprintapp.app.test_client方法的典型用法代碼示例。如果您正苦於以下問題:Python app.test_client方法的具體用法?Python app.test_client怎麽用?Python app.test_client使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在blueprintapp.app的用法示例。


在下文中一共展示了app.test_client方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_blueprint_url_definitions

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_blueprint_url_definitions(self):
        bp = flask.Blueprint('test', __name__)

        @bp.route('/foo', defaults={'baz': 42})
        def foo(bar, baz):
            return '%s/%d' % (bar, baz)

        @bp.route('/bar')
        def bar(bar):
            return text_type(bar)

        app = flask.Flask(__name__)
        app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})
        app.register_blueprint(bp, url_prefix='/2', url_defaults={'bar': 19})

        c = app.test_client()
        self.assert_equal(c.get('/1/foo').data, b'23/42')
        self.assert_equal(c.get('/2/foo').data, b'19/42')
        self.assert_equal(c.get('/1/bar').data, b'23')
        self.assert_equal(c.get('/2/bar').data, b'19') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:22,代碼來源:blueprints.py

示例2: test_dotted_names_from_app

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_dotted_names_from_app(self):
        app = flask.Flask(__name__)
        app.testing = True
        test = flask.Blueprint('test', __name__)

        @app.route('/')
        def app_index():
            return flask.url_for('test.index')

        @test.route('/test/')
        def index():
            return flask.url_for('app_index')

        app.register_blueprint(test)

        with app.test_client() as c:
            rv = c.get('/')
            self.assert_equal(rv.data, b'/test/') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:20,代碼來源:blueprints.py

示例3: test_basic_module

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_basic_module(self):
        app = flask.Flask(__name__)
        admin = flask.Module(__name__, 'admin', url_prefix='/admin')
        @admin.route('/')
        def admin_index():
            return 'admin index'
        @admin.route('/login')
        def admin_login():
            return 'admin login'
        @admin.route('/logout')
        def admin_logout():
            return 'admin logout'
        @app.route('/')
        def index():
            return 'the index'
        app.register_module(admin)
        c = app.test_client()
        self.assert_equal(c.get('/').data, b'the index')
        self.assert_equal(c.get('/admin/').data, b'admin index')
        self.assert_equal(c.get('/admin/login').data, b'admin login')
        self.assert_equal(c.get('/admin/logout').data, b'admin logout') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:23,代碼來源:blueprints.py

示例4: test_context_processors

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_context_processors(self):
        app = flask.Flask(__name__)
        admin = flask.Module(__name__, 'admin', url_prefix='/admin')
        @app.context_processor
        def inject_all_regular():
            return {'a': 1}
        @admin.context_processor
        def inject_admin():
            return {'b': 2}
        @admin.app_context_processor
        def inject_all_module():
            return {'c': 3}
        @app.route('/')
        def index():
            return flask.render_template_string('{{ a }}{{ b }}{{ c }}')
        @admin.route('/')
        def admin_index():
            return flask.render_template_string('{{ a }}{{ b }}{{ c }}')
        app.register_module(admin)
        c = app.test_client()
        self.assert_equal(c.get('/').data, b'13')
        self.assert_equal(c.get('/admin/').data, b'123') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:24,代碼來源:blueprints.py

示例5: test_endpoint_decorator

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_endpoint_decorator(self):
        from werkzeug.routing import Submount, Rule
        from flask import Module

        app = flask.Flask(__name__)
        app.testing = True
        app.url_map.add(Submount('/foo', [
            Rule('/bar', endpoint='bar'),
            Rule('/', endpoint='index')
        ]))
        module = Module(__name__, __name__)

        @module.endpoint('bar')
        def bar():
            return 'bar'

        @module.endpoint('index')
        def index():
            return 'index'

        app.register_module(module)

        c = app.test_client()
        self.assert_equal(c.get('/foo/').data, b'index')
        self.assert_equal(c.get('/foo/bar').data, b'bar') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:27,代碼來源:blueprints.py

示例6: test_dotted_names

# 需要導入模塊: from blueprintapp import app [as 別名]
# 或者: from blueprintapp.app import test_client [as 別名]
def test_dotted_names(self):
        frontend = flask.Blueprint('myapp.frontend', __name__)
        backend = flask.Blueprint('myapp.backend', __name__)

        @frontend.route('/fe')
        def frontend_index():
            return flask.url_for('myapp.backend.backend_index')

        @frontend.route('/fe2')
        def frontend_page2():
            return flask.url_for('.frontend_index')

        @backend.route('/be')
        def backend_index():
            return flask.url_for('myapp.frontend.frontend_index')

        app = flask.Flask(__name__)
        app.register_blueprint(frontend)
        app.register_blueprint(backend)

        c = app.test_client()
        self.assert_equal(c.get('/fe').data.strip(), b'/be')
        self.assert_equal(c.get('/fe2').data.strip(), b'/fe')
        self.assert_equal(c.get('/be').data.strip(), b'/fe') 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:26,代碼來源:blueprints.py


注:本文中的blueprintapp.app.test_client方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。