Esempio n. 1
0
class BankAccountTest(unittest.TestCase):

    def setUp(self):
        self.account = BankAccount()

    def test_newly_opened_account_has_zero_balance(self):
        self.account.open()
        self.assertEqual(self.account.get_balance(), 0)

    def test_can_deposit_money(self):
        self.account.open()
        self.account.deposit(100)
        self.assertEqual(self.account.get_balance(), 100)

    def test_can_deposit_money_sequentially(self):
        self.account.open()
        self.account.deposit(100)
        self.account.deposit(50)

        self.assertEqual(self.account.get_balance(), 150)

    def test_can_withdraw_money(self):
        self.account.open()
        self.account.deposit(100)
        self.account.withdraw(50)

        self.assertEqual(self.account.get_balance(), 50)
Esempio n. 2
0
def main():
    args = sys.argv
    acc = BankAccount()

    # Format: python3 main.py --new account_type account_name
    if '--new' in args:
        pin = getpass.getpass('Please enter a 4 digit pin: ')
        pin_again = getpass.getpass('Please enter it again: ')
        if pin == pin_again:
            acc.new(name=args[3], type=args[2], pin=pin)

    # Format: python3 main.py --delete account_name
    elif '--delete' in args:
        pin = getpass.getpass('Please enter your 4 digit pin: ')
        if acc.check_pin(args[2], int(pin)):
            acc.delete(args[2])

    # Format: python3 main.py --deposit account_name amount
    elif '--deposit' in args:
        pin = getpass.getpass('Please enter your 4 digit pin: ')
        if acc.check_pin(args[2], int(pin)):
            acc.deposit(name=args[2], amount=float(args[3]))

    # Format: python3 main.py --withdraw account_name amount
    elif '--withdraw' in args:
        pin = getpass.getpass('Please enter a 4 digit pin: ')
        if acc.check_pin(args[2], int(pin)):
            acc.withdraw(name=args[2], amount=float(args[3]))

    # Format: python3 main.py --balance account_name
    elif '--balance' in args:
        pin = getpass.getpass('Please enter your 4 digit pin: ')
        if acc.check_pin(args[2], int(pin)):
            acc.balance(name=args[2])

    # Format: python3 main.py --upload account_name source_name file_path
    elif '--upload' in args:
        pin = getpass.getpass('Please enter a 4 digit pin: ')
        if acc.check_pin(args[2], int(pin)):
            acc.upload(args[2], args[4], args[3])

    else:
        print('Usage: python main.py --command')
Esempio n. 3
0
class TestBankAccount (unittest.TestCase):
 
	def setUp(self):
		self.account = BankAccount (100)
 
	def testBankAccountDeposit(self):
		test_balance = 170
		self.account.deposit (70)	
		self.assertEqual(self.account.balance, test_balance)
 
	def testBankAccountWithdraw(self):
		test_balance = 30
		self.account.withdraw (70)
		self.assertEqual(self.account.balance, test_balance)
		self.account.withdraw (270)
		self.assertEqual(self.account.balance, 0)
 
	def testBankAccountInterest(self):
		test_balance = 108.5
		self.account.interest (8.5)
		self.assertEqual(self.account.balance, test_balance)
Esempio n. 4
0
class AccountBalanceTestCase(unittest.TestCase):
    def test_account_owner(self):
        self.my_account = BankAccount()
        self.my_account.open_account("berinda")
        self.assertEqual(self.my_account.name, "berinda", msg="not owner")

    def test_deposit(self):
        self.my_account = BankAccount()
        self.my_account.deposit(80000)
        self.assertEqual(self.my_account.balance, 180000, msg="add more money")

    def test_withdraw(self):
        self.my_account = BankAccount()

        self.my_account.withdraw(50000)
        self.assertEqual(self.my_account.balance, 50000, msg="amount too big")

    def test_close_account(self):
        self.my_account = BankAccount()
        self.my_account.close_account()
        self.assertEqual(self.my_account.active, True, msg="account is closed")
Esempio n. 5
0
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount()

    def test_newly_opened_account_has_zero_balance(self):
        self.account.open()
        self.assertEqual(self.account.get_balance(), 0)

    def test_can_deposit_money(self):
        self.account.open()
        self.account.deposit(100)
        self.assertEqual(self.account.get_balance(), 100)

    def test_can_deposit_money_sequentially(self):
        self.account.open()
        self.account.deposit(100)
        self.account.deposit(50)

        self.assertEqual(self.account.get_balance(), 150)

    def test_can_withdraw_money(self):
        self.account.open()
        self.account.deposit(100)
        self.account.withdraw(50)

        self.assertEqual(self.account.get_balance(), 50)

    def test_can_withdraw_money_sequentially(self):
        self.account.open()
        self.account.deposit(100)
        self.account.withdraw(20)
        self.account.withdraw(80)

        self.assertEqual(self.account.get_balance(), 0)

    def test_checking_balance_of_closed_account_throws_error(self):
        self.account.open()
        self.account.close()

        with self.assertRaises(ValueError):
            self.account.get_balance()

    def test_deposit_into_closed_account(self):
        self.account.open()
        self.account.close()

        with self.assertRaises(ValueError):
            self.account.deposit(50)

    def test_withdraw_from_closed_account(self):
        self.account.open()
        self.account.close()

        with self.assertRaises(ValueError):
            self.account.withdraw(50)

    def test_cannot_withdraw_more_than_deposited(self):
        self.account.open()
        self.account.deposit(25)

        with self.assertRaises(ValueError):
            self.account.withdraw(50)

    def test_cannot_withdraw_negative(self):
        self.account.open()
        self.account.deposit(100)

        with self.assertRaises(ValueError):
            self.account.withdraw(-50)

    def test_cannot_deposit_negative(self):
        self.account.open()

        with self.assertRaises(ValueError):
            self.account.deposit(-50)
Esempio n. 6
0
from account import BankAccount
a = BankAccount('ganesh', 12, 2000)
a.deposit(1000)
a.deposit(2330)
a.withdraw(4000)
print a.get_balance()