Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions abcbank/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abcbank.transaction import Transaction
from transaction import Transaction

CHECKING = 0
SAVINGS = 1
Expand All @@ -20,7 +20,25 @@ def withdraw(self, amount):
if (amount <= 0):
raise ValueError("amount must be greater than zero")
else:
self.transactions.append(Transaction(-amount))
# check for withdrawal over available funds - overdraft
if (self.sumTransactions() < amount):
raise ValueError("amount greater than avail funds")
else:
self.transactions.append(Transaction(-amount))

def transferFunds(self, Account_t, amount):
"""
The account you are transferring to is Account_t
(ie: savings, checking,maxi-savings). the self represents
the account you are transferring from. amount is
how much is being transferred
"""
try:
self.withdraw(amount) # call self's withdraw method
Account_t.deposit(amount) # call the destination account deposit
except ValueError as err:
raise ValueError("transfer exception: "+err[0])


def interestEarned(self):
amount = self.sumTransactions()
Expand All @@ -40,4 +58,4 @@ def interestEarned(self):
return amount * 0.001

def sumTransactions(self, checkAllTransactions=True):
return sum([t.amount for t in self.transactions])
return sum([t.amount for t in self.transactions])
15 changes: 14 additions & 1 deletion tests/customer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ def test_statement():
"\n\nTotal In All Accounts $3900.00")


def test_transfer():
checkingAccount = Account(CHECKING)
savingsAccount = account(SAVINGS)
henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount)
checkingAccount.deposit(100.0)
savingsAccount.deposit(4000.0)
savingsAccount.transferFunds(checkingAccount, 200.0)
assert_equals(henry.getStatement(),
"Statement for Henry" +
"\n\nChecking Account\n deposit $100.00\n deposit $200.00\nTotal $300.00" +
"\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" +
"\n\nTotal In All Accounts $4100.00")

def test_oneAccount():
oscar = Customer("Oscar").openAccount(Account(SAVINGS))
assert_equals(oscar.numAccs(), 1)
Expand All @@ -33,4 +46,4 @@ def test_twoAccounts():
def test_threeAccounts():
oscar = Customer("Oscar").openAccount(Account(SAVINGS))
oscar.openAccount(Account(CHECKING))
assert_equals(oscar.numAccs(), 3)
assert_equals(oscar.numAccs(), 3)