Skip to content

Instantly share code, notes, and snippets.

@rozza
Created August 22, 2012 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rozza/3423317 to your computer and use it in GitHub Desktop.
Save rozza/3423317 to your computer and use it in GitHub Desktop.
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