Merge pull request #2131 from NMFR/master

Set default database when using mongomock.
This commit is contained in:
Bastien Gérard
2019-07-22 11:56:56 +02:00
committed by GitHub
2 changed files with 33 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ from pymongo import MongoClient
from pymongo.errors import OperationFailure, InvalidName
from pymongo import ReadPreference
from mongoengine import Document
try:
import unittest2 as unittest
except ImportError:
@@ -269,6 +271,26 @@ class ConnectionTest(unittest.TestCase):
conn = get_connection("testdb7")
self.assertIsInstance(conn, mongomock.MongoClient)
def test_default_database_with_mocking(self):
"""Ensure that the default database is correctly set when using mongomock.
"""
try:
import mongomock
except ImportError:
raise SkipTest("you need mongomock installed to run this testcase")
disconnect_all()
class SomeDocument(Document):
pass
conn = connect(host="mongomock://localhost:27017/mongoenginetest")
some_document = SomeDocument()
# database won't exist until we save a document
some_document.save()
self.assertEqual(conn.get_default_database().name, "mongoenginetest")
self.assertEqual(conn.database_names()[0], "mongoenginetest")
def test_connect_with_host_list(self):
"""Ensure that the connect() method works when host is a list