diff --git a/.env.test.sample b/.env.test.sample index c3f750e..20e1239 100644 --- a/.env.test.sample +++ b/.env.test.sample @@ -5,7 +5,7 @@ SITE_NAME=萌翻TEST SECRET_KEY=SECRET ADMIN_EMAIL=admin@moeflow.com -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" # MONGODB_DB_NAME=moeflow # MONGODB_USER=moeflow # MONGODB_PASS=CHANGE_ME 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)