def test_fire_coo(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('!promote testuser2') replies = self.command('!fire testuser2') self.assertEqual(len(replies), 1) self.assertEqual(replies[0], message.modify_fire(MockInvestor('testuser2', ''))) sess = self.Session() user = sess.query(Investor).filter( Investor.name == 'testuser2').first() self.assertEqual(user.firm, 0) self.assertEqual(user.firm_role, '') firm = sess.query(Firm).filter(Firm.name == 'Foobar').first() self.assertEqual(firm.size, 1) self.assertEqual(firm.coo, 0)
def fire(self, sess, comment, investor, to_fire): if investor.firm == 0: return comment.reply_wrap(message.firm_none_org) if investor.firm_role == "": return comment.reply_wrap(message.not_ceo_or_exec_org) user = sess.query(Investor).\ filter(func.lower(Investor.name) == func.lower(to_fire)).\ first() if (user == None) or (user.name == investor.name) or (user.firm != investor.firm): return comment.reply_wrap(message.fire_failure_org) if (investor.firm_role != "ceo") and (user.firm_role != ""): return comment.reply_wrap(message.not_ceo_org) firm = sess.query(Firm).\ filter(Firm.id == investor.firm).\ first() user.firm_role = "" user.firm = 0 firm.size -= 1 if investor.firm_role == 'exec': firm.execs -= 1 # Clear the firm flair if not config.TEST: for subreddit in config.SUBREDDITS: REDDIT.subreddit(subreddit).flair.set(user.name, '') return comment.reply_wrap(message.modify_fire(user))