Created
August 22, 2012 07:16
-
-
Save rozza/3423317 to your computer and use it in GitHub Desktop.
Test Case for MongoEngine/mongoengine#83
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from mongoengine import * | |
from mongoengine.tests import query_counter | |
class Test(unittest.TestCase): | |
def setUp(self): | |
conn = connect(db='mongoenginetest') | |
def test_cascade_dereferencing_complexfields(self): | |
class Foo(Document): | |
name = StringField() | |
bars = ListField(ReferenceField('Bar')) | |
class Bar(Document): | |
name = StringField() | |
quux = IntField() | |
Foo.drop_collection() | |
Bar.drop_collection() | |
my_bars = [Bar(name=(u'bar no. %d' % i), quux=i) for i in range(10)] | |
for bar in my_bars: | |
bar.save() | |
foo = Foo(name=u'test foo', bars=my_bars) | |
foo.save() | |
with query_counter() as q: | |
self.assertEqual(q, 0) | |
foo = Foo.objects.get(name=u'test foo') | |
self.assertEqual(q, 1) | |
foo.name = u'another name' | |
self.assertEqual(q, 1) | |
foo.save(validate=False, cascade=False) | |
self.assertEqual(q, 2) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment