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
38 changes: 23 additions & 15 deletions abcbank/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abcbank.transaction import Transaction
from transaction import Transaction
from date_provider import DateProvider

CHECKING = 0
SAVINGS = 1
Expand All @@ -20,24 +21,31 @@ def withdraw(self, amount):
if (amount <= 0):
raise ValueError("amount must be greater than zero")
else:
self.transactions.append(Transaction(-amount))
if self.sumTransactions() >= amount:
self.transactions.append(Transaction(-amount))
else:
raise ValueError("Not sufficient amount in the account to withdraw")

def interestEarned(self):
amount = self.sumTransactions()
days_in_year = 365
actual_amount = self.sumTransactions()
amount = actual_amount
if self.accountType == SAVINGS:
if (amount <= 1000):
return amount * 0.001
else:
return 1 + (amount - 1000) * 0.002
for day in range((self.transactions[-1].transactionDate - self.transactions[0].transactionDate).days):
if amount <= 1000:
amount += amount * 0.001/days_in_year
else:
amount += 1 + (amount - 1000) * 0.002/days_in_year
if self.accountType == MAXI_SAVINGS:
if (amount <= 1000):
return amount * 0.02
elif (amount <= 2000):
return 20 + (amount - 1000) * 0.05
else:
return 70 + (amount - 2000) * 0.1
for each_transaction in self.transactions:
if (DateProvider.now() - each_transaction.transactionDate).days <= 10:
amount += amount * 0.001/days_in_year
else:
amount += amount * 0.05/days_in_year
else:
return amount * 0.001
for day in range((self.transactions[-1].transactionDate - self.transactions[0].transactionDate).days):
amount += amount * 0.001/days_in_year
return amount - actual_amount

def sumTransactions(self, checkAllTransactions=True):
return sum([t.amount for t in self.transactions])
return sum([t.amount for t in self.transactions])
1 change: 0 additions & 1 deletion abcbank/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def totalInterestPaid(self):
return total
def getFirstCustomer(self):
try:
self.customers = None
return self.customers[0].name
except Exception as e:
print(e)
Expand Down
16 changes: 16 additions & 0 deletions abcbank/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def withdrawalOrDepositText(self, transaction):
else:
return "N/A"

def transfer(self, from_acc, to_acc, transfer_amount):
result = False
try:
if len(self.accounts) > 1:
if from_acc.sumTransactions() >= transfer_amount:
from_acc.withdraw(transfer_amount)
to_acc.deposit(transfer_amount)
result = True
else:
raise ValueError("Amount in the from account is not sufficient")
else:
raise ValueError("More than one account needed for transfer")
except Exception as error:
print "ERROR : " + str(error)
return result


def _toDollars(number):
return "${:1.2f}".format(number)
2 changes: 0 additions & 2 deletions tests/bank_tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from nose.tools import assert_equals

from account import Account, CHECKING, MAXI_SAVINGS, SAVINGS
from bank import Bank
from customer import Customer


def test_customer_summary():
bank = Bank()
john = Customer("John").openAccount(Account(CHECKING))
Expand Down
45 changes: 42 additions & 3 deletions tests/customer_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from nose.tools import assert_equals, nottest

from nose.tools import assert_equals, nottest, raises
from bank import Bank
from account import Account, CHECKING, SAVINGS
from customer import Customer

Expand Down Expand Up @@ -33,4 +33,43 @@ 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)

bank = Bank()
checkingAccount = Account(CHECKING)
savingAccount = Account(SAVINGS)
bill = Customer("Bill")
bill.openAccount(checkingAccount)
bill.openAccount(savingAccount)
bank.addCustomer(bill)
checkingAccount.deposit(100.0)
checkingAccount.deposit(500.0)
checkingAccount.deposit(2000.0)
savingAccount.deposit(900.0)

from_acc = checkingAccount
to_acc = savingAccount

def test_transfer_success():
transfer_amount = 100
result = bill.transfer(from_acc, to_acc, transfer_amount)
assert_equals(result, True)
assert_equals(checkingAccount.sumTransactions(), 2500.0)
assert_equals(savingAccount.sumTransactions(), 1000.0)

@raises(ValueError)
def test_transfer_insufficient_balance_failure():
transfer_amount = 5000
result = bill.transfer(from_acc, to_acc, transfer_amount)

@raises(ValueError)
def test_transfer_insufficient_balance_failure():
checkingAccount_oscar = Account(CHECKING)
oscar = Customer("Oscar").openAccount(checkingAccount_oscar)
bank.addCustomer(oscar)
checkingAccount_oscar.deposit(100.0)
transfer_amount = 5000
from_acc = checkingAccount_oscar
to_acc = savingAccount
result = bill.transfer(from_acc, to_acc, transfer_amount)