本文整理汇总了Python中flask_restless.APIManager.init_app方法的典型用法代码示例。如果您正苦于以下问题:Python APIManager.init_app方法的具体用法?Python APIManager.init_app怎么用?Python APIManager.init_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_restless.APIManager
的用法示例。
在下文中一共展示了APIManager.init_app方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_app
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_init_app(self):
self.db.create_all()
manager = APIManager(flask_sqlalchemy_db=self.db)
manager.create_api(self.Person)
manager.init_app(self.flaskapp)
response = self.app.get('/api/person')
assert response.status_code == 200
示例2: test_multiple_managers_init_multiple_apps
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_multiple_managers_init_multiple_apps(self):
"""Tests for calling :meth:`~APIManager.init_app` on multiple
:class:`~flask.Flask` applications after calling
:meth:`~APIManager.create_api` on multiple instances of
:class:`APIManager`.
"""
manager1 = APIManager(session=self.session)
manager2 = APIManager(session=self.session)
# Create the Flask applications and the test clients.
flaskapp1 = self.flaskapp
flaskapp2 = Flask(__name__)
testclient1 = self.app
testclient2 = flaskapp2.test_client()
force_content_type_jsonapi(testclient2)
# First create the API, then initialize the Flask applications after.
manager1.create_api(self.Person)
manager2.create_api(self.Article)
manager1.init_app(flaskapp1)
manager2.init_app(flaskapp2)
# Tests that only the first Flask application gets requests for
# /api/person and only the second gets requests for /api/article.
response = testclient1.get('/api/person')
assert response.status_code == 200
response = testclient1.get('/api/article')
assert response.status_code == 404
response = testclient2.get('/api/person')
assert response.status_code == 404
response = testclient2.get('/api/article')
assert response.status_code == 200
示例3: test_single_manager_init_single_app
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_single_manager_init_single_app(self):
"""Tests for calling :meth:`~APIManager.init_app` with a single
:class:`~flask.Flask` application after calling
:meth:`~APIManager.create_api`.
"""
manager = APIManager(session=self.session)
manager.create_api(self.Person)
manager.init_app(self.flaskapp)
response = self.app.get('/api/person')
assert response.status_code == 200
示例4: test_schema_init_app
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_schema_init_app(self):
manager = APIManager(session=self.session)
manager.create_api(self.Article)
manager.create_api(self.Person)
manager.init_app(self.flaskapp)
response = self.app.get('/api')
self.assertEqual(response.status_code, 200)
document = loads(response.data)
info = document['meta']['modelinfo']
self.assertEqual(sorted(info), ['article', 'person'])
self.assertTrue(info['article']['url'].endswith('/api/article'))
self.assertTrue(info['person']['url'].endswith('/api/person'))
示例5: test_single_manager_init_multiple_apps
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_single_manager_init_multiple_apps(self):
"""Tests for calling :meth:`~APIManager.init_app` on multiple
:class:`~flask.Flask` applications after calling
:meth:`~APIManager.create_api`.
"""
manager = APIManager(session=self.session)
flaskapp1 = self.flaskapp
flaskapp2 = Flask(__name__)
testclient1 = self.app
testclient2 = flaskapp2.test_client()
force_content_type_jsonapi(testclient2)
manager.create_api(self.Person)
manager.init_app(flaskapp1)
manager.init_app(flaskapp2)
response = testclient1.get('/api/person')
assert response.status_code == 200
response = testclient2.get('/api/person')
assert response.status_code == 200
示例6: test_multiple_managers_init_single_app
# 需要导入模块: from flask_restless import APIManager [as 别名]
# 或者: from flask_restless.APIManager import init_app [as 别名]
def test_multiple_managers_init_single_app(self):
"""Tests for calling :meth:`~APIManager.init_app` on a single
:class:`~flask.Flask` application after calling
:meth:`~APIManager.create_api` on multiple instances of
:class:`APIManager`.
"""
manager1 = APIManager(session=self.session)
manager2 = APIManager(session=self.session)
# First create the API, then initialize the Flask applications after.
manager1.create_api(self.Person)
manager2.create_api(self.Article)
manager1.init_app(self.flaskapp)
manager2.init_app(self.flaskapp)
# Tests that both endpoints are accessible on the Flask application.
response = self.app.get('/api/person')
assert response.status_code == 200
response = self.app.get('/api/article')
assert response.status_code == 200