'Ensure that atomic updates work properly.'

def test_update(self):

    class BlogPost(Document, ):
        name = StringField()
        title = StringField()
        hits = IntField()
        tags = ListField(StringField())
    BlogPost.drop_collection()
    post = BlogPost(name='Test    Post', hits=5, tags=['test'])
    post.save()
    BlogPost.objects.update(set__hits=10)
    post.reload()
    self.assertEqual(post.hits, 10)
    BlogPost.objects.update_one(inc__hits=1)
    post.reload()
    self.assertEqual(post.hits, 11)
    BlogPost.objects.update_one(dec__hits=1)
    post.reload()
    self.assertEqual(post.hits, 10)
    BlogPost.objects.update_one(dec__hits=(-1))
    post.reload()
    self.assertEqual(post.hits, 11)
    BlogPost.objects.update(push__tags='mongo')
    post.reload()
    self.assertTrue(('mongo' in post.tags))
    BlogPost.objects.update_one(push_all__tags=['db', 'nosql'])
    post.reload()
    self.assertTrue((('db' in post.tags) and ('nosql' in post.tags)))
    tags = post.tags[:(-1)]
    BlogPost.objects.update(pop__tags=1)
    post.reload()
    self.assertEqual(post.tags, tags)
    BlogPost.objects.update_one(add_to_set__tags='unique')
    BlogPost.objects.update_one(add_to_set__tags='unique')
    post.reload()
    self.assertEqual(post.tags.count('unique'), 1)
    self.assertNotEqual(post.hits, None)
    BlogPost.objects.update_one(unset__hits=1)
    post.reload()
    self.assertEqual(post.hits, None)
    BlogPost.drop_collection()
