Beispiel #1
0
    def test_make_web_cashier_withdraw_detail_request(self):
        # This is the easiest way to get a user's balance. don't axe me.
        dummy_transaction = CashTransaction(self.user)
        initial_balance = dummy_transaction.get_balance_amount()
        self.assertEqual(initial_balance, 0)

        # Mock the response
        responses.add(
            responses.GET,
            WebCashierPaymentDetailRequest.url,
            body=str(json.dumps(WEB_CACHIER_PAYMENT_DETAIL_REQUEST_SUCCESS)),
            status=200,
            content_type='application/json'
        )

        req = make_web_cashier_payment_detail_request(self.user, 'tid', 'sid')

        # Now test the the proper transactions and stuff were created.

        # Get any GidxTransactions that were created because of this payment.
        cash_transaction = GidxTransaction.objects.filter(
            merchant_transaction_id=WEB_CACHIER_PAYMENT_DETAIL_REQUEST_SUCCESS[
                'MerchantTransactionID'])

        # make sure at least one 'sale' transaction was created (based on the current dummy data,
        # there should be 1 since we ignore non-sale transactions)
        self.assertGreater(cash_transaction.count(), 0)
        # Now make sure the counts  match.
        self.assertEqual(cash_transaction.count(), 1)

        # Make sure the user's balance has been udpated.
        # Hard code the amount in case  something get's goofed and it ends up as 0 or something.
        new_balance = dummy_transaction.get_balance_amount()
        self.assertEqual(new_balance, 20)
        self.user.delete()
Beispiel #2
0
    def test_check_cancel_payout(self):
        cw = self.__make_withdrawal_check(self.withdraw_amount)
        pending = models.WithdrawStatus.objects.get(
            pk=WithdrawStatusConstants.Pending.value)
        self.assertEquals(cw.withdraw_object.status, pending)

        cancelled = models.WithdrawStatus.objects.get(
            pk=WithdrawStatusConstants.CancelledAdminDefault.value)
        cw.cancel()
        self.assertEqual(cw.withdraw_object.status, cancelled)

        ct = CashTransaction(self.user)
        self.assertAlmostEquals(ct.get_balance_amount(),
                                decimal.Decimal(self.account_balance))
Beispiel #3
0
    def validate_withdraw(self, amount):
        """
        Sets the standard withdraw data in the :class:`cash.withdraw.models.Withdraw`
        abstract model.

        """

        if amount < Decimal(0.0):
            raise AmountNegativeException(
                type(self).__name__, 'amount: ' + str(amount))

        #
        # make sure they dont have more than the max outstanding withdraw requests
        max_pending = PendingMax().value()
        user_pending_withdraws = self.withdraw_class.objects.filter(
            cash_transaction_detail__user=self.user,
            status__in=self.OUTSTANDING_WITHDRAW_STATUSES)
        if len(user_pending_withdraws) >= max_pending:
            raise MaxCurrentWithdrawsException(
                type(self).__name__, "user at max pending withdraws")

        #
        # less than minimum ? greater than maximum ? we dont want that
        cashout = WithdrawMinMax()
        if amount < cashout.get_min() or cashout.get_max() < amount:
            raise CashoutWithdrawOutOfRangeException(
                type(self).__name__,
                "the amount must be within the range ($%s to $%s)" %
                (str(cashout.get_min()), str(cashout.get_max())))

        #
        # Checks to make sure we are not withdrawing more than we have
        ct = CashTransaction(self.user)
        balance = ct.get_balance_amount()
        if balance < amount:
            raise OverdraftException(self.user.username)

        #
        # Gets the profit for the year before the current withdrawal
        # and raises an exception if their tax information needs to
        # be collected.
        current_year_profit = ct.get_withdrawal_amount_current_year()
        if (current_year_profit + amount
            ) >= settings.DFS_CASH_WITHDRAWAL_AMOUNT_REQUEST_TAX_INFO:
            #
            # Checks to see if we collected tax information for the user
            tm = TaxManager(self.user)
            if not tm.info_collected():
                raise TaxInformationException(self.user.username)
Beispiel #4
0
 def validate_escrow_is_zero(self):
     ct = CashTransaction(AbstractManagerClass.get_escrow_user())
     ct.get_balance_amount()
     self.assertEqual(ct.get_balance_amount(), decimal.Decimal(0.0))
Beispiel #5
0
class RefundTest(AbstractTest, RefundBuildWorldMixin):
    def setUp(self):
        super().setUp()
        self.user1 = self.get_basic_user("test1")
        self.user2 = self.get_basic_user("test2")
        self.user3 = self.get_basic_user("test3")
        self.build_world()
        self.user1_ct = CashTransaction(self.user1)
        self.user1_ct.deposit(100)

        self.user2_ct = CashTransaction(self.user2)
        self.user2_ct.deposit(50)

        ta = TicketAmount.objects.get(amount=10.00)
        self.user3_tm = TicketManager(self.user3)
        self.user3_tm.deposit(10)

        self.escrow_user = self.user2_ct.get_escrow_user()

        self.escrow_ct = CashTransaction(self.escrow_user)

        bm = BuyinManager(self.user1)
        bm.buyin(self.contest_pool)

        bm = BuyinManager(self.user2)
        bm.buyin(self.contest_pool)

        bm = BuyinManager(self.user3)
        bm.buyin(self.contest_pool)
        Entry.objects.filter(contest_pool=self.contest_pool).update(
            contest=self.contest)

    def test_refund(self):

        self.assertEqual(self.user1_ct.get_balance_amount(), 90)
        self.assertEqual(self.user2_ct.get_balance_amount(), 40)
        self.assertEqual(self.escrow_ct.get_balance_amount(), 30)
        self.assertEqual(self.user3_tm.get_available_tickets().count(), 0)

        refund_manager = RefundManager()
        refund_manager.refund(self.contest, force=True)

        self.assertEqual(self.user1_ct.get_balance_amount(), 100)
        self.assertEqual(self.user2_ct.get_balance_amount(), 50)
        self.assertEqual(self.escrow_ct.get_balance_amount(), 0)
        self.assertEqual(self.user3_tm.get_available_tickets().count(), 1)

    # in progress should be refundable in cases
    # where its not a GPP and it did not fill
    # def test_contest_is_in_progress(self):
    #     self.contest.status = self.contest.INPROGRESS
    #     self.contest.save()
    #     self.should_raise_contest_is_in_progress_or_closed_exception()

    def test_contest_is_cancelled(self):
        self.contest.status = self.contest.CANCELLED
        self.contest.save()
        self.should_raise_contest_is_cancelled_or_closed()

    def test_contest_is_closed(self):
        self.contest.status = self.contest.CLOSED
        self.contest.save()
        self.should_raise_contest_is_cancelled_or_closed()

    # completed is an "in progress" status, which has
    # no more live inprogress games
    # def test_contest_is_completed(self):
    #     self.contest.status = self.contest.COMPLETED
    #     self.contest.save()
    #     self.should_raise_contest_is_in_progress_or_closed_exception()

    def should_raise_contest_is_cancelled_or_closed(self):

        self.assertEqual(self.user1_ct.get_balance_amount(), 90)
        self.assertEqual(self.user2_ct.get_balance_amount(), 40)
        self.assertEqual(self.escrow_ct.get_balance_amount(), 30)
        self.assertEqual(self.user3_tm.get_available_tickets().count(), 0)

        refund_manager = RefundManager()
        self.assertRaises(
            ContestCanNotBeRefunded,
            lambda: refund_manager.refund(self.contest, force=True))

        self.assertEqual(self.user1_ct.get_balance_amount(), 90)
        self.assertEqual(self.user2_ct.get_balance_amount(), 40)
        self.assertEqual(self.escrow_ct.get_balance_amount(), 30)
        self.assertEqual(self.user3_tm.get_available_tickets().count(), 0)
 def test_create_first_deposit(self):
     ct = CashTransaction(self.user)
     ct.deposit( self.amount )
     self.assertAlmostEquals( ct.get_balance_amount(), self.amount )
 def cash_balance(self):
     """
     Get the user's current cash balance.
     """
     cash_transaction = CashTransaction(self.user)
     return cash_transaction.get_balance_amount()