Esempio n. 1
0
    def test_promote_to_assoc_and_exec(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('!create', username='******')
        self.command('!joinfirm Foobar', username='******')
        self.command('!promote testuser3')
        self.command('!promote testuser3')

        self.command('!create', username='******')
        self.command('!joinfirm Foobar', username='******')

        replies = self.command('!promote testuser4')
        self.assertEqual(len(replies), 1)
        self.assertEqual(
            replies[0],
            message.modify_promote(MockInvestor('testuser4', 'assoc')))

        sess = self.Session()
        user = sess.query(Investor).filter(
            Investor.name == 'testuser3').first()
        self.assertEqual(user.firm, 1)
        self.assertEqual(user.firm_role, 'exec')

        user = sess.query(Investor).filter(
            Investor.name == 'testuser4').first()
        self.assertEqual(user.firm, 1)
        self.assertEqual(user.firm_role, 'assoc')
Esempio n. 2
0
    def test_promote_to_cfo_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')

        replies = self.command('!promote testuser3')
        self.assertEqual(len(replies), 1)
        self.assertEqual(
            replies[0],
            message.modify_promote(MockInvestor('testuser3', 'coo'), 'exec'))

        sess = self.Session()
        firm = sess.query(Firm).filter(Firm.name == 'Foobar').first()
        self.assertEqual(firm.size, 3)
        self.assertEqual(firm.execs, 0)
        self.assertEqual(firm.cfo, "testuser2")
        self.assertEqual(firm.coo, "testuser3")
Esempio n. 3
0
    def test_promote_to_cfo(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')
        replies = self.command('!promote testuser2', username='******')
        self.assertEqual(len(replies), 1)
        self.assertEqual(
            replies[0],
            message.modify_promote(MockInvestor('testuser2', 'cfo')))
    def promote(self, sess, comment, investor, to_promote):
        if investor.firm == 0:
            return comment.reply_wrap(message.firm_none_org)

        if investor.firm_role != "ceo":
            return comment.reply_wrap(message.not_ceo_org)

        user = sess.query(Investor).\
            filter(func.lower(Investor.name) == func.lower(to_promote)).\
            first()
        if (user is None) or (user.firm != investor.firm):
            return comment.reply_wrap(message.promote_failure_org)

        firm = sess.query(Firm).\
            filter(Firm.id == user.firm).\
            first()

        if user.firm_role == "":
            max_execs = max_execs_for_rank(firm.rank)
            if firm.execs >= max_execs:
                return comment.reply_wrap(message.modify_promote_full(firm))

            user.firm_role = "exec"
            firm.execs += 1
        elif user.firm_role == "exec":
            # Swapping roles
            investor.firm_role = "exec"
            user.firm_role = "ceo"

        # Updating the flair in subreddits
        flair_role = ''
        if user.firm_role == "ceo":
            flair_role = "CEO"
        else:
            flair_role = "Executive"
        if not config.TEST:
            for subreddit in config.SUBREDDITS:
                REDDIT.subreddit(subreddit).flair.set(
                    user.name, f"{firm.name} | {flair_role}")

        return comment.reply_wrap(message.modify_promote(user))
Esempio n. 5
0
    def promote(self, sess, comment, investor, to_promote):
        if investor.firm == 0:
            return comment.reply_wrap(message.firm_none_org)

        user = sess.query(Investor).\
            filter(func.lower(Investor.name) == func.lower(to_promote)).\
            first()
        if (user is None) or (user.firm != investor.firm):
            return comment.reply_wrap(message.promote_failure_org)

        firm = sess.query(Firm).\
            filter(Firm.id == user.firm).\
            first()

        if user.firm_role == "":
            if (investor.firm_role == "") or (investor.firm_role == "assoc"):
                return comment.reply_wrap(message.not_ceo_or_exec_org)

            max_assocs = max_assocs_for_rank(firm.rank)
            if firm.assocs >= max_assocs:
                return comment.reply_wrap(
                    message.modify_promote_assocs_full(firm))

            user.firm_role = "assoc"
            firm.assocs += 1

        elif user.firm_role == "assoc":
            if investor.firm_role != "ceo" and investor.firm_role != "coo":
                return comment.reply_wrap(message.not_ceo_or_coo_org)

            max_execs = max_execs_for_rank(firm.rank)
            if firm.execs >= max_execs:
                return comment.reply_wrap(
                    message.modify_promote_execs_full(firm))

            user.firm_role = "exec"
            firm.assocs -= 1
            firm.execs += 1

        elif user.firm_role == "exec":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            if firm.cfo >= 1:
                return comment.reply_wrap(message.promote_cfo_full_org)

            user.firm_role = "cfo"
            firm.execs -= 1
            firm.cfo += 1

        elif user.firm_role == "cfo":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            if firm.coo >= 1:
                return comment.reply_wrap(message.promote_coo_full_org)

            user.firm_role = "coo"
            firm.cfo -= 1
            firm.coo += 1

        elif user.firm_role == "coo":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            # Swapping roles
            investor.firm_role = "coo"
            user.firm_role = "ceo"

        # Updating the flair in subreddits
        flair_role_user = ''
        if user.firm_role == "ceo":
            flair_role_user = "******"
        elif user.firm_role == "coo":
            flair_role_user = "******"
        elif user.firm_role == "cfo":
            flair_role_user = "******"
        elif user.firm_role == "exec":
            flair_role_user = "******"
        elif user.firm_role == "assoc":
            flair_role_user = "******"

        flair_role_investor = ''
        if investor.firm_role == "ceo":
            flair_role_investor = "CEO"
        elif investor.firm_role == "coo":
            flair_role_investor = "COO"
        elif investor.firm_role == "cfo":
            flair_role_investor = "CFO"
        elif investor.firm_role == "exec":
            flair_role_investor = "Executive"
        elif investor.firm_role == "assoc":
            flair_role_investor = "Associate"

        if not config.TEST:
            for subreddit in config.SUBREDDITS:
                REDDIT.subreddit(subreddit).flair.set(
                    user.name, f"{firm.name} | {flair_role_user}")
                REDDIT.subreddit(subreddit).flair.set(
                    investor.name, f"{firm.name} | {flair_role_investor}")

        return comment.reply_wrap(message.modify_promote(user))
Esempio n. 6
0
    def promote(self, sess, comment, investor, to_promote):
        if investor.firm == 0:
            return comment.reply_wrap(message.firm_none_org)

        user = sess.query(Investor).\
            filter(func.lower(Investor.name) == func.lower(to_promote)).\
            first()
        if (user is None) or (user.name == investor.name) or (user.firm !=
                                                              investor.firm):
            return comment.reply_wrap(message.promote_failure_org)

        firm = sess.query(Firm).\
            filter(Firm.id == user.firm).\
            first()

        user_role = user.firm_role

        if user_role == "":
            if (investor.firm_role == "") or (investor.firm_role == "assoc"):
                return comment.reply_wrap(message.not_ceo_or_exec_org)

            max_assocs = max_assocs_for_rank(firm.rank)
            if firm.assocs >= max_assocs:
                return comment.reply_wrap(
                    message.modify_promote_assocs_full(firm))

            user.firm_role = "assoc"
            firm.assocs += 1

        elif user_role == "assoc":
            if investor.firm_role != "ceo" and investor.firm_role != "coo":
                return comment.reply_wrap(message.not_ceo_or_coo_org)

            max_execs = max_execs_for_rank(firm.rank)
            if firm.execs >= max_execs:
                return comment.reply_wrap(
                    message.modify_promote_execs_full(firm))

            user.firm_role = "exec"
            firm.assocs -= 1
            firm.execs += 1

        elif user_role == "exec":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            # If the firm already has a CFO, the user will be promoted to COO
            if firm.cfo != '' and firm.cfo != 0:
                if firm.coo != '' and firm.coo != 0:
                    return comment.reply_wrap(message.promote_coo_full_org)

                user.firm_role = "coo"
                firm.execs -= 1
                firm.coo = user.name
            else:
                user.firm_role = "cfo"
                firm.execs -= 1
                firm.cfo = user.name

        elif user_role == "cfo":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            if firm.coo != '' and firm.coo != 0:
                return comment.reply_wrap(message.promote_coo_full_org)

            user.firm_role = "coo"
            firm.cfo = ''
            firm.coo = user.name

        elif user_role == "coo":
            if investor.firm_role != "ceo":
                return comment.reply_wrap(message.not_ceo_org)

            # Swapping roles
            investor.firm_role = "coo"
            firm.coo = investor.name
            user.firm_role = "ceo"
            firm.ceo = 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 = "******"

        # Investor role flair must be set in case COO and CEO roles are swapped
        flair_role_investor = ''
        if investor.firm_role == "ceo":
            flair_role_investor = "CEO"
        if investor.firm_role == "coo":
            flair_role_investor = "COO"
        if investor.firm_role == "cfo":
            flair_role_investor = "CFO"
        if investor.firm_role == "exec":
            flair_role_investor = "Executive"
        if investor.firm_role == "assoc":
            flair_role_investor = "Associate"

        if not config.TEST:
            for subreddit in config.SUBREDDITS:
                REDDIT.subreddit(subreddit).flair.set(
                    user.name, f"{firm.name} | {flair_role_user}")
                REDDIT.subreddit(subreddit).flair.set(
                    investor.name, f"{firm.name} | {flair_role_investor}")

        return comment.reply_wrap(message.modify_promote(user, user_role))