我正在尝试使用 factory_boy 来帮助为我的测试生成一些 MongoEngine 文档。我在定义EmbeddedDocumentField
对象时遇到了麻烦。
这是我的 MongoEngine Document
:
class Comment(EmbeddedDocument):
content = StringField()
name = StringField(max_length=120)
class Post(Document):
title = StringField(required=True)
tags = ListField(StringField(), required=True)
comments = ListField(EmbeddedDocumentField(Comment))
这是我部分完成的 factory_boy Factory
:
class CommentFactory(factory.Factory):
FACTORY_FOR = Comment
content = "Platinum coins worth a trillion dollars are great"
name = "John Doe"
class BlogFactory(factory.Factory):
FACTORY_FOR = Blog
title = "On Using MongoEngine with factory_boy"
tags = ['python', 'mongoengine', 'factory-boy', 'django']
comments = [factory.SubFactory(CommentFactory)] # this doesn't work
任何想法如何指定comments
字段?问题是工厂男孩试图创建Comment
EmbeddedDocument。