Skip to content

Commit

Permalink
test_save_max_recursion_not_hit_with_file_field added
Browse files Browse the repository at this point in the history
  • Loading branch information
valuerr authored and Valentin Gorbunov committed Jun 6, 2012
1 parent 27a4d83 commit e4bc922
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pickle
import pymongo
import bson
Expand All @@ -13,6 +14,8 @@
from mongoengine.queryset import InvalidQueryError
from mongoengine.connection import get_db

TEST_IMAGE_PATH = os.path.join(os.path.dirname(__file__), 'mongoengine.png')


class DocumentTest(unittest.TestCase):

Expand Down Expand Up @@ -1328,6 +1331,30 @@ class Person(Document):
p0.name = 'wpjunior'
p0.save()

def test_save_max_recursion_not_hit_with_file_field(self):

class Foo(Document):
name = StringField()
file = FileField()
bar = ReferenceField('self')

Foo.drop_collection()

a = Foo(name='hello')
a.save()

a.bar = a
a.file = open(TEST_IMAGE_PATH, 'rb')
a.save()

# Confirm can save and it resets the changed fields without hitting
# max recursion error
b = Foo.objects.with_id(a.id)
b.name='world'
b.save()

self.assertEquals(b.file, b.bar.file, b.bar.bar.file)

def test_save_cascades(self):

class Person(Document):
Expand Down

0 comments on commit e4bc922

Please sign in to comment.