'Ensure that the \'pull\' update operation works correctly.'

def test_update_push_and_pull_add_to_set(self):

    class BlogPost(Document, ):
        slug = StringField()
        tags = ListField(StringField())
    BlogPost.drop_collection()
    post = BlogPost(slug='test')
    post.save()
    BlogPost.objects.filter(id=post.id).update(push__tags='code')
    post.reload()
    self.assertEqual(post.tags, ['code'])
    BlogPost.objects.filter(id=post.id).update(push_all__tags=['mongodb', 'code'])
    post.reload()
    self.assertEqual(post.tags, ['code', 'mongodb', 'code'])
    BlogPost.objects(slug='test').update(pull__tags='code')
    post.reload()
    self.assertEqual(post.tags, ['mongodb'])
    BlogPost.objects(slug='test').update(pull_all__tags=['mongodb', 'code'])
    post.reload()
    self.assertEqual(post.tags, [])
    BlogPost.objects(slug='test').update(__raw__={'$addToSet': {'tags': {'$each': ['code', 'mongodb', 'code']}}})
    post.reload()
    self.assertEqual(post.tags, ['code', 'mongodb'])
