def test_overdraw_atm(self): bank_iface = BankConnection(self.config) account_name = 'martha' amount = '400' card_id = self.admin_iface.create_account(account_name, amount) self.assertTrue(card_id) bal = self.admin_iface.check_balance('martha') self.assertTrue(bal == 400) card_id_inv = self.admin_iface.create_account(account_name, amount) self.assertTrue(card_id_inv == False) res = bank_iface.check_balance(card_id) self.assertTrue(int(res[5:]) == 400) atm_id = self.admin_iface.create_atm() self.assertTrue(res) bal = self.admin_iface.check_balance('martha') self.assertTrue(bal == 400) res = bank_iface.withdraw(atm_id, card_id, 400) self.assertTrue(res[:5] == 'ERROR') print res bal = self.admin_iface.check_balance('martha') self.assertTrue(bal == 400)
def test_check_balance_invalid_command(self): bank_iface = BankConnection(self.config) card_id = '111 ' res = bank_iface.check_balance(card_id) self.assertTrue(res[:5] == 'ERROR') self.assertTrue( res[6:] == 'check_balance command usage: balance <card_id>')
def test_all(self): bank_iface = BankConnection(self.config) account_name = 'marsha' amount = '57' card_id = self.admin_iface.create_account(account_name, amount) self.assertTrue(card_id) bal = self.admin_iface.check_balance('marsha') self.assertTrue(bal == 57) card_id_inv = self.admin_iface.create_account(account_name, amount) self.assertTrue(card_id_inv == False) res = bank_iface.check_balance(card_id) self.assertTrue(int(res[5:]) == 57) atm_id = self.admin_iface.create_atm() self.assertTrue(res) bal = self.admin_iface.check_balance('marsha') self.assertTrue(bal == 57) res = bank_iface.withdraw(atm_id, card_id, 57) self.assertTrue(res[:4] == 'OKAY') bal = self.admin_iface.check_balance('marsha') self.assertTrue(bal == 0) self.admin_iface.update_balance('marsha', 15) bal = self.admin_iface.check_balance('marsha') self.assertTrue(bal == 15)
def test_withdraw_invalid_command(self): bank_iface = BankConnection(self.config) res = bank_iface.withdraw('a', 'b', 'c') self.assertTrue(res[:5] == 'ERROR') self.assertTrue( res[6:] == 'withdraw command usage: withdraw <atm_id> <card_id> <amount>')
def test_withdraw_valid(self): bank_iface = BankConnection(self.config) # atm,card,amount atm_id = str(uuid.UUID('{40000000-0000-0000-0000-000000000000}')) card_id = str(uuid.UUID('{50000000-0000-0000-0000-000000000000}')) amount = '3' res = bank_iface.withdraw(atm_id, card_id, amount) self.assertTrue(res[:4] == 'OKAY')
def test_check_balance_invalid_card_id(self): bank_iface = BankConnection(self.config) card_id = str(uuid.UUID('{53000000-0000-0000-0000-000000000000}')) res = bank_iface.check_balance(card_id) print res self.assertTrue(res[:5] == 'ERROR') self.assertTrue(res[6:] == 'could not lookup account \'' + card_id + '\'')
def test_withdraw_invalid_card_id(self): bank_iface = BankConnection(self.config) # atm,card,amount atm_id = str(uuid.UUID('{40000000-0000-0000-0000-000000000000}')) card_id = str(uuid.UUID('{88800000-0000-0000-0000-000000000000}')) amount = '3' res = bank_iface.withdraw(atm_id, card_id, amount) self.assertTrue(res[:5] == 'ERROR') self.assertTrue(res[6:] == 'could not lookup card \'%s\'' % card_id)
def test_check_balance_valid(self): bank_iface = BankConnection(self.config) card_id = str(uuid.UUID('{50000000-0000-0000-0000-000000000000}')) res = bank_iface.check_balance(card_id) print 'output' print res print self.config print 'output' self.assertTrue(res[:4] == 'OKAY') self.assertTrue(int(res[5:]) == 10)
def test_withdraw_invalid_amount(self): bank_iface = BankConnection(self.config) # atm,card,amount atm_id = str(uuid.UUID('{40000000-0000-0000-0000-000000000000}')) card_id = str(uuid.UUID('{50000000-0000-0000-0000-000000000000}')) amount = '777' res = bank_iface.withdraw(atm_id, card_id, amount) print res print res[6:37] self.assertTrue(res[:5] == 'ERROR') self.assertTrue(res[6:31] == 'insufficient funds in atm')
def run(): connection = BankConnection() global is_logged_in global account_number global is_manager global client_name display_greeting() display_available_operations() while True: print('') display_login_status() op = input('Operação (m para ver opções): ') if op == 'q': display_greeting() print("Até a próxima!") connection.close_connection() break if(op == 'l'): if(is_logged_in): print("Operação inválida.") else: print("\nLogin.") account = input('Conta: ') password = input('Senha: ') status = connection.request_login(account, password) if status["type"] != "login_success": print("Não foi possível fazer o login. {}".format(get_error_message(status))) else: is_logged_in = True account_number = account is_manager = status["is_manager"] client_name = status["name"] print("Bem vindo, {}! Você está logado.".format(client_name)) elif(op == 'd'): print("\nDepósito.") account = input('Conta destino: ') info = connection.request_client_info(account) if(info["type"] != "account_info"): print("Conta inválida.") else: option = input("Nome do destinatário: {}. Confirma? s/n: ".format(info["name"])) if option != 's': print("Operação cancelada.") else: amount = input('Valor: ') if not is_amount_valid(amount): print("Valor inválido.") else: status = connection.request_deposit(account, float(amount)) if status["type"] != "ok": print("Não possível realizar o depósito. {}".format(get_error_message(status))) else: print("Depósito efetuado com sucesso.") elif(op == 's'): if(not is_logged_in): print("Operação inválida") else: print("\nSaque.") amount = input('Valor: ') if not is_amount_valid(amount): print("Valor inválido.") else: status = connection.request_withdrawal(account_number, float(amount)) if status["type"] != "ok": print("Não possível realizar o saque. {}".format(get_error_message(status))) else: print("Saque efetuado com sucesso.") elif(op == 't'): if(not is_logged_in): print("Operação inválida") else: print("\nTransferência") destination_account = input('Conta favorecida: ') status = connection.request_client_info(destination_account) if(status["type"] != "account_info"): print("Conta inválida.") continue option = input("Nome do destinatário: {}. Confirma? s/n: ".format(status["name"])) if option != "s": continue amount = input('Valor: ') if(not is_amount_valid(amount)): print("Valor inválido.") else: status = connection.request_transfer(account, destination_account, float(amount)) if status["type"] == "ok": print("Transferência efetuada com sucesso.") else: print("Não foi possível realizar a Transferência. {}.".format(get_error_message(status))) elif(op == 'b'): if(not is_logged_in): print("Operação inválida") else: status = connection.request_balance(account_number) if status["type"] != "balance": print("Não foi possível acessar o seu saldo. {}".format(get_error_message(status))) else: print("Saldo disponível: R$ {}".format(status["balance"])) elif(op == 'c'): if(not is_logged_in or not is_manager): print("Operação inválida.") else: print("\nCriar nova conta.") id = input('RG: ' ) name = input('Nome: ' ) password = input('Password: '******'Conta de gerente? s/n: ' ) if(manager == 's'): is_manager_account = True else: is_manager_account = False status = connection.request_create_account(account, id, name, password, is_manager_account) if(status["type"] != "account_created"): print("Não foi possível criar a conta. {}.".format(get_error_message(status))) else: print("Conta criada com sucesso! Número da nova conta: {}.".format(status["account"])) elif(op == 'r'): if(not is_manager or not is_logged_in): print("Operação inválida.") else: print("\nRemover conta.") account_to_remove = input('Número da conta a ser removida: ' ) option = input("Tem certeza que quer remover a conta {}? s/n: ".format(account_to_remove)) if option != 's': continue status = connection.request_remove_account(account_to_remove, account_number) if(status["type"] != "ok"): print("Não foi possível remover a conta. {}.".format(get_error_message(status))) else: print("Conta removida com sucesso.") elif(op == 'o'): if not is_logged_in: print("Operação inválida.") else: is_logged_in = False account_number = "" is_manager = False client_name = "invalid_name" print("Você foi desconectado com sucesso.") elif(op == 'm'): print('') display_available_operations() elif(op == 'snapshot'): connection.request_snapshot() else: print("Operação inválida.")