From 5d8f76693d5a5995f1785a4e485c01ab7e5284c4 Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Sun, 27 Oct 2024 23:51:56 +0900 Subject: [PATCH 1/2] upgrade mongoengine --- deps-top.txt | 2 +- requirements.txt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deps-top.txt b/deps-top.txt index 6d1551d..a4983fd 100644 --- a/deps-top.txt +++ b/deps-top.txt @@ -20,7 +20,7 @@ pytest-html==4.1.1 pytest-md==0.2.0 flask-babel==1.0.0 # i18n -mongoengine==0.20.0 # Mongo数据库 +mongoengine==0.29.1 # Mongo数据库 mongomock==4.1.2 Pillow==8.0.1 # 图片处理 marshmallow==3.0.0b20 # 字段验证 (flask-apikit需要) diff --git a/requirements.txt b/requirements.txt index 03cd15a..ac5e546 100644 --- a/requirements.txt +++ b/requirements.txt @@ -91,8 +91,9 @@ google-cloud-storage==1.33.0 urllib3==1.25.11 gunicorn==20.0.4 setuptools==65.5.0 -mongoengine==0.20.0 - pymongo==3.13.0 +mongoengine==0.29.1 + pymongo==4.10.1 + dnspython==2.7.0 mongomock==4.1.2 packaging==24.1 sentinels==1.0.0 From 385f01ebf67c0350bc0a98614172f2e2a79129aa Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Tue, 15 Oct 2024 12:40:14 +0800 Subject: [PATCH 2/2] adapt mongoengine config change --- .env.test.sample | 2 +- app/models/__init__.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.test.sample b/.env.test.sample index d1b6b13..faebcae 100644 --- a/.env.test.sample +++ b/.env.test.sample @@ -14,7 +14,7 @@ ADMIN_EMAIL=admin@moeflow.com ADMIN_INITIAL_PASSWORD=change_me # mongodb database -MONGODB_URI="mongomock://moeflow:CHANGE_ME@127.0.0.1:27017/moeflow_test?authSource=admin" +MONGODB_URI="mongodb://moeflow:CHANGE_ME@127.0.0.1:27017/moeflow_test?authSource=admin" # celery job queue CELERY_BROKER_URL="amqp://moeflow:CHANGE_ME@127.0.0.1:5672/moeflow" # takes precedence over other RABBITMQ_* entries diff --git a/app/models/__init__.py b/app/models/__init__.py index 97c19f9..20135f6 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -13,6 +13,11 @@ def connect_db(config): logger.info("Connect mongodb") uri = config["DB_URI"] logger.debug(" - $DB_URI: {}".format(uri)) + if config.get("TESTING"): + import mongomock + + return connect(host=uri, mongo_client_class=mongomock.MongoClient) + return connect(host=uri)