From 385f01ebf67c0350bc0a98614172f2e2a79129aa Mon Sep 17 00:00:00 2001 From: Wang Guan Date: Tue, 15 Oct 2024 12:40:14 +0800 Subject: [PATCH] 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)