def test_level_up_if_first_levels_worth_of_points(self):
     points = economy.sticker_schedule(None)
     expected_reward = economy.sticker_schedule(None, reward=True)
     self.user.redis.user_kv.hset('sticker_inbox', points)
     self.request.user_kv = self.user.redis.user_kv.hgetall()
     
     reward = economy.level_up(self.request.user)
     total_stickers = int(self.user.kv.stickers.currency.get() or 0)
     self.assertEquals(total_stickers, expected_reward)
     self.assertEquals(reward, expected_reward)
 def test_level_up_twice_together(self):
     points = economy.sticker_schedule(0) + economy.sticker_schedule(1)
     expected_reward = economy.sticker_schedule(0, reward=True) + economy.sticker_schedule(1, reward=True)
     self.user.redis.user_kv.hset('sticker_inbox', points)
     self.request.user_kv = self.user.redis.user_kv.hgetall()
     
     reward = economy.level_up(self.request.user, only_once=False)
     total_stickers = int(self.user.kv.stickers.currency.get() or 0)
     self.assertEquals(total_stickers, expected_reward)
     self.assertEquals(reward, expected_reward)
def get_info(user):
    comment_id = user.kv.last_sticker_comment_id.get()
    if comment_id:
        from canvas.models import Comment
        details = Comment.details_by_id(comment_id)()
        url = details.url
    else:
        url = None
    
    level = user.kv.sticker_level.get()
    schedule = economy.sticker_schedule(level)
    
    return {
        'type_id': user.kv.last_sticker_type_id.get(),
        'timestamp': user.kv.last_sticker_timestamp.get(),
        'comment_id': comment_id,
        'url': url,
        'level': level, 
        'level_progress': user.kv.sticker_inbox.get(),
        'level_total': schedule,            
    }