Example #1
0
def withdraw_amount(amount):
    # if the customer attempts to withdraw above specified withdrawal limit

    if amount > MAX_WITHDRAWAL_PER_TRANS:
        print("Error: Attempted to make a withdrawal above KES 20,000")

    elif Transaction.number_of_withdrawals() > MAX_WITHDRAWAL_FREQ:
        print("Exceeded number of withdrawals. Please try again tomorrow.")

    else:
        balance = Transaction.query_balance() - amount
        new_trans = Transaction(balance, amount, 'withdraw')
        new_trans.save_transaction()

        if Transaction.amount_withdrawn_today() > MAX_WITHDRAWAL:
            new_trans.delete_transaction()
            print(
                "Exceeded amount of deposit in a day! Your Balance is KES {}".
                format(Transaction.query_balance()))
        else:
            print("-" * 70)
            print("Withdrawal successful! New balance is: KES {}".format(
                Transaction.query_balance()))
 def test_can_calculate_cumulative_withdrawal(self):
     self.first = Transaction(100, 10, 'withdraw')
     self.second = Transaction(10, 10, 'withdraw')
     self.first.save_transaction()
     self.second.save_transaction()
     self.assertEqual(Transaction.amount_withdrawn_today(), 20)
 def test_can_calculate_number_of_withdrawals_made(self):
     self.emergency = Transaction(100, 500, 'withdraw')
     self.salary = Transaction(100, 2000, 'withdraw')
     self.emergency.save_transaction()
     self.salary.save_transaction()
     self.assertTrue(Transaction.amount_withdrawn_today(), 2)