def main(): # 存取所以用户的信息 # 界面对象 admin = Admin() admin.print_admin_view() # 用户管理员开机 # 如果view.admin_login()返回值是-1,程序结束。如果是0就不会执行下去 if admin.admin_option() == -1: return -1 # 提款机对象 ''' f = open(file_path, "rb") all_users = pickle.load(f) atm = Atm(all_users) ''' file_path = os.path.join(os.getcwd(), "a.txt") all_users = {} atm = Atm(all_users) # admin.print_sys_function_view() while True: admin.print_sys_function_view() # 等待用户操作 option = input("请输入你的操作:") if option == "1": atm.create_user() elif option == "2": atm.search_user_info() elif option == "3": atm.get_money() elif option == "4": print("存款") elif option == "5": print("转账") elif option == "6": print("改密") elif option == "7": atm.lock_user() elif option == "8": atm.unlock_user() elif option == "9": print("补卡") elif option == "0": print("销户") elif option == "q": if not admin.admin_option(): # 讲当前系统中用户信息保存到文件中 # abs_path = os.getcwdb() # 获取当前目录觉得路径 # file_path = os.path.join(os.getcwdb(), "allusers.txt") f = open(file_path, "wb") pickle.dump(atm.all_user, f) f.closed print(file_path) return -1 time.sleep(0.5)
class TestAtmExceptions(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_exception(self): try: self.atm.get_money(1000000) except Exception as e: self.assertEqual('Atm balance is no enough!!!', e.message)
class TestAtm(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_enter_true_pin_and_check_balance(self): '''Enter the correct pin and check the balance''' balance = self.atm.check_balance() self.assertEqual(10000, balance) def test_gives_4000_money(self): '''Give money in the amount of 4000''' money = self.atm.get_money(4000) self.assertEqual(4000, money) def test_gives_10000_money(self): '''Give money in the amount of 10000''' money = self.atm.get_money(10000) self.assertEqual(10000, money) def test_gives_9999_money(self): '''Give money in the amount of 9999''' money = self.atm.get_money(9999) self.assertEqual(9999, money) def test_gives_0_money(self): '''Give money in the amount of 0''' money = self.atm.get_money(0) self.assertEqual(0, money) @unittest.skip("Bug #0001") def test_gives_min_1_money(self): '''A negative amount is given''' money = self.atm.get_money(-1) self.assertEqual(0, money) def test_rise_1000000_money(self): '''Add the amount of 1000000''' rise_money = self.atm._rise_money(1000000) self.assertEqual(1010000, rise_money) def test_rise_0_money(self): '''Add the amount of 0''' rise_money = self.atm._rise_money(0) self.assertEqual(10000, rise_money) @unittest.skip("Bug #0002") def test_rise_min_1_money(self): '''A negative amount is added''' rise_money = self.atm._rise_money(-1) self.assertEqual(10000, rise_money)
class TestAtm(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_atm_gives_money(self): money = self.atm.get_money(1000) self.assertEqual(1000, money)
class TestAtmExceptions(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) self.atm2 = Atm() def test_gives_10001_money(self): '''Trying to give the amount more available''' try: self.atm.get_money(10001) except Exception as e: self.assertEqual('Atm balance is no enough!!!', e.message) def test_incorrect_pin(self): '''Testing an incorrect pin''' try: self.atm2.enter_pin(77) except Exception as e: self.assertEqual('Incorrect Pin!!!', e.message)
class TestAtmPinBlock(unittest.TestCase): """ Testing block with a pin input """ def setUp(self): self.term = Atm() def test_input_correct_pin_and_get_balance(self): self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) def test_input_wrong_pin_three_times_and_get_error_message(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(111) except IncorrectPin as e: pass except AttemptsOver as e: self.assertEqual('Attempts are over!!!', e.message) def test_input_wrong_pin_two_times_then_correct_and_get_balance(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) except IncorrectPin as e: pass def test_input_pin_value_more_than_three_characters(self): try: self.term.enter_pin(8888) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_less_than_three_characters(self): try: self.term.enter_pin(88) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_string(self): try: self.term.enter_pin("something") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_char(self): try: self.term.enter_pin('A') except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_empty(self): try: self.term.enter_pin("") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_space(self): try: self.term.enter_pin(" ") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_without_input_pin_check_balance(self): try: self.term.check_balance() except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_get_money(self): try: self.term.get_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_rise_money(self): try: self.term._rise_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message)
class TestAtmMoneyBlock(unittest.TestCase): """ Testing block with a cash transactions """ def setUp(self): self.term = Atm() self.term.enter_pin(777) def test_rise_money(self): rise = self.term._rise_money(1000) self.assertEqual(rise, 11000) def test_get_money(self): get = self.term.get_money(1000) balance = self.term.check_balance() self.assertEqual(balance, 10000 - get) def test_rise_money_with_negative_value(self): try: self.term._rise_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_zero_value(self): try: self.term._rise_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_very_big_value(self): try: self.term._rise_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_string_value(self): try: self.term._rise_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_character_value(self): try: self.term._rise_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_negative_value(self): try: self.term.get_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_zero_value(self): try: self.term.get_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_very_big_value(self): try: self.term.get_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_string_value(self): try: self.term.get_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_character_value(self): try: self.term.get_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message)