Update mongomock example

Improved the mongomock example as reported in #2067 
 
Fixes #2067
This commit is contained in:
Bastien Gérard 2019-06-04 22:56:52 +02:00 committed by GitHub
parent 048a045966
commit 5bf1dd55b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,3 +19,30 @@ or with an alias:
connect('mongoenginetest', host='mongomock://localhost', alias='testdb') connect('mongoenginetest', host='mongomock://localhost', alias='testdb')
conn = get_connection('testdb') conn = get_connection('testdb')
Example of test file:
--------
.. code-block:: python
import unittest
from mongoengine import connect, disconnect
class Person(Document):
name = StringField()
class TestPerson(unittest.TestCase):
@classmethod
def setUpClass(cls):
connect('mongoenginetest', host='mongomock://localhost')
@classmethod
def tearDownClass(cls):
disconnect()
def test_thing(self):
pers = Person(name='John')
pers.save()
fresh_pers = Person.objects().first()
self.assertEqual(fresh_pers.name, 'John')