diff --git a/abcbank/account.py b/abcbank/account.py index e010009..3256b31 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,4 @@ -from abcbank.transaction import Transaction +from transaction import Transaction CHECKING = 0 SAVINGS = 1 @@ -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() @@ -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]) \ No newline at end of file + return sum([t.amount for t in self.transactions]) diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..bc3e4ea 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -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) @@ -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) \ No newline at end of file + assert_equals(oscar.numAccs(), 3)