Python api.create_app() Examples
The following are 10
code examples of api.create_app().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
api
, or try the search function
.
Example #1
Source File: conftest.py From flask-boilerplate with MIT License | 6 votes |
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
Example #2
Source File: run.py From picoCTF with MIT License | 5 votes |
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, )
Example #3
Source File: common.py From picoCTF with MIT License | 5 votes |
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()
Example #4
Source File: common.py From picoCTF with MIT License | 5 votes |
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
Example #5
Source File: test.py From ACE with Apache License 2.0 | 5 votes |
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()
Example #6
Source File: test.py From ACE with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: conftest.py From age-of-empires-II-api with BSD 3-Clause "New" or "Revised" License | 5 votes |
def app(): APP_CONFIG.update({'TESTING': True}) app = create_app(APP_CONFIG) yield app
Example #8
Source File: test_api_v2.py From flask-restful-example with MIT License | 5 votes |
def setUp(self): self.app = create_app(environment="Testing")
Example #9
Source File: test_api_v1.py From flask-restful-example with MIT License | 5 votes |
def setUp(self): self.app = create_app(environment="Testing")
Example #10
Source File: cache_stats.py From picoCTF with MIT License | 4 votes |
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"]))