def test_app(): """Instantiate the app for each test with its own temporary data directory Each test using this fixture will use its own db.json and its own data directory, and then delete them. """ # create a temporary file to isolate the database for each test global _app if _app is None: _app = create_click_web_app(cli, cli.cli, app) app_dir = tempfile.mkdtemp() _app.config["INTERNAL_DIR"] = app_dir _app.config["USER_DIR"] = app_dir data_dir = os.path.join(app_dir, "data") os.mkdir(data_dir) _app.config["TESTING"] = True _app.config["WTF_CSRF_ENABLED"] = False # This setups a TinyDB instance, using the `app_dir` temporary # directory defined above # Required so that `flask.current_app` can be called in data.py and # models.py # See https://flask.palletsprojects.com/en/1.1.x/appcontext/ for more # information. with _app.app_context(): _ = get_db() user = {"username": "******", "password": "******"} User(**user).insert() yield _app # close and remove the temporary database shutil.rmtree(app_dir)
def run(): click.echo('Running archivy...') load_dotenv() watcher = Watcher(app) watcher.start() port = int(os.environ.get("ARCHIVY_PORT", 5000)) os.environ["FLASK_RUN_FROM_CLI"] = "false" app_with_cli = create_click_web_app(click, cli, app) app_with_cli.run(host='0.0.0.0', port=port) click.echo("Stopping archivy watcher") watcher.stop() watcher.join()
def run(): click.echo("Running archivy...") load_dotenv() environ["FLASK_RUN_FROM_CLI"] = "false" app_with_cli = create_click_web_app(click, cli, app) app_with_cli.run(host=app.config["HOST"], port=app.config["PORT"])