'Ensure that a list field only accepts lists with valid elements.'

def test_list_validation(self):

    class User(Document, ):
        pass
    class Comment(EmbeddedDocument, ):
        content = StringField()
    class BlogPost(Document, ):
        content = StringField()
        comments = ListField(EmbeddedDocumentField(Comment))
        tags = ListField(StringField())
        authors = ListField(ReferenceField(User))
        generic = ListField(GenericReferenceField())
    User.drop_collection()
    BlogPost.drop_collection()
    post = BlogPost(content='Went    for    a    walk    today...')
    post.validate()
    post.tags = 'fun'
    self.assertRaises(ValidationError, post.validate)
    post.tags = [1, 2]
    self.assertRaises(ValidationError, post.validate)
    post.tags = ['fun', 'leisure']
    post.validate()
    post.tags = ('fun', 'leisure')
    post.validate()
    post.comments = ['a']
    self.assertRaises(ValidationError, post.validate)
    post.comments = 'yay'
    self.assertRaises(ValidationError, post.validate)
    comments = [Comment(content='Good    for    you'), Comment(content='Yay.')]
    post.comments = comments
    post.validate()
    post.authors = [Comment()]
    self.assertRaises(ValidationError, post.validate)
    post.authors = [User()]
    self.assertRaises(ValidationError, post.validate)
    user = User()
    user.save()
    post.authors = [user]
    post.validate()
    post.generic = [1, 2]
    self.assertRaises(ValidationError, post.validate)
    post.generic = [User(), Comment()]
    self.assertRaises(ValidationError, post.validate)
    post.generic = [Comment()]
    self.assertRaises(ValidationError, post.validate)
    post.generic = [user]
    post.validate()
