'Ensure that a referenced document is also deleted upon
deletion.'

def test_reverse_delete_rule_cascade_and_nullify(self):

    class BlogPost(Document, ):
        content = StringField()
        author = ReferenceField(self.Person, reverse_delete_rule=CASCADE)
        reviewer = ReferenceField(self.Person, reverse_delete_rule=NULLIFY)
    self.Person.drop_collection()
    BlogPost.drop_collection()
    author = self.Person(name='Test    User')
    author.save()
    reviewer = self.Person(name='Re    Viewer')
    reviewer.save()
    post = BlogPost(content='Watched    some    TV')
    post.author = author
    post.reviewer = reviewer
    post.save()
    reviewer.delete()
    self.assertEqual(BlogPost.objects.count(), 1)
    self.assertEqual(BlogPost.objects.get().reviewer, None)
    author.delete()
    self.assertEqual(BlogPost.objects.count(), 0)
