def test_demote_execs_full(self): self.command('!create') self.set_balance(5000000) self.command('!createfirm Foobar') self.command('!create', username='******') self.command('!joinfirm Foobar', username='******') self.command('!promote testuser2') self.command('!promote testuser2') self.command('!promote testuser2') self.command('!create', username='******') self.command('!joinfirm Foobar', username='******') self.command('!promote testuser3') self.command('!promote testuser3') self.command('!create', username='******') self.command('!joinfirm Foobar', username='******') self.command('!promote testuser4') self.command('!promote testuser4') replies = self.command('!demote testuser2') self.assertEqual(len(replies), 1) self.assertEqual( replies[0], message.modify_demote_execs_full(MockFirm('Foobar', execs=2))) sess = self.Session() user = sess.query(Investor).filter( Investor.name == 'testuser2').first() self.assertEqual(user.firm, 1) self.assertEqual(user.firm_role, 'cfo')
def demote(self, sess, comment, investor, to_demote): if investor.firm == 0: return comment.reply_wrap(message.firm_none_org) user = sess.query(Investor).\ filter(func.lower(Investor.name) == func.lower(to_demote)).\ first() if (user is None) or (user.name == investor.name) or (user.firm != investor.firm): return comment.reply_wrap(message.demote_failure_org) firm = sess.query(Firm).\ filter(Firm.id == user.firm).\ first() user_role = user.firm_role # If user is already at the lowest rank, they cannot be demoted if user_role == "": return comment.reply_wrap(message.demote_failure_trader_org) if user_role == "assoc": if (investor.firm_role == "") or (investor.firm_role == "assoc"): return comment.reply_wrap(message.not_ceo_or_exec_org) user.firm_role = "" firm.assocs -= 1 if user_role == "exec": if investor.firm_role != "ceo" and investor.firm_role != "coo": return comment.reply_wrap(message.not_ceo_or_coo_org) max_assocs = max_assocs_for_rank(firm.rank) if firm.assocs >= max_assocs: return comment.reply_wrap( message.modify_demote_assocs_full(firm)) user.firm_role = "assoc" firm.execs -= 1 firm.assocs += 1 if user.firm_role == "cfo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) max_execs = max_execs_for_rank(firm.rank) if firm.execs >= max_execs: return comment.reply_wrap( message.modify_demote_execs_full(firm)) user.firm_role = "exec" firm.cfo = '' firm.execs += 1 if user.firm_role == "coo": if investor.firm_role != "ceo": return comment.reply_wrap(message.not_ceo_org) # If the firm already has a CFO, the user will be demoted to Executive if firm.cfo != '' and firm.cfo != 0: max_execs = max_execs_for_rank(firm.rank) if firm.execs >= max_execs: return comment.reply_wrap( message.modify_demote_execs_full(firm)) user.firm_role = "exec" firm.coo = '' firm.execs += 1 else: user.firm_role = "cfo" firm.coo = '' firm.cfo = user.name # Updating the flair in subreddits flair_role_user = '' if user.firm_role == "ceo": flair_role_user = "******" if user.firm_role == "coo": flair_role_user = "******" if user.firm_role == "cfo": flair_role_user = "******" if user.firm_role == "exec": flair_role_user = "******" if user.firm_role == "assoc": flair_role_user = "******" if not config.TEST: for subreddit in config.SUBREDDITS: REDDIT.subreddit(subreddit).flair.set( user.name, f"{firm.name} | {flair_role_user}") return comment.reply_wrap(message.modify_demote(user, user_role))