class TestJohnCrediteSonCompte(unittest.TestCase): def setUp(self): self.storage = mock() self.account = Account(self.storage) def test_credit_du_compte_positivement(self): """Test l'accreditement d'un compte""" amount = 100 self.account.credit(amount) verify(self.storage).insert(amount) def test_historique(self): when(self.storage).select().thenReturn([]) history = self.account.historique() self.assertEquals(history, self.account.operations) def test_can_accept_credit_valeur_positive(self): """Test si un compte accepte un credit sur valeur positive""" amount = 1 self.assertTrue(self.account.can_accept_credit(amount)) def test_can_accept_credit_valeur_negative(self): """Test si un compte accepte un credit sur valeur negative""" amount = -1 self.assertFalse(self.account.can_accept_credit(amount)) def test_credit_du_compte_negativement(self): """Test l'accreditement d'un compte negativement""" amount = -10 self.assertRaises(ValueError, self.account.credit, amount)
def test_debit_du_compte_positivement(self): """Test le debit d'un compte avec une valeur positive""" storage = mock() when(storage).select().thenReturn([105]) account = Account(storage) amount = 100 account.debit(amount) verify(storage).insert(-amount)
def test_account(): """Test account class.""" person1 = Person("Ellina", "Gedrojets", 18) person2 = Person("Robert", "Soidla", 19) bank1 = Bank("Swed") bank2 = Bank("LHV") acc1 = Account(20, person1, bank1) acc2 = Account(100, person2, bank2) assert len(acc1.number) == 20 assert acc2._balance == 100
def __init__(self, uni): self.client = Account('balance.txt') self.universe = uni self.available_cash = self.client.get_balance() # update for leverage self.number_units_sought = 20 # base on execution threads or pipes self.current_transaction_amount = 0 self.commission_rate = 0.01 self.order_type = ["limit", "market"] self.last_transactions = LifoQueue( ) # provides me a put and get method
class TestAccountOverdraft(unittest.TestCase): def setUp(self): self.client = Client(1, "2017-09-21", 1, "Olivier", "LON") self.account = Account(1, self.client) def testIsOverdraft(self): plus = self.account.overdraft is False self.account.withdraw(200) minus = self.account.overdraft is False self.assertEqual((plus, minus), (True, True))
def test_transaction(): """Test transaction class.""" person1 = Person("Ellina", "Gedrojets", 18) person2 = Person("Robert", "Soidla", 19) bank1 = Bank("Swed") bank2 = Bank("LHV") acc1 = Account(20, person1, bank1) acc2 = Account(100, person2, bank2) tr1 = Transaction(10, datetime.date.today(), acc1, acc2, False) tr2 = Transaction(20, datetime.date.today(), acc1, acc1, True) assert tr1.__repr__() == "(10 €) Ellina Gedrojets -> Robert Soidla" assert tr2.__repr__() == "(20 €) ATM"
def test_account(): """Test Account class.""" p1 = Person('Jack', 'Jackson', 19) p2 = Person('Anna', 'Dark', 194) b1 = Bank('NotSwedBank') b2 = Bank('CoolerThanLHV') p1_acc = Account(100, p1, b1) p2_acc = Account(25, p2, b2) assert len(p1_acc.number[2:]) == 18 assert p1_acc.number[2] assert p1_acc.balance == 100 assert p2_acc.balance == 25
def test_credit_turnover(): """Test get_credit_turnover method in Account class.""" p1 = Person('Jack', 'Jackson', 19) b1 = Bank('NotSwedBank') p1_acc = Account(100, p1, b1) p1_acc = Account(100, p1, b1) expected = -150 p1_acc.deposit(500) p1_acc.deposit(100) p1_acc.withdraw(50) p1_acc.withdraw(100) assert p1_acc.get_credit_turnover(datetime.date.today(), datetime.date.today()) == expected
def test_get_debit_turnover(): """Test.""" person1 = Person("Ellina", "Gedrojets", 18) bank1 = Bank("Swed") acc1 = Account(20, person1, bank1) acc1.deposit(300) acc1.deposit(10) acc1.withdraw(50) assert acc1.get_debit_turnover(datetime.date.today(), datetime.date.today()) == 310
class Executor(Account): """ An account to execute buying and selling of an asset """ def __init__(self, uni): self.client = Account('balance.txt') self.universe = uni self.available_cash = self.client.get_balance() # update for leverage self.number_units_sought = 20 # base on execution threads or pipes self.current_transaction_amount = 0 self.commission_rate = 0.01 self.order_type = ["limit", "market"] self.last_transactions = LifoQueue( ) # provides me a put and get method def set_buy_price(self): selection = str(input("Enter asset: ")) for asset in self.universe: for k, v in asset.items(): if k == selection: ask = v.get("ask") if self.number_units_sought < v.get("shares_available"): return int(ask * self.number_units_sought) def set_buy_order(self): order_value = self.set_buy_price() commission_value = self.commission_rate * order_value order = order_value + commission_value return order def execute_buy_order(self): buy_order = self.set_buy_order() print("Your current value inside execute order is ${}".format( client1.available_cash)) self.client.withdraw(buy_order) self.last_transaction.put(("order value", buy_order)) # complete the txn with client server interaction def set_sell_price(self): pass def execute_sell_order(self): pass def order_metrics(self): pass def fetch_universe(self): """ calls the fetcher class to get the investible universe" """ pass
def test_account(self): #Setup & Perform self.user_account = Account(self.a_new_user.id, 2000) #Test self.assertEqual(self.user_account.user_id, self.a_new_user.id) self.assertEqual(self.user_account.amount, 2000)
def test_acc_statement(): """Test.""" person1 = Person("Ellina", "Gedrojets", 18) bank1 = Bank("Swed") acc1 = Account(20, person1, bank1) old_transaction = Transaction( 150, datetime.date.today() - datetime.timedelta(days=19), acc1, acc1, True) acc1.transactions.append(old_transaction) new_transaction = Transaction( 50, datetime.date.today() - datetime.timedelta(days=5), acc1, acc1, True) acc1.transactions.append(new_transaction) result_is_new_trans = acc1.account_statement( datetime.date.today() - datetime.timedelta(days=7), datetime.date.today()) assert result_is_new_trans == [new_transaction]
def test_withdraw(): """Test function withdraw.""" person1 = Person("Ellina", "Gedrojets", 18) person2 = Person("Robert", "Soidla", 19) bank1 = Bank("Swed") bank2 = Bank("LHV") acc1 = Account(20, person1, bank1) acc2 = Account(100, person2, bank2) with pytest.raises(TransactionError): assert acc1.withdraw(-10) with pytest.raises(TransactionError): assert acc1.withdraw(acc1.balance + 1) acc2.withdraw(10, False) assert acc2.balance == 90 acc2.withdraw(10) tr = Transaction(-10, datetime.date.today(), acc2, acc2, True) assert str(acc2.transactions[0]) == str(tr)
def test_withdraw(): """Test withdraw method in Account class.""" p1 = Person('Jack', 'Jackson', 19) p2 = Person('Anna', 'Dark', 194) b1 = Bank('NotSwedBank') b2 = Bank('CoolerThanLHV') p1_acc = Account(100, p1, b1) p2_acc = Account(25, p2, b2) with pytest.raises(TransactionError): assert p1_acc.withdraw(p1_acc.balance + 5) with pytest.raises(TransactionError): assert p1_acc.withdraw(-225) p2_acc.withdraw(20) tr = Transaction(-20, datetime.date.today(), p2_acc, p2_acc, True) assert str(p2_acc.transactions[0]) == str(tr) p1_acc.withdraw(15, is_from_atm=False) assert p1_acc.balance == 100 - 15
class TestJohnOuvreUnCompte(unittest.TestCase): """ Cette classe test l'ouverture d'un compte ainsi que les deux operations elementaires que sont les credits et les debits """ def setUp(self): self.storage = mock() self.account = Account(self.storage) def test_ouverture_de_compte_solde_a_zero(self): """Test l'ouverture d'une compte et son solde""" when(self.storage).select().thenReturn([]) self.assertEquals(self.account.balance(), 0) def test_balance(self): """Test la balance d'un compte""" when(self.storage).select().thenReturn([10, -5]) balance = self.account.balance() self.assertEquals(balance, 5)
def test_deposit(): """Test deposit.""" person1 = Person("Ellina", "Gedrojets", 18) person2 = Person("Robert", "Soidla", 19) bank1 = Bank("Swed") bank2 = Bank("LHV") acc1 = Account(20, person1, bank1) acc2 = Account(100, person2, bank2) with pytest.raises(TransactionError): assert acc1.deposit(-10) acc2.deposit(2, True) tr1 = Transaction(2, datetime.date.today(), acc2, acc2, True) assert str(acc2.transactions[0]) == str(tr1) acc1.deposit(10, False) assert acc1.balance == 30
def test_deposit(): """Test deposit method in Account class.""" p1 = Person('Jack', 'Jackson', 19) p2 = Person('Anna', 'Dark', 194) b1 = Bank('NotSwedBank') b2 = Bank('CoolerThanLHV') p1_acc = Account(100, p1, b1) p2_acc = Account(25, p2, b2) with pytest.raises(TransactionError): assert p1_acc.deposit(-15) p1_acc.deposit(15) tr1 = Transaction(15, datetime.date.today(), p1_acc, p1_acc, True) assert str(p1_acc.transactions[0]) == str(tr1) p2_acc.deposit(20, is_from_atm=False) assert p2_acc.balance == 45
def test_acc_statement(): """Test account_statement method in Account class.""" p1 = Person('Jack', 'Jackson', 19) b1 = Bank('NotSwedBank') p1_acc = Account(100, p1, b1) old_trans = Transaction( 150, datetime.date.today() - datetime.timedelta(days=15), p1_acc, p1_acc, True) p1_acc.transactions.append(old_trans) new_trans = Transaction(50, datetime.date.today() - datetime.timedelta(days=5), p1_acc, p1_acc, True) p1_acc.transactions.append(new_trans) res_newer = p1_acc.account_statement( datetime.date.today() - datetime.timedelta(days=7), datetime.date.today()) assert res_newer == [new_trans] res_old = p1_acc.account_statement( datetime.date.today() - datetime.timedelta(days=365), datetime.date.today() - datetime.timedelta(days=10)) assert res_old == [old_trans]
def create_checking_account(c): print("Enter Checking Account_id") try: account_id = int(input()) except ValueError: print("Please enter an integer number") if c.cust_id in customers and account_id in checkings: print("Checking Account ID aleady exists") print(checkings[account_id].getAccountInfo()) return checkings[account_id] else: print("Type opening balance") opening_balance = int(input()) a1 = Account(account_id, c, opening_balance) checkings[account_id] = a1 return a1
def bank_operation(self, request_message, request_params): response_msg = None response_params = None debug = False if request_message == "addAccount": response_msg = Bank().addAccount( Account(request_params['name'], request_params['email'], request_params['password'], request_params['type'])) elif request_message == "deleteAccount": response_msg = Bank().deleteAccount(request_params['email']) elif request_message == "changePassword": response_msg = Bank().changePassword(request_params['email'], request_params['password']) elif request_message == "withdraw": log.debug('withDraw: %s' % str(request_params)) response_msg = Bank().withDraw(request_params['email'], request_params['amount']) elif request_message == "deposit": response_msg = Bank().deposit(request_params['email'], request_params['amount']) elif request_message == "getPassbook": response_msg = Bank().getPassbook(request_params['email']) debug = True return response_msg, response_params, debug
def test_withdraw_not_enough_money(): account = Account(initial_balance=200) with pytest.raises(ValueError): account.withdraw(amount=500)
while True: option = int(input("\nEnter your Option Here \n")) if option == 1: acc = int(input("Enter your account number\n")) first = str(input("Enter your first name\n").strip()) last = str(input("Enter your last name\n").strip()) balance = float(input("Enter starting account balance\n").strip()) if acc > 0: if acc in users: print("User already Exists") else: user = Account(acc, first, last, balance) users[acc] = user else: print("\nAccount Number cannot be zero\n") elif option == 2: accNum = int(input("Enter your account number\n")) amt = float(input("Enter amount you want to deposit\n")) if accNum in users: if amt > 0: user.deposit(amt) print(user.getBalance()) else: print("The amount is too small to be Withdrawn")
def get_value(): name_value = "" occupation_value = "" email_value = "" pin_value = "" dob_value = "" # check for name format if name.get().isalpha(): name_value = name.get() tkinter.Label( account_open_canvas, text=' ', bg='blue', fg='white').grid(row=1, column=1, sticky='w') elif name.get() == "": tkinter.Label(account_open_canvas, text='Name field can not be empty', bg='blue', fg='white').grid(row=1, column=1, sticky='w') else: tkinter.Label(account_open_canvas, text='Name can only be alphabets', bg='blue', fg='white').grid(row=1, column=1, sticky='w') # validate date if dob.get() != "": try: dob_value = dob.get() datetime.datetime.strptime(dob_value, '%d.%m.%Y') except ValueError: tkinter.Label(account_open_canvas, text='Incorrect date format, should be DD.MM.YYYY', bg='blue', fg='white').grid(row=3, column=1, sticky='w') dob_value = "" # default the entry once there is an error else: tkinter.Label(account_open_canvas, text='Date of Birth field can not be empty', bg='blue', fg='white').grid(row=3, column=1, sticky='w') # check for occupation format if occupation.get().isalpha(): occupation_value = occupation.get() tkinter.Label( account_open_canvas, text=' ', bg='blue', fg='white').grid(row=5, column=1, sticky='w') elif occupation.get() == "": tkinter.Label(account_open_canvas, text='Occupation field can not be empty', bg='blue', fg='white').grid(row=5, column=1, sticky='w') else: tkinter.Label(account_open_canvas, text='Occupation can only be alphabets', bg='blue', fg='white').grid(row=5, column=1, sticky='w') # check for email format if email_value == "": tkinter.Label(account_open_canvas, text="e_mail field can not be empty", bg='blue', fg='white').grid(row=8, column=1, sticky='w') elif not validate_email.validate_email(email.get(), verify=False): tkinter.Label(account_open_canvas, text="Incorrect email address", bg='blue', fg='white').grid(row=8, column=1, sticky='w') else: email_value = email.get() # check for pin format try: pin_value = int(pin.get()) if len(pin.get()) != 4: tkinter.Label(account_open_canvas, text='PIN must be four digits', bg='blue', fg='white').grid(row=10, column=1, sticky='w') else: tkinter.Label( account_open_canvas, text=' ', bg='blue', fg='white').grid(row=10, column=1, sticky='w') except ValueError: tkinter.Label(account_open_canvas, text='PIN can only be digits', bg='blue', fg='white').grid(row=10, column=1, sticky='w') if name_value != "" and occupation_value != "" and email_value != "" and pin_value != "" and dob_value != "": new_account = Account() new_account._name = name_value new_account._date_of_birth = dob_value new_account._occupation = occupation_value new_account._account_type = rbvalue.get() new_account._account_number = new_account.generate_account_number() new_account._email = email_value new_account._pin = pin_value new_account._security_question = question_values.get() new_account._security_answer = answer.get() print(new_account)
def test_account_object_can_be_created(self): account = Account()
def test_transfer(): """Test transfer method in Account class.""" p1 = Person('Jack', 'Jackson', 19) p2 = Person('Anna', 'Dark', 194) p3 = Person('Igor', 'Smirnov', 33) p4 = Person('Nana', 'Banana', 44) b1 = Bank('NotSwedBank') b2 = Bank('CoolerThanLHV') b3 = Bank('NotYourSEB') p1_acc = Account(100, p1, b1) p2_acc = Account(25, p2, b2) p3_acc = Account(300, p3, b3) p4_acc = Account(0, p4, b3) with pytest.raises(TransactionError): assert p2_acc.transfer(100500, p1_acc) """transaction1 = Transaction(5, datetime.date.today(), p2_acc, p1_acc, False) transaction2 = Transaction(10, datetime.date.today(), p3_acc, p2_acc, False)""" # different banks transfer p2_acc.transfer(5, p1_acc) assert p2_acc.transactions == p1_acc.transactions == b1.transactions == b2.transactions # transaction repr tests for different bank operations expected = f'(5 €) {p2} -> {p1}' assert p2_acc.transactions[0].__repr__() == expected # same bank transfer p3_acc.transfer(10, p4_acc) assert p3_acc.transactions == p4_acc.transactions == b3.transactions
def create_account(name, balance, pin): account = Account(name=name, balance=balance, pin=pin) session.add(account) session.commit()
def setUp(self): self.client = Client(1, "2017-09-21", 1, "Olivier", "LON") self.account = Account(1, self.client)
def test_net_turnover(): """Test get_net_turnover method in Account class.""" p1 = Person('Jack', 'Jackson', 19) b1 = Bank('NotSwedBank') p1_acc = Account(100, p1, b1) p1_acc = Account(100, p1, b1) expected1 = 450 p1_acc.deposit(500) p1_acc.withdraw(50) assert p1_acc.get_net_turnover(datetime.date.today(), datetime.date.today()) == expected1 p2 = Person('Anna', 'Dark', 194) p2_acc = Account(200, p2, b1) expected2 = -50 p2_acc.deposit(100) p2_acc.withdraw(150) assert p2_acc.get_net_turnover(datetime.date.today(), datetime.date.today()) == expected2
def account(): return Account(initial_balance=1000)
# -*- coding: utf-8 -*- #import bank from bank import Client from bank import Account pedro = Client('Pedro', 30) maria = Client('Maria da Penha', 22) marcos = Client('Marcos', 26) print("---- Clientes ----\n") for client in [pedro, maria, marcos]: print("Nome: %s | Idade: %s" % (client.name, client.age)) acc1 = Account([pedro], 1, 1500) acc2 = Account([marcos, maria], 2, 2400) print('\n---- Saldo inicial ----\n') acc1.summary() acc2.summary() print('\n---- Movimentação ----\n') acc1.take_money(120) acc1.take_money(25) acc2.deposit_money(300) acc2.take_money(1000) acc2.take_money(1500) acc2.take_money(1500) print('\n---- Extratos ----')
def setUp(self): self.storage = mock() self.account = Account(self.storage)
def test_transfer(): """Test transfer function.""" person1 = Person("Ellina", "Gedrojets", 18) person2 = Person("Robert", "Soidla", 19) person3 = Person("Mari", "Mets", 80) person4 = Person("Lilian", "Valge", 40) bank1 = Bank("Swed") bank2 = Bank("LHV") bank3 = Bank("Luminor") acc1 = Account(20, person1, bank1) acc2 = Account(100, person2, bank2) acc3 = Account(250, person3, bank3) acc4 = Account(0, person4, bank3) with pytest.raises(TransactionError): assert acc1.transfer(10000, acc2) """different banks transfer.""" acc1.transfer(10, acc2) assert acc1.transactions == acc2.transactions == bank1.transactions == bank2.transactions """Same banks transfer.""" acc3.transfer(7, acc4) assert acc3.transactions == acc4.transactions == bank3.transactions
def test_account_object_returns_current_balance(self): account = Account('001', 50) self.assertEqual(account.account_number, '001') self.assertEqual(account.balance, 50)
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__'