コード例 #1
0
ファイル: test_bank.py プロジェクト: gianglc/Bank
 def setup_class(self):
     '''Setting up'''
     self.addr1 = Address('700 College Dr', 'Decorah', 'IA', '52101')
     self.addr2 = Address('1000 5th Ave', 'New York', 'NY', '10028')
     self.addr3 = Address('700 College Dr', 'Decorah', 'IA', '52101')
     self.customer1 = Customer('John Doe', '1861-09-01', self.addr1)
     self.customer2 = Customer('Jane Doe', '1861-09-02', self.addr1)
     self.check_acc = CheckingAccount(self.customer1, 15.00, 100.00)
     self.save_acc = SavingsAccount(self.customer2, 3.5, 200.00)
コード例 #2
0
def createBank(number=0):
    """Saves a bank with the specified number of accounts.
    Used during testing."""
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name' + str(i + 1), str(1000 + i), 100.00))
    bank.save("bank.dat")
コード例 #3
0
def main(number=0):
    """Instantiate a Bank and an ATM and run it."""
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name ' + str(i + 1), str(1000 + i), 100.00))
    atm = ATM(bank)
    atm.run()
    bank.save("bank.dat")
コード例 #4
0
def testBank(self,number = 0):
    '''Returns a bank with the specified number of accounts and/or
    the accounts loaded from the specified file name.'''
    bank = Bank()

    for i in xrange(number):
        bank.add(SavingsAccount('Name' + str(i + 1),str(1000 + i),100.00))
    return bank
コード例 #5
0
 def newAccount(self):
     name = self.nameField.getText()
     pin = self.pinField.getText()
     balance = self.balanceField.getNumber()
     newAccount = SavingsAccount(name, pin, balance)
     self.bank.add(newAccount)
     self.position = self.bank.getKeys().index(self.bank.makeKey(name, pin))
     self.displayAccount()
     self.statusField.setText("Account added.")
コード例 #6
0
ファイル: savings.py プロジェクト: smsamMG/test_project
 def withdraw(self, amount):
     """Restricts number of withdrawals to MAX_WITHDRAWALS."""
     if self._counter == RestricatedSavingsAccount.MAX_WITHDRAWALS:
         return "No more withdrawals this month"
     else:
         message = SavingsAccount.withdraw(self, amount)
         if message == None:
             self._counter += 1
         return message
コード例 #7
0
 def updateAccount(self):
     name = self.nameField.getText()
     pin = self.pinField.getText()
     balance = self.balanceField.getNumber()
     newAccount = SavingsAccount(name, pin, balance)
     self.bank.remove(self.account.getName(), self.account.getPin())
     self.bank.add(newAccount)
     self.position = self.bank.getKeys().index(self.bank.makeKey(name, pin))
     self.displayAccount()
     self.statusField.setText("Account updated.")
コード例 #8
0
ファイル: savings.py プロジェクト: gregpuzzles1/Sandbox
 def withdraw(self, amount):
     """Restricts number of withdrawals to MAX_WITHDRAWALS."""
     if self._counter == \
        RestrictedSavingsAccount.MAX_WITHDRAWALS:
         return "No more withdrawals this month"
     else:
         message = SavingsAccount.withdraw(self, amount)
         if message == None:
             self._counter += 1
         return message
コード例 #9
0
ファイル: atm.py プロジェクト: smsamMG/test_project
def main(number):
    bank = Bank()
    for i in range(number):
        bank.add(SavingsAccount('Name' + str(i + 1),
                                str(1000 + i),
                                100.00))

    """Instantiate a bank and use it in an ATM."""
    
    print("The bank has been loaded")
    
    atm = ATM(bank)
    print("Running the GUI")
    atm.mainloop()
    
    bank.save('bank.dat')
    bank.__init__("bank.dat")
    
    print("The bank has been updated")
コード例 #10
0
ファイル: main.py プロジェクト: faith7/Data_Projects
def create_savings_account(c):
    print("Enter Savings Account_id")
    try:
        savings_id = int(input())
    except ValueError:
        print("Please enter an integer number")
    if c.cust_id in customers and savings_id in savings:
        print("Savings Account ID aleady exists")
        print(savings[savings_id].getAccountInfo())
        return savings[savings_id]

    # Or savings id is new, request additonal information
    else:
        print("Type opening balance")
        opening_balance = int(input())
        print("Type min balance")
        min_balance = int(input())
        s1 = SavingsAccount(savings_id, c, opening_balance, min_balance)
        savings[savings_id] = s1
        return s1
コード例 #11
0
ファイル: test_bank.py プロジェクト: akash-011/bank_tdd
 def setUp(self):
     self.savings_account = SavingsAccount()
コード例 #12
0
ファイル: test_bank.py プロジェクト: akash-011/bank_tdd
class TestSaving(unittest.TestCase):
    """ Tests SavingsAccount Class  """

    #create global variables
    def setUp(self):
        self.savings_account = SavingsAccount()
    
    #test the account is a child of the bank account class
    def test_create_savings_account(self):
        self.assertTrue(self.savings_account, BankAccount)
    
    #test add person
    def test_add_person(self):
        self.assertEqual(self.savings_account.add_person("Adams Kariuki"), "Person Successfully Added")
    
    #test add invalid person
    def test add_invalid_person(self):
        error = "Invalid Account Name"
        self.assertEqual(self.savings_account.add_person(""), error)
        self.assertEqual(self.savings_account.add_person("A@@ "), error)
        self.assertEqual(self.savings_account.add_person(68768), error)

    #test successful deposit    
    def test_savings_deposit(self):
        self.savings_account.deposit(5000)
        self.assertEqual(self.savings_account.balance, 5000)
    
    #test invalid deposit amounts
    def test_saving_deposit_invalid(self):
        deposit_error_message = "Invalid Deposit amount"
        self.assertEqual(self.savings_account.deposit(-100), deposit_error_message)
        self.assertEqual(self.savings_account.deposit('ak122'), deposit_error_message)
        self.assertEqual(self.savings_account.deposit(0), deposit_error_message)
        self.assertEqual(self.savings_account.balance, 0)
    
    #test successful withdraw
    def test_savings_withdraw(self):
        self.savings_account.deposit(5000)
        self.savings_account.withdraw(3000)
        self.assertEqual(self.savings_account.balance, 2000)
    
    #test invalid withdraw amounts
    def test_savings_withdraw_invalid(self):
        withdraw_error_message = "Invalid Withdraw Amount"
        self.assertEqual(self.savings_account.withdraw('lk2000'), withdraw_error_message)
        self.assertEqual(self.savings_account.withdraw(0), withdraw_error_message)
        self.assertEqual(self.savings_account.withdraw(-100), withdraw_error_message)
        self.assertEqual(self.savings_account.balance, 0)
    
    #test account overdrafts
    def test_savings_overdraft(self):
        self.savings_account.withdraw(9000) 
        self.assertGreaterEqual(self.savings_account.balance, -3000, msg='Overdraft Exceeded. Overdraft Limit is 3000 KES') 
コード例 #13
0
ファイル: savings.py プロジェクト: smsamMG/test_project
 def __init__(self, name, pin, balance=0.0):
     """Same attributes as SavingSAccount, but with
     a counter for withdrawals."""
     SavingsAccount.__init__(self, name, pin, balance)
     self._counter = 0
コード例 #14
0
ファイル: savings.py プロジェクト: gregpuzzles1/Sandbox
 def __init__(self, name, pin, balance = 0.0):
     """Same attributes as SavingsAccount, but with
     a counter for withdrawals."""
     SavingsAccount.__init__(self, name, pin, balance)
     self._counter = 0
コード例 #15
0
ファイル: test_bank.py プロジェクト: gianglc/Bank
class TestBankingMethods:
    '''Testing module banking'''
    @pytest.fixture(scope='function', autouse=True)
    def setup_class(self):
        '''Setting up'''
        self.addr1 = Address('700 College Dr', 'Decorah', 'IA', '52101')
        self.addr2 = Address('1000 5th Ave', 'New York', 'NY', '10028')
        self.addr3 = Address('700 College Dr', 'Decorah', 'IA', '52101')
        self.customer1 = Customer('John Doe', '1861-09-01', self.addr1)
        self.customer2 = Customer('Jane Doe', '1861-09-02', self.addr1)
        self.check_acc = CheckingAccount(self.customer1, 15.00, 100.00)
        self.save_acc = SavingsAccount(self.customer2, 3.5, 200.00)

    def test_address(self):
        '''Testing address properties'''
        assert self.addr1.street == '700 College Dr'
        assert self.addr1.city == 'Decorah'
        assert self.addr1.state == 'IA'
        assert self.addr1.zip == '52101'

    def test_address_str(self, capsys):
        '''Testing address.__str__ method'''
        print(self.addr1)
        out, err = capsys.readouterr()
        assert out.strip() == ('700 College Dr\nDecorah, IA 52101')

    def test_address_eq(self):
        '''Testing address.__eq__ method'''
        assert self.addr1 != self.addr2
        assert self.addr1 is not self.addr3
        assert self.addr1 == self.addr3

    def test_customer(self):
        '''Testing customer properties'''
        assert self.customer1.name == 'John Doe'
        assert self.customer1.dob == '1861-09-01'
        assert self.customer1.address == Address('700 College Dr', 'Decorah',
                                                 'IA', '52101')

    def test_customer_str(self, capsys):
        '''Testing customer.__str__ method'''
        print(self.customer1)
        out, err = capsys.readouterr()
        assert out.strip() == ('John Doe (1861-09-01)\n' +
                               '700 College Dr\nDecorah, IA 52101')

    def test_customer_move(self, capsys):
        '''Testing customer.move method'''
        self.customer1.move(self.addr2)
        assert self.customer1.address == Address('1000 5th Ave', 'New York',
                                                 'NY', '10028')
        print(self.customer1)
        out, err = capsys.readouterr()
        assert out.strip() == ('John Doe (1861-09-01)\n' + '1000 5th Ave\n' +
                               'New York, NY 10028')

    #Raises TypeError -- Account is abstract, cannot be instantiated
    def test_abstract_class_Account(self):
        with pytest.raises(TypeError) as excinfo:
            self.acc = Account(self.customer1, 500)
        exception_msg = excinfo.value.args[0]
        assert exception_msg == 'Can\'t instantiate abstract class Account with abstract methods __init__'

    def test_account(self):
        '''Testing account properties'''
        assert self.check_acc.owner == self.customer1
        assert self.save_acc.owner == self.customer2
        assert self.check_acc.balance == pytest.approx(100, 0.01)
        assert self.save_acc.balance == pytest.approx(200, 0.01)

    def test_account_deposit(self):
        '''Testing account.deposit method'''
        self.check_acc.deposit(60)
        assert self.check_acc.balance == pytest.approx(160, 0.01)
        self.save_acc.deposit(60)
        assert self.save_acc.balance == pytest.approx(260, 0.01)

    def test_account_deposit_error(self):
        with pytest.raises(ValueError) as excinfo:
            self.check_acc.deposit(-10)
        exception_msg = excinfo.value.args[0]
        assert exception_msg == 'Must deposit positive amount'

    def test_account_close(self):
        '''Testing account.close method'''
        self.check_acc.close()
        assert self.check_acc.balance == pytest.approx(0, 0.01)
        self.save_acc.close()
        assert self.save_acc.balance == pytest.approx(0, 0.01)

    def test_checking_process_check(self):
        '''Testing check processing method'''
        assert self.check_acc.balance == pytest.approx(100, 0.01)
        self.check_acc.process_check(30)
        assert self.check_acc.balance == pytest.approx(70, 0.01)
        self.check_acc.process_check(80)
        assert self.check_acc.balance == pytest.approx(55, 0.01)

    def test_checking_str(self, capsys):
        '''Testing checking.__str__ method'''
        print(self.check_acc)
        out, err = capsys.readouterr()
        assert out.strip() == ('Checking account\n' +
                               'Owner: John Doe (1861-09-01)\n' +
                               '700 College Dr\n' + 'Decorah, IA 52101\n' +
                               'Balance: 100.00')

    def test_savings_yield_interest(self):
        '''Testing check processing method'''
        assert self.save_acc.balance == pytest.approx(200.00, 0.01)
        self.save_acc.yield_interest()
        assert self.save_acc.balance == pytest.approx(207.00, 0.01)

    def test_savings_str(self, capsys):
        '''Testing savings.__str__ method'''
        print(self.save_acc)
        out, err = capsys.readouterr()
        assert out.strip() == ('Savings account\n' +
                               'Owner: Jane Doe (1861-09-02)\n' +
                               '700 College Dr\n' + 'Decorah, IA 52101\n' +
                               'Balance: 200.00')
コード例 #16
0
from bank import SavingsAccount

acc1 = SavingsAccount("VD", 1000, 10000, 1000)
acc1.show_balance()
acc1.deposit(5000)
acc1.show_balance()
acc1.withdraw(8000)
acc1.show_balance()
acc1.withdraw(6000)
acc1.show_balance()