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)