本文整理汇总了Python中api.create_app方法的典型用法代码示例。如果您正苦于以下问题:Python api.create_app方法的具体用法?Python api.create_app怎么用?Python api.create_app使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api
的用法示例。
在下文中一共展示了api.create_app方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: client
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def client(postgres):
config_dict = {
"SQLALCHEMY_DATABASE_URI": postgres.url(),
"DEBUG": True,
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
}
app = create_app(config_dict)
app.app_context().push()
time.sleep(2)
from api.models import db
db.create_all()
# for test client api reference
# http://flask.pocoo.org/docs/1.0/api/#test-client
client = app.test_client()
yield client
示例2: main
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def main():
"""Parse web API startup flags."""
parser = ArgumentParser(description="CTF API configuration")
parser.add_argument(
"-p",
"--port",
action="store",
help="port the server should listen on.",
type=int,
default=8000,
)
parser.add_argument(
"-l",
"--listen",
action="store",
help="host the server should listen on.",
default="0.0.0.0",
)
parser.add_argument(
"-d",
"--debug",
action="store_true",
help="run the server in debug mode.",
default=False,
)
parser.add_argument(
"-k",
"--debug-key",
action="store",
help="debug key for problem grading; only applies if debug is enabled",
type=str,
default=None,
)
args = parser.parse_args()
if args.debug:
api.submissions.DEBUG_KEY = args.debug_key
api.create_app().run(
host=args.listen, port=args.port, debug=args.debug,
)
示例3: client
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def client():
"""Create a test client of the Flask app."""
app = api.create_app(
{
"TESTING": True,
"MONGO_DB_NAME": TESTING_DB_NAME,
"MONGO_PORT": 27018,
"RATE_LIMIT_BYPASS_KEY": RATE_LIMIT_BYPASS_KEY,
}
)
return app.test_client()
示例4: app
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def app():
"""Create an instance of the Flask app for testing."""
app = api.create_app(
{"TESTING": True, "MONGO_DB_NAME": TESTING_DB_NAME, "MONGO_PORT": 27018}
)
return app
示例5: initialize_test_client
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def initialize_test_client(self):
from api import create_app
self.app = create_app(testing=True)
self.app_context = self.app.test_request_context()
self.app_context.push()
self.client = self.app.test_client()
# Hopefully temporary hack to ensure session is cleared after each test
import api
api.db.session.close()
示例6: execute_api_server
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def execute_api_server(self, listen_address=None, listen_port=None, ssl_cert=None, ssl_key=None):
# https://gist.github.com/rduplain/1705072
# this is a bit weird because I want the urls to be the same as they
# are configured for apache, where they are all starting with /api
import api
from saq.database import initialize_database
app = api.create_app(testing=True)
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
from flask import Flask
app.config['DEBUG'] = True
app.config['APPLICATION_ROOT'] = '/api'
application = DispatcherMiddleware(Flask('dummy_app'), {
app.config['APPLICATION_ROOT']: app,
})
if listen_address is None:
listen_address = saq.CONFIG.get('api', 'listen_address')
if listen_port is None:
listen_port = saq.CONFIG.getint('api', 'listen_port')
ssl_context = (
saq.CONFIG.get('api', 'ssl_cert') if ssl_cert is None else ssl_cert,
saq.CONFIG.get('api', 'ssl_key') if ssl_key is None else ssl_key )
initialize_database()
saq.db = api.db.session
logging.info(f"starting api server on {listen_address} port {listen_port}")
run_simple(listen_address, listen_port, application, ssl_context=ssl_context, use_reloader=False)
示例7: app
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def app():
APP_CONFIG.update({'TESTING': True})
app = create_app(APP_CONFIG)
yield app
示例8: setUp
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def setUp(self):
self.app = create_app(environment="Testing")
示例9: run
# 需要导入模块: import api [as 别名]
# 或者: from api import create_app [as 别名]
def run():
"""Run the stat caching daemon."""
with api.create_app().app_context():
def cache(f, *args, **kwargs):
result = f(reset_cache=True, *args, **kwargs)
return result
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
host = s.getsockname()[0]
s.close()
_cache = api.cache.get_cache()
active_stat_host = _cache.get("active_stat_host")
if active_stat_host is not None and host != active_stat_host:
print("Another ctf-stats is primary, exiting...")
raise SystemExit
else:
_cache.set("active_stat_host", host, COOLDOWN_TIME)
print("Caching registration stats...")
cache(get_registration_count)
print("Caching the scoreboards...")
for scoreboard in api.scoreboards.get_all_scoreboards():
get_all_team_scores(scoreboard_id=scoreboard["sid"])
print("Caching the score progressions for each scoreboard...")
for scoreboard in api.scoreboards.get_all_scoreboards():
cache(
get_top_teams_score_progressions,
limit=5,
scoreboard_id=scoreboard["sid"],
)
print("Caching the scores and score progressions for each group...")
for group in api.group.get_all_groups():
get_group_scores(gid=group["gid"])
cache(get_top_teams_score_progressions, limit=5, group_id=group["gid"])
print("Caching number of solves for each problem...")
for problem in api.problem.get_all_problems():
print(problem["name"], cache(get_problem_solves, problem["pid"]))