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):
|
def to_python(self, value):
|
||||||
"""Convert a MongoDB-compatible type to a Python type.
|
"""Convert a MongoDB-compatible type to a Python type.
|
||||||
"""
|
"""
|
||||||
Document = _import_class('Document')
|
|
||||||
|
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -306,6 +304,7 @@ class ComplexBaseField(BaseField):
|
|||||||
value_dict = dict([(key, self.field.to_python(item))
|
value_dict = dict([(key, self.field.to_python(item))
|
||||||
for key, item in value.items()])
|
for key, item in value.items()])
|
||||||
else:
|
else:
|
||||||
|
Document = _import_class('Document')
|
||||||
value_dict = {}
|
value_dict = {}
|
||||||
for k, v in value.items():
|
for k, v in value.items():
|
||||||
if isinstance(v, Document):
|
if isinstance(v, Document):
|
||||||
|
@ -1593,6 +1593,31 @@ class FieldTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(47, BlogPost.objects.first().author.power)
|
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):
|
def test_reference_validation(self):
|
||||||
"""Ensure that invalid docment objects cannot be assigned to reference
|
"""Ensure that invalid docment objects cannot be assigned to reference
|
||||||
fields.
|
fields.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user