def addMoney(): User.setAccount(Utils.inputHelp("账号")) Bank.setMoney(Utils.inputHelp("存储金额")) start = Bank.bank_addMoney(User.getAccount(), Bank.getMoney()) if start == 1: print("存入成功!") if start == False: print("您输入的账号不存在!")
def addUser(): # 随机生成账号 account = Utils.getRandom() User.setUsername(Utils.inputHelp("用户名")) User.setPassword(Utils.inputHelp("密码")) Address.setCounrry(Utils.inputHelp("国家")) Address.setProvince(Utils.inputHelp("省份")) Address.setStreet(Utils.inputHelp("街道")) Address.setDoor(Utils.inputHelp("门牌号")) # username = input("请输入您的姓名:") # password = input("请输入您的密码(6个数字):") # print("接下来请输入您的地址信息") # counrry = input("\t请输入您的国家:") # province = input("\t请输入省份:") # street = input("\t请输入街道:") # door = input("\t请输入门牌号:") # 余额不允许第一次输入,需要存钱 start = Bank.bank_addUser(account, User.getUsername(), User.getPassword(), Address.getCounrry(), Address.getProvicne(), Address.getStreet(), Address.getDoor()) if start == 1: print("开户成功!") info = ''' ----------- 个人信息------------- 账号: %s, 用户名: %s, 取款密码: %s, 地址信息: 国家: %s, 省份: %s, 街道: %s, 门牌号: %s, 余额: %s, 开户行: %s --------------------------------- ''' print(info % (account, User.getUsername(), User.getPassword(), Address.getCounrry(), Address.getProvicne(), Address.getStreet(), Address.getDoor(), 0, Bank.getBankName())) if start == 2: print("该用户名已经存在!!!") if start == 3: print("银行用户库已满!!!")
def seek(): User.setAccount(Utils.inputHelp("您的要查询的账号")) User.setPassword(Utils.inputHelp("密码")) start = Bank.bank_seek(User.getAccount(), User.getPassword()) if start == 0: # 查询表中数据 sql = "select * from jdbcbank where account = %s and password = %s" param = [User.getAccount(), User.getPassword()] # 执行sql data = DB.Select(sql, param) for i in data: account = data[0][0] username = data[0][1] password = data[0][2] cunrry = data[0][3] province = data[0][4] street = data[0][5] door = data[0][6] money = data[0][7] bank_name = data[0][8] print("以下为您的账号信息") info = ''' ----------- 个人信息------------- 账号: %s, 用户名: %s, 取款密码: %s, 地址信息: 国家: %s, 省份: %s, 街道: %s, 门牌号: %s, 余额: %s, 开户行: %s --------------------------------- ''' print(info % (account, username, password, cunrry, province, street, door, money, bank_name)) if start == 1: print("该用户不存在") if start == 2: print("您输入的密码不正确")
def withdrawal(): User.setAccount(Utils.inputHelp("账号")) User.setPassword(Utils.inputHelp("密码")) Bank.setMoney(Utils.inputHelp("要取出的金额")) start = Bank.bank_withdrawal(User.getAccount(), User.getPassword(), Bank.getMoney()) if start == 0: print("取款成功!") if start == 1: print("账号不存在!") if start == 2: print("密码不对") if start == 3: print("账户余额不足")
class TestAddMoney(unittest.TestCase): user = None address = None bank = None def setUp(self) -> None: self.user = User() self.bank = Bank() self.address = Address() def test_addMoney1(self): # 1.准备测试数据 self.user.setAccount("qqqqqqq2") self.bank.setMoney("10000") # 2.预期结果 teststart = 1 # 3.调用被测方法 start = self.bank.bank_addMoney(self.user.getAccount(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start) def test_addMoney2(self): # 1.准备测试数据 self.user.setAccount("qqqqqqq3") self.bank.setMoney("10000") # 2.预期结果 teststart = False # 3.调用被测方法 start = self.bank.bank_addMoney(self.user.getAccount(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start)
from werkzeug.security import safe_str_cmp from util.User import User users = [User(1, 'bob', 'asdf')] username_mapping = {u.username: u for u in users} userid_mapping = {u.id: u for u in users} def authenticate(username, password): user = username_mapping.get(username, None) if user and safe_str_cmp(user.password, password): return user def identity(payload): user_id = payload['identity'] return userid_mapping.get(user_id, None)
class TestAddUser(unittest.TestCase): user = None address = None bank = None def setUp(self) -> None: self.user = User() self.address = Address() self.bank = Bank() def test_adduser1(self): # 1.准备测试数据 self.user.setAccount("qqqqqqq1") self.user.setPassword("123456") self.user.setUsername("q1") self.address.setCounrry("中国") self.address.setProvince("北京") self.address.setStreet("幸福路") self.address.setDoor("46") # 2. 预期结果 teststart = 1 # 3.调用被测方法 start = self.bank.bank_addUser(self.user.getAccount(), self.user.getUsername(), self.user.getPassword(), self.address.getCounrry(), self.address.getProvicne(), self.address.getStreet(), self.address.getDoor()) # 4.断言 self.assertEqual(teststart, start) def test_adduser2(self): # 1.准备测试数据 self.user.setAccount("0tqr0d3c") self.user.setPassword("123456") self.user.setUsername("q1") self.address.setCounrry("中国") self.address.setProvince("北京") self.address.setStreet("幸福路") self.address.setDoor("46") # 2. 预期结果 teststart = 2 start = self.bank.bank_addUser(self.user.getAccount(), self.user.getUsername(), self.user.getPassword(), self.address.getCounrry(), self.address.getProvicne(), self.address.getStreet(), self.address.getDoor()) # 3.断言 self.assertEqual(teststart, start)
def setUp(self) -> None: self.user = User() self.address = Address() self.bank = Bank()
from util.DBUtils import DBUtils from util.welcome import Welcome from util.User import User from util.Address import Address from util.Bank import Bank from util.HelpUtils import Utils DB = DBUtils() welcome = Welcome() User = User() Address = Address() Bank = Bank() Utils = Utils() # 开户方法 def addUser(): # 随机生成账号 account = Utils.getRandom() User.setUsername(Utils.inputHelp("用户名")) User.setPassword(Utils.inputHelp("密码")) Address.setCounrry(Utils.inputHelp("国家")) Address.setProvince(Utils.inputHelp("省份")) Address.setStreet(Utils.inputHelp("街道")) Address.setDoor(Utils.inputHelp("门牌号")) # username = input("请输入您的姓名:") # password = input("请输入您的密码(6个数字):") # print("接下来请输入您的地址信息") # counrry = input("\t请输入您的国家:") # province = input("\t请输入省份:") # street = input("\t请输入街道:")
def setUp(self) -> None: self.user = User() self.bank = Bank()
class TestWithdrawal(unittest.TestCase): user = None bank = None def setUp(self) -> None: self.user = User() self.bank = Bank() def test_Withdrawal1(self): # 1.准备数据 self.user.setAccount("qqqqqqq4") self.user.setPassword("123456") self.bank.setMoney("100") # 2.预期结果 teststart = 0 # 3.调用被测试方法 start = self.bank.bank_withdrawal(self.user.getAccount(), self.user.getPassword(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start) def test_Withdrawal2(self): # 1.准备数据 self.user.setAccount("qqqqqqq5") self.user.setPassword("123456") self.bank.setMoney("100") # 2.预期结果 teststart = 1 # 3.调用被测试方法 start = self.bank.bank_withdrawal(self.user.getAccount(), self.user.getPassword(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start) def test_Withdrawal3(self): # 1.准备数据 self.user.setAccount("qqqqqqq6") self.user.setPassword("333333") self.bank.setMoney("100") # 2.预期结果 teststart = 2 # 3.调用被测试方法 start = self.bank.bank_withdrawal(self.user.getAccount(), self.user.getPassword(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start) def test_Withdrawal4(self): # 1.准备数据 self.user.setAccount("qqqqqqq7") self.user.setPassword("123456") self.bank.setMoney("100") # 2.预期结果 teststart = 3 # 3.调用被测试方法 start = self.bank.bank_withdrawal(self.user.getAccount(), self.user.getPassword(), self.bank.getMoney()) # 4.断言 self.assertEqual(teststart, start)
class TestSeek(unittest.TestCase): user = None bank = None def setUp(self) -> None: self.user = User() self.bank = Bank() def test_seek1(self): self.user.setAccount("qqqqqq14") self.user.setPassword("123456") teststart = 0 start = self.bank.bank_seek(self.user.getAccount(), self.user.getPassword()) self.assertEqual(teststart, start) def test_seek2(self): self.user.setAccount("qqqqqq15") self.user.setPassword("123456") teststart = 1 start = self.bank.bank_seek(self.user.getAccount(), self.user.getPassword()) self.assertEqual(teststart, start) def test_seek3(self): self.user.setAccount("qqqqqq16") self.user.setPassword("weqweqw") teststart = 2 start = self.bank.bank_seek(self.user.getAccount(), self.user.getPassword()) self.assertEqual(teststart, start)