Esempio n. 1
0
    def test_transfer_funds_error_insufficient_funds(self):
        # Create two accounts and deposit funds.
        account_id1 = self.accounts.create_account()
        account_id2 = self.accounts.create_account()
        self.commands.deposit_funds(account_id1, Decimal("200.00"))

        # Fail to transfer funds - insufficient funds.
        transaction_id = self.commands.transfer_funds(
            debit_account_id=account_id1,
            credit_account_id=account_id2,
            amount=Decimal("1000.00"),
        )

        # Check saga errored.
        self.assertFalse(self.sagas.get_saga(transaction_id).has_succeeded)
        self.assertTrue(self.sagas.get_saga(transaction_id).has_errored)
        errors = self.sagas.get_saga(transaction_id).errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0],
                         InsufficientFundsError({"account_id": account_id1}))

        # Check balances - should be unchanged.
        self.assertEqual(self.accounts.get_balance(account_id1),
                         Decimal("200.00"))
        self.assertEqual(self.accounts.get_balance(account_id2),
                         Decimal("0.00"))
Esempio n. 2
0
    def test_overdraft_limit(self):
        # Create an account and deposit funds.
        account_id1 = self.accounts.create_account()
        self.commands.deposit_funds(account_id1, Decimal("200.00"))

        # Check overdraft limit.
        self.assertEqual(self.accounts.get_overdraft_limit(account_id1),
                         Decimal("0.00"))

        # Set overdraft limit.
        self.accounts.set_overdraft_limit(account_id=account_id1,
                                          overdraft_limit=Decimal("500.00"))

        # Can't set negative overdraft limit.
        with self.assertRaises(AssertionError):
            self.accounts.set_overdraft_limit(
                account_id=account_id1, overdraft_limit=Decimal("-500.00"))

        # Check overdraft limit.
        self.assertEqual(self.accounts.get_overdraft_limit(account_id1),
                         Decimal("500.00"))

        # Withdraw funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("500.00"))

        # Check saga succeeded.
        self.assertTrue(self.sagas.get_saga(transaction_id).has_succeeded)
        self.assertFalse(self.sagas.get_saga(transaction_id).has_errored)
        self.assertFalse(self.sagas.get_saga(transaction_id).errors)

        # Check balance - should be overdrawn.
        self.assertEqual(self.accounts.get_balance(account_id1),
                         Decimal("-300.00"))

        # Fail to withdraw funds - insufficient funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("200.01"))

        # Check saga errored.
        self.assertFalse(self.sagas.get_saga(transaction_id).has_succeeded)
        self.assertTrue(self.sagas.get_saga(transaction_id).has_errored)
        errors = self.sagas.get_saga(transaction_id).errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0],
                         InsufficientFundsError({"account_id": account_id1}))

        # Check balance.
        self.assertEqual(self.accounts.get_balance(account_id1),
                         Decimal("-300.00"))

        # Close account.
        self.accounts.close_account(account_id1)

        # Fail to set overdraft limit - account closed.
        with self.assertRaises(AccountClosedError):
            self.accounts.set_overdraft_limit(
                account_id=account_id1, overdraft_limit=Decimal("5000.00"))
    def test_overdraft_limit(self):
        # Create an account and deposit funds.
        account_id1 = self.accounts.create_account()
        transaction_id = self.commands.deposit_funds(account_id1,
                                                     Decimal("200.00"))
        self.assertSagaHasSucceeded(transaction_id)

        # Check overdraft limit.
        self.assertEqual(self.accounts.get_overdraft_limit(account_id1),
                         Decimal("0.00"))

        # Set overdraft limit.
        self.accounts.set_overdraft_limit(account_id=account_id1,
                                          overdraft_limit=Decimal("500.00"))

        # Can't set negative overdraft limit.
        with self.assertRaises(AssertionError):
            self.accounts.set_overdraft_limit(
                account_id=account_id1, overdraft_limit=Decimal("-500.00"))

        # Check overdraft limit.
        self.assertEqual(self.accounts.get_overdraft_limit(account_id1),
                         Decimal("500.00"))

        # Withdraw funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("500.00"))

        # Check saga succeeded.
        self.assertSagaHasSucceeded(transaction_id)

        # Check balance - should be overdrawn.
        self.assertBalanceEquals(account_id1, Decimal("-300.00"))

        # Fail to withdraw funds - insufficient funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("200.01"))

        # Check saga errored.
        self.assertSagaHasNotSucceeded(
            transaction_id,
            [InsufficientFundsError({"account_id": account_id1})])

        # Check balance.
        self.assertBalanceEquals(account_id1, Decimal("-300.00"))

        # Close account.
        self.accounts.close_account(account_id1)

        # Fail to set overdraft limit - account closed.
        with self.assertRaises(AccountClosedError):
            self.accounts.set_overdraft_limit(
                account_id=account_id1, overdraft_limit=Decimal("5000.00"))
    def test_withdraw_funds_error_insufficient_funds(self):
        # Create an account and deposit funds.
        account_id1 = self.accounts.create_account()
        self.commands.deposit_funds(account_id1, Decimal("200.00"))

        # Fail to withdraw funds - insufficient funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("200.01"))

        # Check saga errored.
        self.assertSagaHasNotSucceeded(
            transaction_id,
            [InsufficientFundsError({"account_id": account_id1})])

        # Check balance.
        self.assertBalanceEquals(account_id1, Decimal("200.00"))
Esempio n. 5
0
    def test_withdraw_funds_error_insufficient_funds(self):
        # Create an account and deposit funds.
        account_id1 = self.accounts.create_account()
        self.commands.deposit_funds(account_id1, Decimal("200.00"))

        # Fail to withdraw funds - insufficient funds.
        transaction_id = self.commands.withdraw_funds(account_id1,
                                                      Decimal("200.01"))

        # Check saga errored.
        self.assertFalse(self.sagas.get_saga(transaction_id).has_succeeded)
        self.assertTrue(self.sagas.get_saga(transaction_id).has_errored)
        errors = self.sagas.get_saga(transaction_id).errors
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0],
                         InsufficientFundsError({"account_id": account_id1}))

        # Check balance.
        self.assertEqual(self.accounts.get_balance(account_id1),
                         Decimal("200.00"))
    def test_transfer_funds_error_insufficient_funds(self):
        # Create two accounts and deposit funds.
        account_id1 = self.accounts.create_account()
        account_id2 = self.accounts.create_account()
        self.commands.deposit_funds(account_id1, Decimal("200.00"))

        # Fail to transfer funds - insufficient funds.
        transaction_id = self.commands.transfer_funds(
            debit_account_id=account_id1,
            credit_account_id=account_id2,
            amount=Decimal("1000.00"),
        )

        # Check saga errored.
        self.assertSagaHasNotSucceeded(
            transaction_id,
            [InsufficientFundsError({"account_id": account_id1})])

        # Check balances - should be unchanged.
        self.assertBalanceEquals(account_id1, Decimal("200.00"))
        self.assertBalanceEquals(account_id2, Decimal("0.00"))
Esempio n. 7
0
 def check_has_sufficient_funds(self, amount: Decimal) -> None:
     if self.balance + amount < -self.overdraft_limit:
         raise InsufficientFundsError({"account_id": self.id})