'Ensure that invalid document objects cannot be assigned to
reference fields.'

def test_reference_validation(self):

    class User(Document, ):
        name = StringField()
    class BlogPost(Document, ):
        content = StringField()
        author = ReferenceField(User)
    User.drop_collection()
    BlogPost.drop_collection()
    self.assertRaises(ValidationError, ReferenceField, EmbeddedDocument)
    user = User(name='Test    User')
    post1 = BlogPost(content='Chips    and    gravy    taste    good.')
    post1.author = user
    self.assertRaises(ValidationError, post1.save)
    post2 = BlogPost(content='Chips    and    chilli    taste    good.')
    post1.author = post2
    self.assertRaises(ValidationError, post1.validate)
    user_object_id = user.pk
    post3 = BlogPost(content='Chips    and    curry    sauce    taste    good.')
    post3.author = user_object_id
    post3.save()
    user.save()
    post1.author = user
    post1.save()
    post2.save()
    post1.author = post2
    self.assertRaises(ValidationError, post1.validate)
