diff --git a/Makefile b/Makefile index 9483206..f902d92 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,11 @@ format: test: @bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest" -test_smoketest: +test_single: + @bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_not_exist_error.py" + +test_logging: #--capture=no # WTF: setting level to above WARNING not working? @bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_it_runs.py" + # @bash -c "set -uexo allexport && source .env.test && exec venv/bin/pytest --capture=sys --log-cli-level=DEBUG tests/base/test_it_runs.py" diff --git a/app/__init__.py b/app/__init__.py index 3d7a26e..3edbbaa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,19 +2,14 @@ import logging from flask import Flask, g, request -from flask_apikit import APIKit -from flask_babel import Babel -from .factory import app_config, create_celery, create_flask_app +from .factory import app_config, create_celery, create_flask_app, babel, oss from app.constants.locale import Locale from app.core.rbac import AllowApplyType, ApplicationCheckType from app.services.google_storage import GoogleStorage -from app.services.oss import OSS from app.utils.logging import configure_root_logger, configure_extra_logs -from .apis import register_apis - configure_root_logger() flask_app = create_flask_app(Flask(__name__)) configure_extra_logs(flask_app) @@ -28,11 +23,7 @@ FILE_PATH = os.path.abspath(os.path.join(APP_PATH, "..", "files")) # 一般文件 TMP_PATH = os.path.abspath(os.path.join(FILE_PATH, "tmp")) # 临时文件存放地址 STORAGE_PATH = os.path.abspath(os.path.join(APP_PATH, "..", "storage")) # 储存地址 -# 插件 -babel = Babel() -oss = OSS() gs_vision = GoogleStorage() -apikit = APIKit() def create_default_team(admin_user): @@ -84,17 +75,7 @@ def create_or_override_default_admin(app): def create_app(): - app = flask_app - logger.info("-" * 50) - register_apis(app) - babel.init_app(app) - apikit.init_app(app) - - logger.info("-" * 50) - logger.info("站点支持语言: " + str([str(i) for i in babel.list_translations()])) - oss.init(app.config) # 文件储存 - - return app + return flask_app def init_db(app: Flask): diff --git a/app/config.py b/app/config.py index 86779e7..6a8e961 100644 --- a/app/config.py +++ b/app/config.py @@ -12,7 +12,7 @@ SECRET_KEY = env["SECRET_KEY"] # 必填 - 密钥 LOG_LEVEL = env.get("LOG_LEVEL", "INFO") # DEPRECATED: please use modern container logging collector -LOG_PATH = env.get('LOG_PATH') +LOG_PATH = env.get("LOG_PATH") MAX_CONTENT_LENGTH = int(env.get("MAX_CONTENT_LENGTH_MB", 1024)) * 1024 * 1024 ADMIN_EMAIL = env["ADMIN_EMAIL"] # ----------- diff --git a/app/factory.py b/app/factory.py index 3fcc47e..1418c54 100644 --- a/app/factory.py +++ b/app/factory.py @@ -1,9 +1,21 @@ +import logging from celery import Celery from flask import Flask from flask.logging import default_handler as flask_default_handler +from flask_apikit import APIKit +from flask_babel import Babel import app.config as _app_config +from app.services.oss import OSS +from .apis import register_apis + from app.models import connect_db +logger = logging.getLogger(__name__) +babel = Babel() +apikit = APIKit() +# 插件 +oss = OSS() + app_config = { k: getattr(_app_config, k) for k in dir(_app_config) if not k.startswith("_") } @@ -20,6 +32,15 @@ def create_flask_app(app: Flask) -> Flask: return app +def init_flask_app(app: Flask) -> Flask: + register_apis(app) + babel.init_app(app) + apikit.init_app(app) + logger.info("-" * 50) + logger.info("站点支持语言: " + str([str(i) for i in babel.list_translations()])) + oss.init(app.config) # 文件储存 + + def create_celery(app: Flask) -> Celery: # 通过app配置创建celery实例 created = Celery(