def test_top(self): self.command('!create') replies = self.command('!top') self.assertEqual(len(replies), 1) self.assertEqual(replies[0], message.modify_top([ Leader('testuser', 1000) ])) self.command('!create', username='******') self.command('!create', username='******') self.command('!create', username='******') self.command('!create', username='******') self.command('!create', username='******') replies = self.command('!top') self.assertEqual(len(replies), 1) self.assertEqual(replies[0], message.modify_top([ Leader('testuser', 1000), Leader('testuser2', 1000), Leader('testuser3', 1000), Leader('testuser4', 1000), Leader('testuser5', 1000) ])) self.set_balance(1234, username='******') replies = self.command('!top') self.assertEqual(len(replies), 1) self.assertEqual(replies[0], message.modify_top([ Leader('testuser6', 1234), Leader('testuser', 1000), Leader('testuser2', 1000), Leader('testuser3', 1000), Leader('testuser4', 1000) ]))
def test_networth(self): self.command("!create") self.command("!invest 100") replies = self.command("!top") self.assertEqual(len(replies), 1) self.assertEqual(replies[0].body, message.modify_top([Leader("testuser", 1000)]))
def test_networth(self): self.command('!create') self.command('!invest 100') replies = self.command('!top') self.assertEqual(len(replies), 1) self.assertEqual(replies[0].body, message.modify_top([Leader('testuser', 1000)]))
def top(self, sess, comment): leaders = sess.query( Investor.name, func.coalesce(Investor.balance+func.sum(Investment.amount), Investor.balance).label('networth')).\ outerjoin(Investment, and_(Investor.name == Investment.name, Investment.done == 0)).\ group_by(Investor.name).\ order_by(desc('networth')).\ limit(5).\ all() comment.reply_wrap(message.modify_top(leaders))
def test_top(self): self.command("!create") replies = self.command("!top") self.assertEqual(len(replies), 1) self.assertEqual(replies[0].body, message.modify_top([Leader("testuser", 1000)])) self.command("!create", username="******") self.command("!create", username="******") self.command("!create", username="******") self.command("!create", username="******") self.command("!create", username="******") replies = self.command("!top") self.assertEqual(len(replies), 1) self.assertEqual( replies[0].body, message.modify_top([ Leader("testuser", 1000), Leader("testuser2", 1000), Leader("testuser3", 1000), Leader("testuser4", 1000), Leader("testuser5", 1000), ]), ) self.set_balance(1234, username="******") replies = self.command("!top") self.assertEqual(len(replies), 1) self.assertEqual( replies[0].body, message.modify_top([ Leader("testuser6", 1234), Leader("testuser", 1000), Leader("testuser2", 1000), Leader("testuser3", 1000), Leader("testuser4", 1000), ]), )
def top(self, sess, comment): """ Returns the top users in the meme market """ leaders = (sess.query( Investor.name, func.coalesce(Investor.balance + func.sum(Investment.amount), Investor.balance).label("networth"), ).outerjoin( Investment, and_(Investor.name == Investment.name, Investment.done == 0)).group_by(Investor.name).order_by( desc("networth")).limit(5).all()) return comment.reply_wrap(message.modify_top(leaders))
def top(self, sess, comment): leaders = sess.query(Investor).order_by(Investor.balance.desc()).limit(5).all() comment.reply_wrap(message.modify_top(leaders))
def test_top_none(self): replies = self.command("!top") self.assertEqual(len(replies), 1) self.assertEqual(replies[0].body, message.modify_top([]))