def app_module(): db_fd = db_path = None app = create_app( environment='test', ) # Choose tests database if app.config['SQLALCHEMY_DATABASE_URI'] == 'sqlite://': db_fd, db_path = tempfile.mkstemp() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{}.db'.format(db_path) with app.app_context(): db.create_all() app.response_class = DepcResponse app.test_client_class = DepcTestClient yield app with app.app_context(): db.drop_all() if db_fd and db_path: os.close(db_fd) os.unlink(db_path) return app_module
from flask_script import Shell, Manager from flask_script.commands import ShowUrls from flask_migrate import MigrateCommand from depc import create_app from depc.commands.getconfig import GetConfig from depc.commands.key import key_manager # Disable insecure warnings import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # Create an application using the `api` context app = create_app(environment=os.getenv('DEPC_ENV') or 'dev', ) manager = Manager(app) @manager.shell def make_shell_context(): return dict(app=app) manager.add_command('shell', Shell(make_context=make_shell_context)) manager.add_command('getconfig', GetConfig(app)) manager.add_command('db', MigrateCommand) manager.add_command('urls', ShowUrls) manager.add_command('key', key_manager) if __name__ == '__main__':
import json import os import ssl from pathlib import Path import fastjsonschema from neo4j.v1 import TRUST_ON_FIRST_USE, basic_auth from depc import create_app HOME = os.getenv("DEPC_HOME", str(Path(__file__).resolve().parents[2])) SCHEMAS_PATH = str(Path(HOME) / "consumer" / "schemas.json") DEFINITIONS_PATH = str(Path(HOME) / "consumer" / "definitions.json") app = create_app(environment=os.getenv("DEPC_ENV") or "dev") CONSUMER_CONFIG = app.config["CONSUMER"] # Load the JSON schemas to support flat and nested messages with open(SCHEMAS_PATH, "r") as f_schemas, open(DEFINITIONS_PATH, "r") as f_defs: schemas = json.load(f_schemas) definitions = json.load(f_defs) # Add the definitions in each schema schemas["flat"].update(definitions) schemas["nested"].update(definitions) validate_flat_message = fastjsonschema.compile(schemas["flat"]) validate_nested_message = fastjsonschema.compile(schemas["nested"])
import os from depc import create_app from depc.commands.config import config_cli from depc.commands.key import key_cli from depc.commands.user import user_cli env = os.getenv("DEPC_ENV", "dev") app = create_app(environment=env) app.cli.add_command(config_cli) app.cli.add_command(key_cli) app.cli.add_command(user_cli) if __name__ == "__main__": app.run(debug=(env == "dev"))
# -*- coding: utf8 -*- import os from depc import create_app from depc.extensions import cel app = create_app(os.getenv('DEPC_ENV') or 'dev') app.app_context().push()