Esempio n. 1
0
class AccountBalanceTestCases(unittest.TestCase):
    def setUp(self):
        self.my_account = BankAccount(90)

    def test_balance(self):
        self.assertEqual(self.my_account.balance,
                         90,
                         msg='Account Balance Invalid')

    def test_deposit(self):
        self.my_account.deposit(90)
        self.assertEqual(self.my_account.balance,
                         180,
                         msg='Deposit method inaccurate')

    def test_withdraw(self):
        self.my_account.withdraw(40)
        self.assertEqual(self.my_account.balance,
                         50,
                         msg='Withdraw method inaccurate')

    def test_invalid_operation(self):
        self.assertEqual(self.my_account.withdraw(1000),
                         "invalid transaction",
                         msg='Invalid transaction')

    def test_sub_class(self):
        self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount),
                        msg='No true subclass of BankAccount')
Esempio n. 2
0
class BankAcount(unittest.TestCase):

    def setUp(self):
        self.ba = BankAccount("rado", 500, "$")

    def tearDown(self):
        pass

    def tets_create_new_BankAccount_class(self):
        self.assertEqual(self.ba.history(),"Account was created")
        self.assertTrue(isinstance(self.ba, BankAccount))

    def test_create_int_value_from_BankAccount(self):
        self.assertEqual(int(self.ba), 500)
    def test__str__in_BankAccount(self):
        self.assertEqual(str(self.ba),"Bank account for rado with balance of 500$")
    def test_balance(self):
        self.assertEqual(self.ba.balance(),500)
    def test_transfer_to(self):
        maria = BankAccount("Maria",200,"$")
        self.assertEqual(self.ba.transfer_to(maria,"$"),True)
        with self.assertRaises(TypeError) :
            self.ba.transfer_to("maria","$")
    def test_withdraw(self):
        self.assertTrue(self.ba.withdraw(200))
        self.assertFalse(self.ba.withdraw(900))
    def test_deposit(self):
        d = 1000
        self.ba.deposit(500)
        self.assertEqual(self.ba.balance(),1000)
class BankAccountTest(unittest.TestCase):

    def setUp(self):
        self.acc_name = "Ivan"
        self.acc_balance = 200
        self.acc_curr = "$"

        self.bank_acc = BankAccount(self.acc_name, self.acc_balance, self.acc_curr)
        self.test_dep_value = 1000
        self.test_str_dun = "Bank account for Ivan with balance of 200$"
        self.test_hist_str = ['Account was created', 'Deposited 1000$', 'Balance check -> 1200$', \
'__int__ check -> 1200$']

    def test_create_new_bank_instance(self):
        self.assertTrue(isinstance(self.bank_acc, BankAccount))

    def test_method_deposit(self):
        new_balance = self.bank_acc.balance() + self.test_dep_value
        self.bank_acc.deposit(self.test_dep_value)

        self.assertEqual(new_balance, self.bank_acc.balance())

    def test_method_balance(self):
        self.assertEqual(self.bank_acc.balance(), self.acc_balance)

    def test_str_dunder(self):
        self.assertEqual(self.test_str_dun, str(self.bank_acc))

    def test_history(self):
        self.bank_acc.deposit(self.test_dep_value)
        self.bank_acc.balance()
        int(self.bank_acc)
        self.assertEqual(self.bank_acc.history(), self.test_hist_str)
Esempio n. 4
0
class User:  # here's what we have so far
    def __init__(self, name, email):
        self.name = name
        self.email = email
        self.account = BankAccount(4.0)

    # adding the deposit method
    def make_deposit(
            self,
            amount):  # takes an argument that is the amount of the deposit
        self.account.deposit(amount)
        return self

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

    def display_user_balance(self):
        self.account.display_account_info()
        return self

    def transfer_money(self, other_user, amount):
        other_user.account.deposit(amount)
        self.account.withdraw(amount)
        return self
Esempio n. 5
0
class TestBankAccount(unittest.TestCase):  # test case
    """
    Unit Test for the BankAccount Class
    """
    def setUp(self):  # test fixture
        # print('setup called')
        self.ing = BankAccount('mila', 500)
        self.bnp = BankAccount('alex', 2000)

    def test_deposit(self):
        """ testing the deposit method """
        self.ing.deposit(200)
        self.bnp.deposit(500)

        self.assertEqual(self.ing.balance, 700)
        self.assertEqual(self.bnp.balance, 2500)

    def test_withdraw(self):
        """ testing the withdraw method """
        self.ing.withdraw(400)
        self.bnp.withdraw(1200)

        self.assertEqual(self.ing.balance, 100)
        self.assertEqual(self.bnp.balance, 800)

        self.assertRaises(ValueError, self.ing.withdraw, 500)
Esempio n. 6
0
class TestBankAccount(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Vladko", 2000, "RON")
        self.account1 = BankAccount("Phillip", 4114, "RON")

    def test_init(self):
        self.assertEqual(self.account.get_name(), "Vladko")
        self.assertEqual(self.account1.get_name(), "Phillip")
        self.assertEqual(self.account.get_currency(), "RON")
        self.assertTrue(self.account.get_currency() == self.account1.get_currency())

    def test_str(self):
        self.assertEqual(str(self.account), "Bank account for Vladko with balance of 2000 RON")
        self.assertEqual(str(self.account1), "Bank account for Phillip with balance of 4114 RON")

    def test_get_name(self):
        self.assertEqual(self.account.get_name(), "Vladko")

    def test_get_currency(self):
        self.assertEqual(self.account1.get_currency(), "RON")

    def test_int(self):
        self.assertEqual(int(self.account), 2000)
        self.assertEqual(int(self.account1), 4114)

    def test_history(self):
        self.assertEqual(self.account.history(), ['Account was created.'])

    def test_deposit(self):
        self.account.deposit(213)
        self.assertEqual(int(self.account), 2213)
        self.account1.deposit(400)
        self.assertEqual(int(self.account1), 4514)

    def test_balance(self):
        self.assertEqual(self.account.balance(), 2000)

    def test_withdraw(self):
        self.account.withdraw(1200)
        self.assertEqual(self.account.balance(), 800)
        self.account1.withdraw(10000)
        self.assertEqual(self.account1.balance(), 4114)

    def test_transfer(self):
        self.account1.transfer_to(self.account, 114)
        self.assertEqual(int(self.account), 2114)
        self.assertEqual(int(self.account1), 4000)

    def test_history(self):
        self.assertEqual(self.account.history(), ['Account was created.'])
class User:
    def __init__(self, name, email):
        self.name = name
        self.email = email
        self.account = BankAccount()

    def deposit(self, amount):
    	self.account.deposit(amount)
    def make_withdrawal(self, amount):
    	return self.account.withdraw(amount)
    def display_user_balance(self):
        self.account.display_account_info()
        print(f"{self.name} balance is:{self.balance}")
    def transfer_money(self,other_user,amount):
        if self.withdrawal(amount):
            other_user.deposit(amount)
            return True
        return False     
Esempio n. 8
0
class user:
    def _int_(self, name, year_of_birth, balance=0):
        self.name = name
        self.year_of_birth = year_of_birth
        self.account = BankAccount()

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

    def display_user_balance(self):
        print(f"{self.name} Balance is:", end=" ")

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

    def transfer_money(self, other_user, amount):
        if self.make_withdrawal(amount):
            other_user.deposit(amount)
            return True
        return False
Esempio n. 9
0
def main():
    populate_database()
    while True:
        try:
            # To Test please use 123,5678 or 6788
            customer_id = input(
                "Please enter customer ID, Use Cust_id=123 or 5678 or 6788: ")
            if not customer_id:
                break
            choice = int(input("Please enter 1-Deposit or 2-Withdraw: "))
            if choice == 1:
                b = BankAccount(cust_id=customer_id)
                amt = int(input("Please enter the amount to deposit: "))
                b.deposit(cust_id=customer_id, amount=amt)

            elif choice == 2:
                b = BankAccount(cust_id=customer_id)
                amt = int(input("Please enter the amount to withdraw: "))
                b.withdraw(cust_id=customer_id, amount=amt)
        except ValueError:
            print("Oops!  Invalid values  Try again...")
Esempio n. 10
0
class user:
    def __init__(self, name, email):
        self.name = name
        self.email = email
        self.account = BankAccount()

    def make_deposite(self, amount):
        self.account.deposit(amount)

    def make_withdrawal(self, amount=0):
        self.account.withdraw(amount)

    def display_user_balance(self):
        print("User Name: " + self.name + ", User Balance: ", end=" ")
        self.account.display_account_info()

    def transfer_money(self, other_user, amount):
        if self.make_withdrawal(amount):
            other_user.make_deposite(amount)
            return True
        return False
Esempio n. 11
0
# Class: 1321L
# Sec: 02
# Lab: Python
# Term: Fall 2018
# Instructor: Malcolm
# Name: Ly Pham

from BankAccount import BankAccount

myObject = BankAccount()
myObject.setID(123456)
myObject.setbalance(10000)
myObject.withdraw(3500)
myObject.deposit(500)
myObject.setannualInterestRate(2.50)
print(myObject.toString())

Esempio n. 12
0
            print(' OPTIONS:\n'
                  '1. Check Balance \n'
                  '2. Deposit \n'
                  '3. Withdraw \n'
                  '4. Spend \n')
            choice = input("what is your choice from the above options: ")
            print("you chose OPTION #: ", choice)

            if choice is '1':
                print("You have: $", my_account.balance,
                      "in your bank Account")

            elif choice is '2':
                newBalance = float(
                    input("How much are you depositing today?: "))
                my_account.deposit(newBalance)
                print("Your new Balance is: $", round(my_account.balance, 2))
                keepGo = input("Are you done with your transaction?:\n"
                               '1.yes\n'
                               '2.no\n')

                if keepGo is '2':
                    print(' OPTIONS:\n'
                          '1. Check Balance \n'
                          '2. Deposit \n'
                          '3. Withdraw \n'
                          '4. Spend \n')
                    choice = input(
                        "what is your choice from the above options: ")
                    print("you chose OPTION #: ", choice)
                    if choice is '1':
Esempio n. 13
0
from BankAccount_COVID19_company import BankAccount_COVID19_company

bank = Bank()
pl_01 = BankAccount('PL_01', 10000)
int_01 = BankAccount_INT('INT_01', 10000)
covid_01 = BankAccount_COVID19('COVID_01', 10000)
company_01 = BankAccount_COVID19_company('COMPANY_01', 10000)

for account in [pl_01, int_01, covid_01, company_01]:
  bank.add(account)
 
print(bank)

# BankAccount
print()
pl_01.deposit(200)
pl_01.withdraw(300)
print(pl_01)

try:
  pl_01.withdraw(50000)
except AccountException as e:
  print('Error:', e)

print()
print(pl_01)
pl_01.close()
try:
  pl_01.close()
except AccountException as e:
  print('Error: ', e)
Esempio n. 14
0
# A sample comment.  All comments start with #.

# Importing the classes we will use
# Format is: from <file name without .py> import <class name>
from BankAccount import BankAccount
from JointBankAccount import JointBankAccount
from CreditBankAccount import CreditBankAccount


# Create a BankAccount object and do a few transactions
# Notice "try/except" statement to handle exceptions raised
basicAccount = BankAccount("Sam Smith", 0)
print("At creation      : " + basicAccount.toString())

basicAccount.deposit(100)
print("After deposit 100: " + basicAccount.toString())

basicAccount.withdraw(50)
print("After withdraw 50: " + basicAccount.toString())

try:
    basicAccount.withdraw(75)
    print("After withdraw 75: " + basicAccount.toString())
except Exception as ex:
    print("Failed to withdraw 75: " + str(ex))


# Create a JointBankAccount account and do a few transactions
# Notice the "deposit()" and "withdraw()" calls are on JointBankAccount's
# parent class (since they are not defined in JointBankAccount) but the
Esempio n. 15
0
class TestBankAccout(unittest.TestCase):
    def setUp(self):
        self.name = "Rado"
        self.amount = 0
        self.currency = '$'
        self.my_account = BankAccount(self.name, self.amount, self.currency)
        self.deposited_money = 1000
        self.deposited_money_negative = -1000
        self.withdrawed_money_true = 500
        self.withdrawed_money_false = 1000
        self.transfered_money_true = 500
        self.transfered_money_false = 2000

    def test_init(self):
        self.assertTrue(isinstance(self.my_account, BankAccount))
        self.assertEqual(self.my_account.name, self.name)
        self.assertEqual(self.my_account.amount, self.amount)
        self.assertEqual(self.my_account.currency, self.currency)

    def test_deposit(self):
        current_balance = self.my_account.balance()
        self.my_account.deposit(self.deposited_money)
        self.assertEqual(self.my_account.amount,
                         current_balance + self.deposited_money)
        with self.assertRaises(ValueError):
            self.my_account.deposit(self.deposited_money_negative)

    def test_balance(self):
        self.assertEqual(self.my_account.balance(), self.my_account.amount)

    def test_withdraw(self):
        self.my_account.amount = 1000
        self.assertTrue(self.my_account.withdraw(self.withdrawed_money_true))
        self.assertFalse(self.my_account.withdraw(self.withdrawed_money_false))
        self.my_account.withdraw(self.withdrawed_money_false)
        self.my_account.amount = 1000
        current_balance = self.my_account.balance()
        self.assertEqual(self.my_account.balance(), current_balance)
        current_balance = self.my_account.balance()
        self.my_account.withdraw(self.withdrawed_money_true)
        self.assertEqual(self.my_account.balance(),
                         current_balance - self.withdrawed_money_true)

    def test_str(self):
        wanted_result = "Bank account for {} with balance of {}{}".format(
            self.my_account.name, self.my_account.amount,
            self.my_account.currency)
        self.assertEqual(str(self.my_account), wanted_result)

    def test_int(self):
        self.assertEqual(int(self.my_account), self.my_account.balance())

    def test_transfer_to(self):
        self.my_account.amount = 1000
        # CHECK CURRENCY
        ivo = BankAccount("Ivo", 0, "BGN")
        self.assertFalse(self.my_account.transfer_to(ivo, 600))
        ivo.currency = '$'
        # CHECK IF MONEY IS ENOUGH
        self.assertFalse(
            self.my_account.transfer_to(ivo, self.transfered_money_false))
        self.assertTrue(
            self.my_account.transfer_to(ivo, self.transfered_money_true))
        # CHECK IF MONEY HAS CHANGED, TRANSFERED
        ivo.amount = 0
        self.my_account.amount = 1000
        self.my_account.transfer_to(ivo, 200)
        self.assertEqual(self.my_account.balance(), 800)
        self.assertEqual(ivo.balance(), 200)

    def test_history(self):
        # Account Creation
        self.assertEqual(self.my_account.history()[0], 'Account was created')
        # Deposit
        self.my_account.deposit(1000)
        trueString = 'Deposited 1000' + self.my_account.currency
        self.assertEqual(self.my_account.history()[-1], trueString)
        # Balance
        self.my_account.balance()
        trueString = 'Balance check -> ' + \
            str(self.my_account.balance()) + self.my_account.currency
        self.assertEqual(self.my_account.history()[-1], trueString)
        # Int transformation
        trueString = '__int__ check -> ' + \
            str(self.my_account.balance()) + self.my_account.currency
        int(self.my_account)
        self.assertEqual(self.my_account.history()[-1], trueString)
        # Successfull withdraw
        self.my_account.withdraw(500)
        trueString = '500' + self.my_account.currency + \
            ' was withdrawed'
        self.assertEqual(self.my_account.history()[-1], trueString)
        # Failed withdraw
        self.my_account.withdraw(1000)
        trueString = 'Withdraw for {}{} failed.'.format(
            1000, self.my_account.currency)
        self.assertEqual(self.my_account.history()[-1], trueString)
        # Transfer
        ivo = BankAccount("Ivo", 0, "$")
        self.my_account = BankAccount("Rado", 1000, "$")
        self.my_account.transfer_to(ivo, 500)
        trueString_Rado = 'Transfer to {} for {}{}'.format(
            ivo.name, 500, self.my_account.currency)
        trueString_Ivo = 'Transer from {} for {}{}'.format(
            self.my_account.name, 500, ivo.currency)
        self.assertEqual(self.my_account.history()[-1], trueString_Rado)
        self.assertEqual(ivo.history()[-1], trueString_Ivo)
Esempio n. 16
0
# Insert new line here

# Importing the classes we will use
# Format is: from <file name without .py> import <class name>
from BankAccount import BankAccount
from JointBankAccount import JointBankAccount
from CreditBankAccount import CreditBankAccount


# Create a BankAccount object and do a few transactions
# Notice "try/except" statement to handle exceptions raised
basicAccount = BankAccount("Sam Smith", 0)
print("At creation      : " + basicAccount.toString())

basicAccount.deposit(100)
print("After deposit 100: " + basicAccount.toString())

basicAccount.withdraw(50)
print("After withdraw 50: " + basicAccount.toString())

try:
    basicAccount.withdraw(75)
    print("After withdraw 75: " + basicAccount.toString())
except Exception as ex:
    print("Failed to withdraw 75: " + str(ex))


# Create a JointBankAccount account and do a few transactions
# Notice the "deposit()" and "withdraw()" calls are on JointBankAccount's
# parent class (since they are not defined in JointBankAccount) but the