Add test for nested list in EmbeddedDocument
This commit is contained in:
parent
adce9e6220
commit
9e9703183f
@ -285,8 +285,6 @@ class ComplexBaseField(BaseField):
|
||||
def to_python(self, value):
|
||||
"""Convert a MongoDB-compatible type to a Python type.
|
||||
"""
|
||||
Document = _import_class('Document')
|
||||
|
||||
if isinstance(value, basestring):
|
||||
return value
|
||||
|
||||
@ -306,6 +304,7 @@ class ComplexBaseField(BaseField):
|
||||
value_dict = dict([(key, self.field.to_python(item))
|
||||
for key, item in value.items()])
|
||||
else:
|
||||
Document = _import_class('Document')
|
||||
value_dict = {}
|
||||
for k, v in value.items():
|
||||
if isinstance(v, Document):
|
||||
|
@ -1593,6 +1593,31 @@ class FieldTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(47, BlogPost.objects.first().author.power)
|
||||
|
||||
def test_embedded_document_inheritance_with_list(self):
|
||||
"""Ensure that nested list of subclassed embedded documents is
|
||||
handled correctly.
|
||||
"""
|
||||
|
||||
class Group(EmbeddedDocument):
|
||||
name = StringField()
|
||||
content = ListField(StringField())
|
||||
|
||||
class Basedoc(Document):
|
||||
groups = ListField(EmbeddedDocumentField(Group))
|
||||
meta = {'abstract': True}
|
||||
|
||||
class User(Basedoc):
|
||||
doctype = StringField(require=True, default='userdata')
|
||||
|
||||
User.drop_collection()
|
||||
|
||||
content = ['la', 'le', 'lu']
|
||||
group = Group(name='foo', content=content)
|
||||
foobar = User(groups=[group])
|
||||
foobar.save()
|
||||
|
||||
self.assertEqual(content, User.objects.first().groups[0].content)
|
||||
|
||||
def test_reference_validation(self):
|
||||
"""Ensure that invalid docment objects cannot be assigned to reference
|
||||
fields.
|
||||
|
Loading…
x
Reference in New Issue
Block a user