def joinfirm(self, sess, comment, investor, firm_name): if investor.firm != 0: return comment.reply_wrap(message.joinfirm_exists_failure_org) firm = sess.query(Firm).\ filter(func.lower(Firm.name) == func.lower(firm_name)).\ first() if firm == None: return comment.reply_wrap(message.joinfirm_failure_org) max_members = max_members_for_rank(firm.rank) if firm.size >= max_members: return comment.reply_wrap(message.modify_joinfirm_full(firm)) if firm.private: invite = sess.query(Invite).\ filter(Invite.investor == investor.id).\ filter(Invite.firm == firm.id).\ first() if invite == None: return comment.reply_wrap(message.joinfirm_private_failure_org) investor.firm = firm.id investor.firm_role = "" firm.size += 1 # Updating the flair in subreddits if not config.TEST: for subreddit in config.SUBREDDITS: REDDIT.subreddit(subreddit).flair.set( investor.name, f"{firm.name} | Floor Trader") return comment.reply_wrap(message.modify_joinfirm(firm))
def test_full(self): self.command('!create') self.set_balance(5000000) self.command('!createfirm Foobar') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.command('!create', username='******') replies = self.command('!joinfirm Foobar', username='******') self.assertEqual(len(replies), 1) self.assertEqual(replies[0], message.modify_joinfirm_full(MockFirm('Foobar', size=8))) sess = self.Session() user = sess.query(Investor).filter(Investor.name == 'testuser2').first() self.assertEqual(user.firm, 1) self.assertEqual(user.firm_role, '')