def test_empty_batch(self): scores = [] batcher = ParseBatcher() try: batcher.batch_save(scores) except ValueError: self.fail('Batcher raised ValueError due to empty batch list')
def testCanBatchUpdate(self): user = self._get_logged_user() phone_number = "555-0134" original_updatedAt = user.updatedAt user.phone = phone_number batcher = ParseBatcher() batcher.batch_save([user]) self.assert_(User.Query.filter(phone=phone_number).exists(), 'Failed to batch update user data. New info not on Parse') self.assert_(user.updatedAt != original_updatedAt, 'Failed to batch update user data: updatedAt not changed')
def testBatch(self): """test saving, updating and deleting objects in batches""" scores = [ GameScore(score=s, player_name='Jane', cheat_mode=False) for s in range(5) ] batcher = ParseBatcher() batcher.batch_save(scores) self.assert_( GameScore.Query.filter(player_name='Jane').count() == 5, "batch_save didn't create objects") self.assert_(all(s.objectId is not None for s in scores), "batch_save didn't record object IDs") # test updating for s in scores: s.score += 10 batcher.batch_save(scores) updated_scores = GameScore.Query.filter(player_name='Jane') self.assertEqual(sorted([s.score for s in updated_scores]), range(10, 15), msg="batch_save didn't update objects") # test deletion batcher.batch_delete(scores) self.assert_( GameScore.Query.filter(player_name='Jane').count() == 0, "batch_delete didn't delete objects")
def testBatch(self): """test saving, updating and deleting objects in batches""" scores = [GameScore(score=s, player_name=self.SCORE_NAME, cheat_mode=False) for s in range(5)] batcher = ParseBatcher() batcher.batch_save(scores,_using=self.USING) self.assert_(GameScore.Query.using(self.USING).filter(player_name=self.SCORE_NAME).count() == 5, "batch_save didn't create objects") self.assert_(all(s.objectId is not None for s in scores), "batch_save didn't record object IDs") # test updating for s in scores: s.score += 10 batcher.batch_save(scores,_using=self.USING) updated_scores = GameScore.Query.using(self.USING).filter(player_name=self.SCORE_NAME) self.assertEqual(sorted([s.score for s in updated_scores]), range(10, 15), msg="batch_save didn't update objects") # test deletion batcher.batch_delete(scores,_using=self.USING) self.assert_(GameScore.Query.using(self.USING).filter(player_name=self.SCORE_NAME).count() == 0, "batch_delete didn't delete objects")