Esempio n. 1
0
class User:
    def __init__(self, first_name: str, last_name: str):
        self.first_name = first_name
        self.last_name = last_name
        self.account = BankAccount(int_rate=.02, balance=0)

    def make_deposit(self, amount: int):
        self.account.deposit(amount)
        return self

    def make_withdrawal(self, amount: int):
        self.account.withdraw(amount)
        return self

    def display_user_balance(self):
        print(
            f"{self.first_name} {self.last_name}, Balance: ${self.account.balance}"
        )
        return self

    def transfer_money(self, other_user, amount: int):
        print(
            f"{self.first_name} {self.last_name} transferring ${amount} to {other_user.first_name} {other_user.last_name}"
        )
        self.make_withdrawal(amount)
        other_user.make_deposit(amount)
        return self
Esempio n. 2
0
class IBank(cmd.Cmd):
    '''Interactive Bank Application'''

    intro = "Welcome to the iBank"
    prompt = "bank> "

    account = None

    def account_valid(self):
        return self.account != None
    
    def do_new(self, line):
        '''Create an account'''
        if self.account_valid():
            raise RuntimeError("Account already exists.")
        else:
            line = line.strip()
            initial_balance = float(line) if len(line) > 0 else 0
            print "creating new account: initial balance =", initial_balance
            self.account = BankAccount(initial_balance)

    def do_deposit(self, line):
        '''deposit some money into account'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
            return

        print "depositing money:", line
        amount = float(line.strip())
        self.account.deposit(amount)
 
    def do_withdraw(self, line):
        '''withdraw some money from account'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
            return
        try:
            print "withdrawing money:", line
            amount = float(line.strip())
            self.account.withdraw(amount)
        except OverdrawnError:
            print "Nice try.  You don't have that much in the bank.  You have: ", self.account.balance


    def do_history(self, line):
        '''dump the account history'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
        else:
            print self.account.history

    def do_quit(self, line):
        '''exit the program'''
        return True

    def do_EOF(self, line):
        return True

    def postloop(self):
        print
class TestBankAcount(unittest.TestCase):
    def setUp(self):
            # Create a test BankAccount object
                self.account = BankAccount()     
            # Provide it with some property values        
                self.account.balance= 1000.0
    def test_legal_deposit_works(self):
        # deposit amount + into current balance.
       result = self.account.deposit_funds(500.0)
       self.assertEqual(self.account.balance,1500.0)
    def test_illegal_deposit_raises_exception(self):
        # deposit amount illegal amount like negative amount  
        self.assertRaises(ValueError ,self.account.deposit_funds,'fantastic')
        self.assertRaises(ValueError ,self.account.deposit_funds,'-145.0')
    def test_legal_withdrawal(self):
        #withdraw amount from current balance 
        self.account.withdraw_funds(100.0)
        self.assertEqual(self.account.balance,900.0)
    def test_illegal_withdrawal(self):
        # Your code here to test that withdrawing an illegal amount (like 'bananas'none)
         self.assertRaises(ValueError ,self.account.withdraw_funds,'anything')
         self.assertRaises(ValueError ,self.account.withdraw_funds,'-4.44')
    def test_insufficient_funds_withdrawal(self):
        #withdrawal fund is not more balance amount 
        self.assertRaises(ValueError ,self.account.withdraw_funds,3100.0)
        self.assertRaises(ValueError ,self.account.withdraw_funds,3100.78)        
Esempio n. 4
0
def index():

    user = BankAccount(session['username'], 0)

    rec_trans = []

    for x in user.recents():
        a, b, c = x

        fromz = tz.tzutc()

        toz = tz.tzlocal()

        utc = datetime.strptime(b, '%Y-%m-%d %H:%M:%S.%f')

        utc = utc.replace(tzinfo=fromz)

        b = utc.astimezone(toz)

        rec_trans.append([
            str(b.date()) + ' ' + str(b.hour) + ':' + str(b.minute) + ':' +
            str(b.second),
            str(c)
        ])

    rec_trans = list(reversed(rec_trans))[0:9]
    return render_template('index.html',
                           amount=str(user.getBalance()),
                           username=session['username'],
                           recents=convert(rec_trans))
Esempio n. 5
0
    def CreateAccount(self, bWantCard):
        obj = BankAccount(500)
        BankBranch.dctBankAccount[obj.getAccountNumber()] = obj

        #objATM = ATM()
        #objATM.ApplyCard(obj.getAccountNumber(), bWantCard)
        return obj.getAccountNumber()
Esempio n. 6
0
class IBank(cmd.Cmd):
    '''Interactive Bank Application'''

    intro = "Welcome to the iBank"
    prompt = "bank> "

    account = None

    def account_valid(self):
        return self.account != None

    def do_new(self, line):
        '''Create an account'''
        if self.account_valid():
            raise RuntimeError("Account already exists.")
        else:
            line = line.strip()
            initial_balance = float(line) if len(line) > 0 else 0
            print "creating new account: initial balance =", initial_balance
            self.account = BankAccount(initial_balance)

    def do_deposit(self, line):
        '''deposit some money into account'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
            return

        print "depositing money:", line
        amount = float(line.strip())
        self.account.deposit(amount)

    def do_withdraw(self, line):
        '''withdraw some money from account'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
            return
        try:
            print "withdrawing money:", line
            amount = float(line.strip())
            self.account.withdraw(amount)
        except OverdrawnError:
            print "Nice try.  You don't have that much in the bank.  You have: ", self.account.balance

    def do_history(self, line):
        '''dump the account history'''
        if not self.account_valid():
            print "No Account set up.  Do 'new' first."
        else:
            print self.account.history

    def do_quit(self, line):
        '''exit the program'''
        return True

    def do_EOF(self, line):
        return True

    def postloop(self):
        print
Esempio n. 7
0
 def do_new(self, line):
     '''Create an account'''
     if self.account_valid():
         raise RuntimeError("Account already exists.")
     else:
         line = line.strip()
         initial_balance = float(line) if len(line) > 0 else 0
         print "creating new account: initial balance =", initial_balance
         self.account = BankAccount(initial_balance)
Esempio n. 8
0
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # test for save file
        self.account.account_number = 1100
        self.account.pin_number = 1100

        # Provide it with some property values
        self.account.balance = 1000.0
Esempio n. 9
0
class TestBankAcount(unittest.TestCase):
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # Provide it with some property values
        self.account.balance = 1000.0

    def test_legal_deposit_works(self):
        # Your code here to test that depsositing money using the account's
        # 'deposit_funds' function adds the amount to the balance.
        previous_balance = self.account.balance
        self.account.deposit_funds(2000)
        self.assertGreater(self.account.balance, previous_balance)

    def test_illegal_deposit_raises_exception(self):
        # Your code here to test that depositing an illegal value (like 'bananas'
        # or such - something which is NOT a float) results in an exception being
        # raised.
        try:
            self.account.deposit_funds("bananas")
        except ValueError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:' + str(e))

    def test_legal_withdrawal(self):
        # Your code here to test that withdrawing a legal amount subtracts the
        # funds from the balance.
        previous_balance = self.account.balance
        self.account.withdraw_funds(100)
        self.assertLess(self.account.balance, previous_balance)

    def test_illegal_withdrawal(self):
        # Your code here to test that withdrawing an illegal amount (like 'bananas'
        # or such - something which is NOT a float) raises a suitable exception.
        try:
            self.account.withdraw_funds("apple")
        except ValueError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:' + str(e))

    def test_insufficient_funds_withdrawal(self):
        # Your code here to test that you can only withdraw funds which are available.
        # For example, if you have a balance of 500.00 dollars then that is the maximum
        # that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception
        # should be raised and the withdrawal should NOT be applied to the account balance
        # or the account's transaction list.
        try:
            self.account.withdraw_funds(5000000)
        except Exception as e:
            pass
Esempio n. 10
0
def withdraw():
    if re.match(r'\d+', request.form['amount']):

        user = BankAccount(session['username'], 0)

        user.withdraw(float(request.form['amount']))

        return redirect(url_for('index'))

    else:

        return redirect(url_for('index'))
Esempio n. 11
0
def transfer():

    if re.match(r'\d+', request.form['amount']):

        user = BankAccount(session['username'])

        user.transfer(float(request.form['amount']), request.form['target'])

        return redirect(url_for('index'))

    else:

        return redirect(url_for('index'))
def account(start_ammount):
    """
    Vytvoří účet s počátečním stavem 20000

    Fixture může používat jinou fixture
    """
    return BankAccount(start_ammount)
Esempio n. 13
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number
    global account_number
    filepath = ""

    pin_number = account_pin_entry.get()
    account_number = account_number_entry.get()
    filepath = filepath + account_number
    filepath = filepath + '.txt'
    try:
        ac_file = open(filepath, 'r')
        account.account_number = ac_file.readline().strip()
        account.pin_number = ac_file.readline().strip()
        account.balance = ac_file.readline().strip()
        account.interest_rate = ac_file.readline().strip()
        if not account.pin_number == pin_number:
            messagebox.showinfo("ERROR", "Invalid PIN")
            clear_details()
            account = BankAccount()
        else:
            transaction = ac_file.readline().strip()
            while transaction:
                account.transaction_list.append(transaction)
                transaction = ac_file.readline().strip()
            remove_all_widgets()
            create_account_screen()

    except IOError:
        messagebox.showinfo("ERROR", "Invalid Account Number")
        clear_details()
Esempio n. 14
0
 def do_new(self, line):
     '''Create an account'''
     if self.account_valid():
         raise RuntimeError("Account already exists.")
     else:
         line = line.strip()
         initial_balance = float(line) if len(line) > 0 else 0
         print "creating new account: initial balance =", initial_balance
         self.account = BankAccount(initial_balance)
Esempio n. 15
0
class User:  # declare a class and give it name User
    def __init__(self, username, email_address):
        self.name = username
        self.email = email_address
        self.account = BankAccount(int_rate=0.02, balance=0)

    def make_deposit(self, amount):
        self.account.deposit(amount)
        return self

    def make_withdrawl(self, amount):
        self.account.withdraw(amount)
        return self

    def display_user_balance(self):
        if self.account >= 0:
            print(f"User: {self.name}, Balance: ${round(self.account,2)}")
            return self
        else:
            print(f"User: {self.name}, Balance: -${round(self.account*-1,2)}")
            return self

    def transfer_money(self, other_user, amount):
        self.account.withdraw(amount)
        other_user.account.deposit(amount)
        print(
            f"{self.name} has successfully transferred ${amount} to {other_user.name}"
        )
        return self

#nina = User("Nina Gervaise Tompkin","*****@*****.**")
#guido = User("Guido Von Trapperson","*****@*****.**")
#dimitar = User("Dimitar Mi Ho","*****@*****.**")

    ninaAccount = BankAccount("0.006", "5000")
    guidoAccount = BankAccount("0.05", "1000")

    ninaAccount.deposit(400).deposit(12.99).deposit(35.23).withdraw(
        300).yield_interest().display_account_info()
    guidoAccount.deposit(200).deposit(300).withdraw(100).withdraw(
        40.23).withdraw(19.99).withdraw(
            99.99).yield_interest().display_account_info()


#nina.make_deposit(100).make_deposit(200).make_deposit(50).make_withdrawl(300).display_user_balance()

#dimitar.make_deposit(42.32).make_deposit(59.99).make_withdrawl(24.99).make_withdrawl(6.60).display_user_balance()

#guido.make_deposit(1024.41).make_withdrawl(543.20).make_withdrawl(42.31).make_withdrawl(245.99).display_user_balance()

#nina.transfer_money(guido,200).display_user_balance()
#guido.display_user_balance()
Esempio n. 16
0
 def create_bank_account(self, account_id, balance):
     bank_account = BankAccount(
         account_id, 
         self.bank_id, 
         self.currency, 
         balance, 
         self.transaction_queue
     )
     self.bank_accounts[account_id] = bank_account
     logger.debug(f'{self.bank_id}: Created account: {account_id}')
     return bank_account
Esempio n. 17
0
class TestBankAcount(unittest.TestCase):
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # Provide it with some property values
        self.account.balance = 1000.0

    def test_legal_deposit_works(self):
        # Your code here to test that depsositing money using the account's
        # 'deposit_funds' function adds the amount to the balance.
        deposit = self.account.deposit_funds('2000')
        self.assertEqual(deposit, '3000.0')

    def test_illegal_deposit_raises_exception(self):
        # Your code here to test that depositing an illegal value (like 'bananas'
        # or such - something which is NOT a float) results in an exception being
        # raised.
        self.assertRaises(ValueError, self.account.deposit_funds, 'deposit')

    def test_legal_withdrawal(self):
        # Your code here to test that withdrawing a legal amount subtracts the
        # funds from the balance.
        withdrawal = self.account.withdraw_funds('100')
        self.assertEqual(withdrawal, '900.0')

    def test_illegal_withdrawal(self):
        # Your code here to test that withdrawing an illegal amount (like 'bananas'
        # or such - something which is NOT a float) raises a suitable exception.
        self.assertRaises(ValueError, self.account.withdraw_funds,
                          'withdrawal')

    def test_insufficient_funds_withdrawal(self):
        # Your code here to test that you can only withdraw funds which are available.
        # For example, if you have a balance of 500.00 dollars then that is the maximum
        # that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception
        # should be raised and the withdrawal should NOT be applied to the account balance
        # or the account's transaction list.
        insufficient_money = self.account.withdraw_funds('2000')
        self.assertNotEqual(insufficient_money, '-1000')
def save_and_log_out():
        
    '''Function  to overwrite the account file with the current state of
       the account object (i.e. including any new transactions), remove
       all widgets and display the login screen.'''
    global account

    # Save the account with any new transactions
    #print(account)
    account.save_to_file()
    
    # Reset the bank acount object
    account = BankAccount()

    # Reset the account number and pin to blank
    account.account_number = ''
    account.pin_number = ''
    

    # Remove all widgets and display the login screen again    
    remove_all_widgets()
    create_login_screen()
Esempio n. 19
0
class User:		# here's what we have so far
    def __init__(self, name, email):
        self.name = name
        self.email = email
        self.account_balance = 0
        self.account = BankAccount(int_rate=0.02, balance=0)

    def example_method(self):
        # we can call the BankAccount instance's methods
        # self.account.deposit(100)
        # print(self.account.balance)
        pass

        # adding the deposit method
    def make_deposit(self, amount):  # takes an argument that is the amount of the deposit
        # the specific user's account increases by the amount of the value received
        self.account.deposit(amount)
        return self

    def make_withdrawal(self, amount):
        self.account.withdraw(amount)
        # if (amount < self.account_balance):
        #     self.account_balance -= amount
        # else:
        #     print(
        #         f'Sorry: {self.name}, requested amount is more than your balance.')
        return self

    def display_user_balance(self):
        print(f'User: {self.name}, Balance: ${self.account.balance}')
        return self

    def transfer_money(self, other_user, amount):
        if (amount < self.account.balance):
            self.account.withdraw(amount)
            other_user.make_deposit(amount)
        else:
            self.account.withdraw(amount)
        return self
def main():

    #Getting user's beginning balance through input
    balance = float(input("Enter beginning balance: "))
    #Making an object of the BankAccount class with the balance as he beginning value
    account = BankAccount(balance)
    #Getting user's desired amount to deposit
    deposit = float(input("How much were you paid this week? "))
    #Depositing the user's desired amount from the bank account object
    account.deposit(deposit)
    #Printing account's balance
    print(account)
    print()

    #Getting user's desired amount to withdraw
    withdraw = float(input("How much would you like to withdraw? "))
    #Withdrawing the user's desired amount from the bank account object
    account.withdraw(withdraw)
    #Printing account's balance
    print(account)
Esempio n. 21
0
 def test_balance(self):
     acc = BankAccount(100)
     self.assertEqual(100, acc.balance())
Esempio n. 22
0
#!/usr/bin/env python3

from bankaccount import BankAccount

account = BankAccount("Rado", 0, "$")
print(account)

print(account.deposit(1000))

print(account.balance())

print(str(account))

print(account.history())

print(account.withdraw(500))

print(account.balance())

print(account.history())

print(account.withdraw(1000))

print(account.balance())

print(int(account))

print(account.history())

Esempio n. 23
0
 def __init__(self, first_name: str, last_name: str):
     self.first_name = first_name
     self.last_name = last_name
     self.account = BankAccount(int_rate=.02, balance=0)
class TestBankAccount(unittest.TestCase):

    def setUp(self):
        self.account = BankAccount("Niki", 1350, "$")
        self.second_account = BankAccount("Vayne", 0, '$')
        self.account_diff_curr = BankAccount('Georgi', 260, 'e')

    def test_b_account_init(self):
        self.assertEqual(self.account.name, "Niki")
        self.assertEqual(self.account._balance, 1350)
        self.assertEqual(self.account.currency, "$")

    def test_b_account_str(self):
        self.assertEqual(str(self.account), 'Bank account for {} with balance of {}{}'.format(
            self.account.name, self.account._balance, self.account.currency))

    def test_b_account_int(self):
        self.assertEqual(int(self.account._balance), 1350)

    def test_b_account_deposit(self):
        self.account.deposit(100)
        self.assertEqual(self.account._balance, 1350 + 100)

    def test_b_account_balance(self):
        self.assertEqual(self.account._balance, 1350)

    def test_b_account_withdraw(self):
        self.assertTrue(self.account.withdraw(520))
        self.assertEqual(self.account._balance, 1350 - 520)

    def test_b_account_withdraw_with_no_balance(self):
        self.assertFalse(self.second_account.withdraw(300))

    def test_b_account_transfer_to_with_same_currencies(self):
        self.assertTrue(self.account.transfer_to(self.second_account, 400))
        self.assertEqual(self.account._balance, 1350 - 400)
        self.assertEqual(self.second_account._balance, 0 + 400)

    def test_b_account_transfer_to_with_diff_currencies(self):
        self.assertFalse(self.account.transfer_to(self.account_diff_curr, 400))
        self.assertFalse(self.account_diff_curr.transfer_to(self.account, 600))

        self.assertEqual(self.account._balance, 1350)
        self.assertEqual(self.second_account._balance, 0)

    def test_b_account_history(self):
        history_to_compare = ['Account was created']
        self.account.deposit(320)
        history_to_compare.append('Deposited 320{}'.format(
            self.account.currency))

        self.account.balance()
        history_to_compare.append('Balance check -> {}{}'.format(
            self.account._balance, self.account.currency))

        self.account.withdraw(20)
        history_to_compare.append('20{} was withdrawed'.format(
            self.account.currency))

        # check history when withdraw fail
        self.account.withdraw(100000000)
        history_to_compare.append('Withdraw for {}{} failed.'.format(
                100000000, self.account.currency))

        int(self.account)
        history_to_compare.append('__int__ check -> {}{}'.format(
            self.account._balance, self.account.currency))

        self.account.transfer_to(self.second_account, 400)

        # check other acc transfer history
        self.assertEqual('Transfer from {} for {}{}'.format(
            self.account.name, 400, self.account.currency),
            self.second_account.history()[len(self.second_account.history()) - 1])

        history_to_compare.append('Transfer to {} for {}{}'.format(
            self.second_account.name, 400, self.second_account.currency))
        self.assertEqual(self.account.history(), history_to_compare)
Esempio n. 25
0
 def __init__(self, name):
     self.monthly_interest = 0.1
     BankAccount.__init__(self, name)
Esempio n. 26
0
balance_label = tk.Label(win, textvariable=balance_var)

brand_title_var = tk.StringVar()
brand_title_var.set("FedUni Banking")
brand_label = None

# The Entry widget to accept a numerical value to deposit or withdraw
amount_entry_var = tk.StringVar('')
amount_entry = tk.Entry(win, textvariable=amount_entry_var)

# The transaction text widget holds text of the accounts transactions

transaction_text_widget = tk.Text(win, height=10, width=48)
scrolbar = tk.Scrollbar(win)
# The bank account object we will work with
account = BankAccount()

# ---------- Button Handlers for Login Screen ----------


def clear_pin_entry(event):
    '''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
    pin_number_var.set('')
    account_number_var.set('')
    # Clear the pin number entry here


def handle_pin_button(event):
    '''Function to add the number of the button clicked to the PIN number entry via its associated variable.'''
    data = pin_number_var.get()
    if len(data) < 4:
 def create_account_Test(self):
     testobj = BankAccount("Palqk", 0, "Shekel")
     self.assertEqual(("Palqk", 0, "Shekel"), (testobj._name, testobj.balance(), testobj._currency))
class TestBankAccount(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Niki", 1350, "$")
        self.second_account = BankAccount("Vayne", 0, '$')
        self.account_diff_curr = BankAccount('Georgi', 260, 'e')

    def test_b_account_init(self):
        self.assertEqual(self.account.name, "Niki")
        self.assertEqual(self.account._balance, 1350)
        self.assertEqual(self.account.currency, "$")

    def test_b_account_str(self):
        self.assertEqual(
            str(self.account),
            'Bank account for {} with balance of {}{}'.format(
                self.account.name, self.account._balance,
                self.account.currency))

    def test_b_account_int(self):
        self.assertEqual(int(self.account._balance), 1350)

    def test_b_account_deposit(self):
        self.account.deposit(100)
        self.assertEqual(self.account._balance, 1350 + 100)

    def test_b_account_balance(self):
        self.assertEqual(self.account._balance, 1350)

    def test_b_account_withdraw(self):
        self.assertTrue(self.account.withdraw(520))
        self.assertEqual(self.account._balance, 1350 - 520)

    def test_b_account_withdraw_with_no_balance(self):
        self.assertFalse(self.second_account.withdraw(300))

    def test_b_account_transfer_to_with_same_currencies(self):
        self.assertTrue(self.account.transfer_to(self.second_account, 400))
        self.assertEqual(self.account._balance, 1350 - 400)
        self.assertEqual(self.second_account._balance, 0 + 400)

    def test_b_account_transfer_to_with_diff_currencies(self):
        self.assertFalse(self.account.transfer_to(self.account_diff_curr, 400))
        self.assertFalse(self.account_diff_curr.transfer_to(self.account, 600))

        self.assertEqual(self.account._balance, 1350)
        self.assertEqual(self.second_account._balance, 0)

    def test_b_account_history(self):
        history_to_compare = ['Account was created']
        self.account.deposit(320)
        history_to_compare.append('Deposited 320{}'.format(
            self.account.currency))

        self.account.balance()
        history_to_compare.append('Balance check -> {}{}'.format(
            self.account._balance, self.account.currency))

        self.account.withdraw(20)
        history_to_compare.append('20{} was withdrawed'.format(
            self.account.currency))

        # check history when withdraw fail
        self.account.withdraw(100000000)
        history_to_compare.append('Withdraw for {}{} failed.'.format(
            100000000, self.account.currency))

        int(self.account)
        history_to_compare.append('__int__ check -> {}{}'.format(
            self.account._balance, self.account.currency))

        self.account.transfer_to(self.second_account, 400)

        # check other acc transfer history
        self.assertEqual(
            'Transfer from {} for {}{}'.format(self.account.name, 400,
                                               self.account.currency),
            self.second_account.history()[len(self.second_account.history()) -
                                          1])

        history_to_compare.append('Transfer to {} for {}{}'.format(
            self.second_account.name, 400, self.second_account.currency))
        self.assertEqual(self.account.history(), history_to_compare)
Esempio n. 29
0
from bankaccount import BankAccount

hauptkonto = BankAccount("DE123", "Marko")

sparkonto = BankAccount("DE4432", "Marko")

print(hauptkonto.buchungen)
print(hauptkonto.iban)
print(sparkonto.owner_name)

hauptkonto.buchen(1234, "EUR", "Gehalt")
hauptkonto.buchen(-12, "EUR", "Mittagessen")

print(hauptkonto.buchungen)
print(hauptkonto.getbalance())
Esempio n. 30
0
 def __init__(self):
     self._checkings = BankAccount()
     self._savings = BankAccount()
 def setUp(self):
     self.account = BankAccount("Niki", 1350, "$")
     self.second_account = BankAccount("Vayne", 0, '$')
     self.account_diff_curr = BankAccount('Georgi', 260, 'e')
Esempio n. 32
0
class Portfolio():
    def __init__(self):
        self._checkings = BankAccount()
        self._savings = BankAccount()

    def get_balance(self, account):
        if account == "C":
            self._checkings.getBalance()
        elif account == "S":
            self._savings.getBalance()

    def deposit(self, amount, account):
        if account == "C":
            self._checkings.deposit(amount)
        elif account == "S":
            self._savings.deposit(amount)

    def withdraw(self, amount, account):
        if account == "C":
            self._checkings.withdraw(amount)
        elif account == "S":
            self._savings.withdraw(amount)

    def transfer(self, amount, account):
        if account == "C":
            amount_to_transfer = self._checkings.withdraw(amount)
            self._savings.deposit(amount_to_transfer)
        elif account == "S":
            amount_to_transfer = self._savings.withdraw(amount)
            self._checkings.deposit(amount_to_transfer)
 def setUp(self):
     self.account = BankAccount("Niki", 1350, "$")
     self.second_account = BankAccount("Vayne", 0, '$')
     self.account_diff_curr = BankAccount('Georgi', 260, 'e')
Esempio n. 34
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number_var
    global account_number_var
    # Create the filename from the entered account number with '.txt' on the end
    filename = str(account_number_var.get()) + '.txt'

    # Try to open the account file for reading

    try:
        # Open the account file for reading
        fopen = open(filename, 'r')

        # First line is account number

        account.account_number = int(fopen.readline())

        # Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read

        account.pin_number = int(fopen.readline())

        assert int(pin_number_var.get()) == account.pin_number

        # Read third and fourth lines (balance and interest rate)

        account.balance = float(fopen.readline())
        account.interest_rate = float(fopen.readline())

        # Section to read account transactions from file - start an infinite 'do-while' loop here
        while True:
            # Attempt to read a line from the account file, break if we've hit the end of the file. If we
            # read a line then it's the transaction type, so read the next line which will be the transaction amount.
            # and then create a tuple from both lines and add it to the account's transaction_list
            transac_list = []
            check = fopen.readline()
            if check == '':
                break
            transac_list.append(check)
            transac_list.append(float(fopen.readline()))
            account.transaction_list.append(tuple(transac_list))

        # Close the file now we're finished with it
        fopen.close()

        # Catch exception if we couldn't open the file or PIN entered did not match account PIN
    except FileNotFoundError:

        # Show error messagebox and & reset BankAccount object to default...
        messagebox.showerror("Error",
                             "Invalid account number - please try again!")

        account = BankAccount()  # account  balance wiil call here

        #  ...also clear PIN entry and change focus to account number entry

        pin_number_var.set('')
        account_number_var.set('')

        return
    except AssertionError:
        messagebox.showerror("Error", "Wrong PIN entered!")
        account = BankAccount()
        pin_number_var.set('')
        account_number_var.set('')
        return

    except ValueError:
        messagebox.showerror("Error", "Enter some pin!")
        account = BankAccount()
        pin_number_var.set('')
        account_number_var.set('')
        return
        # return the value here

    # Got here without raising an exception? Then we can log in - so remove the widgets and display the account screen

    remove_all_widgets()
    create_account_screen()
Esempio n. 35
0
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # Provide it with some property values        
        self.account.balance        = 1000.0
Esempio n. 36
0
class Portfolio():
    def __init__(self):
        self._checkings = BankAccount()
        self._savings = BankAccount()

    def get_balance(self, account):
        if account == "C":
            self._checkings.getBalance()
        elif account == "S":
            self._savings.getBalance()

    def deposit(self, amount, account):
        if account == "C":
            self._checkings.deposit(amount)
        elif account == "S":
            self._savings.deposit(amount)

    def withdraw(self, amount, account):
        if account == "C":
            self._checkings.withdraw(amount)
        elif account == "S":
            self._savings.withdraw(amount)

    def transfer(self, amount, account):
        if account == "C":
            amount_to_transfer = self._checkings.withdraw(amount)
            self._savings.deposit(amount_to_transfer)
        elif account == "S":
            amount_to_transfer = self._savings.withdraw(amount)
            self._checkings.deposit(amount_to_transfer)
Esempio n. 37
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number_var
    global account_number_var

    read = event + '.txt'
    # Create the filename from the entered account number with '.txt' on the end
    # Try to open the account file for reading
    accept_loging = False
    try:
        with open(str(read),
                  'r') as account_file:  # Open the account file for reading

            account_number = account_file.readline(
            )[:-1]  # First line is account number

            account_pin = account_file.readline(
            )[:
              -1]  # Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read

            if account_pin != pin_number_var.get():
                raise ValueError("Pin doesnt match")
            else:
                accept_loging = True

            account_balance = float(account_file.readline(
            )[:-1])  # Read third and fourth lines (balance and interest rate)

            account_interest = float(account_file.readline()[:-1])
            transaction_list = []
            # Section to read account transactions from file - start an infinite 'do-while' loop here

            # Attempt to read a line from the account file, break if we've hit the end of the file. If we
            # read a line then it's the transaction type, so read the next line which will be the transaction amount.
            # and then create a tuple from both lines and add it to the account's transaction_list
            while True:
                _type = account_file.readline()[:-1]  # Attempt to read a line
                if not _type:  # If we failed, then exit
                    break
                _amount = float(account_file.readline()[:-1])

                transaction_list.append((_type.strip(), _amount))

            account.account_number = account_number
            account.account_pin = account_pin
            account.balance = account_balance
            account.account_interest = account_interest
            account.transaction_list = transaction_list
        # Close the file now we're finished with it (context manager is doing this for us)
    except ValueError:
        messagebox.showerror("Error", "Incorrect PIN")
        account = BankAccount()
        account.account_interest = .30
        account = account_number_var
        clear_pin_entry("event")
        account_number_entry.focus_force()
    except Exception:
        # Catch exception if we couldn't open the file or PIN entered did not match account PIN
        messagebox.showerror("Error", "file doesnt exists")
        account = BankAccount()
        clear_pin_entry("event")
        account_number_entry.focus_force()

        # Show error messagebox and & reset BankAccount object to default...

        #  ...also clear PIN entry and change focus to account number entry
    if accept_loging:
        remove_all_widgets()
        create_account_screen()
Esempio n. 38
0
 def __init__(self):
     self._checkings = BankAccount()
     self._savings = BankAccount()