Exemple #1
0
    def vendi(self, sess, comment, investor):
        """
        Returns a list of all active investments made by the user
        """
        investments = sess.query(Investment).\
            filter(Investment.done == 0).\
            filter(Investment.post == comment.submission.id).\
            filter(Investment.name == investor.name).\
            order_by(Investment.time).\
            all()

        taxes = 0
        for investment in investments:
            if comment.submission.author and not comment.submission.removed:
                # no taxes on deleted submissions
                remaining = config.INVESTMENT_DURATION - int(
                    time.time()) + investment.time
                tax = min(99, pow(remaining / 60 / 60,
                                  1.5)) / 100  # (1% every hour)^1.5 - max 99%
                taxes += investment.amount - round(investment.amount -
                                                   investment.amount * tax)
                investment.amount = round(investment.amount -
                                          investment.amount * tax)
            # expire investment time (update it in the past)
            investment.time = int(time.time()) - config.INVESTMENT_DURATION

        sess.commit()

        return comment.reply_wrap(
            message.modify_sell_investment(len(investments), taxes))
Exemple #2
0
 def test_sell(self):
     self.command("!create")
     replies = self.command("!investi 200")
     self.assertEqual(len(replies), 1)
     replies = self.command("!vendi")
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_sell_investment(1, 0))
Exemple #3
0
 def test_sell_taxes_max(self):
     INVESTMENT_DURATION = config.INVESTMENT_DURATION
     config.INVESTMENT_DURATION = 86400
     self.command("!create")
     replies = self.command("!investi 100")
     self.assertEqual(len(replies), 1)
     replies = self.command("!vendi")
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_sell_investment(1, 99))
     config.INVESTMENT_DURATION = INVESTMENT_DURATION
Exemple #4
0
 def test_sell_taxes(self):
     INVESTMENT_DURATION = config.INVESTMENT_DURATION
     config.INVESTMENT_DURATION = 16 * 60 * 60
     self.command("!create")
     replies = self.command("!investi 100")
     self.assertEqual(len(replies), 1)
     replies = self.command("!vendi")
     self.assertEqual(len(replies), 1)
     # 16^(1.5) = 64
     self.assertEqual(replies[0].body, message.modify_sell_investment(1, 64))
     config.INVESTMENT_DURATION = INVESTMENT_DURATION
Exemple #5
0
 def test_sell_removed(self):
     INVESTMENT_DURATION = config.INVESTMENT_DURATION
     config.INVESTMENT_DURATION = 16 * 60 * 60
     self.command("!create")
     replies = self.command("!investi 100")
     self.assertEqual(len(replies), 1)
     replies = self.command(
         "!vendi", lpost=lambda submission: setattr(submission, "removed", True)
     )
     self.assertEqual(len(replies), 1)
     # No taxes
     self.assertEqual(replies[0].body, message.modify_sell_investment(1, 0))
     config.INVESTMENT_DURATION = INVESTMENT_DURATION
Exemple #6
0
 def test_sell_deleted(self):
     INVESTMENT_DURATION = config.INVESTMENT_DURATION
     config.INVESTMENT_DURATION = 16 * 60 * 60
     self.command('!create')
     replies = self.command('!investi 100')
     self.assertEqual(len(replies), 1)
     replies = self.command('!vendi')
     self.assertEqual(len(replies), 1)
     replies = self.command(
         '!vendi',
         lpost=lambda submission: setattr(submission, 'author', None))
     # No taxes
     self.assertEqual(replies[0].body, message.modify_sell_investment(1, 0))
     config.INVESTMENT_DURATION = INVESTMENT_DURATION
Exemple #7
0
 def test_sell_void(self):
     self.command('!create')
     replies = self.command('!vendi')
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_sell_investment(0, 0))