代码拉取完成,页面将自动刷新
import unittest
from ddt import ddt,data,unpack
import requests
import Common
@ddt
class TermFinancialTest(unittest.TestCase):
test = "test"
finish = "finish"
testTxt = "测好了"
db=""
cursor=""
url="http://localhost:90/user/buyTermFinancial"
login_url="http://localhost:90/login/verifyLogin"
@classmethod
def setUpClass(self):
self.db,self.cursor=Common.connectMysql()
@classmethod
def tearDownClass(self):
Common.closeMysql(self.db,self.cursor)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":200,"code":100}])
def test_01_normal_user_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
res=req.json()
code=res["code"]
self.assertEqual(targets["status"],status)
self.assertEqual(targets["code"],code)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":123456},{"status":200,"code":200}])
def test_02_normal_errorPassWord_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
res=req.json()
code=res["code"]
self.assertEqual(targets["status"],status)
self.assertEqual(targets["code"],code)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":200,"code":300}])
def test_03_normal_NotPassWord_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
Common.clearPassWord(self.db,self.cursor,userId)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
res=req.json()
code=res["code"]
self.assertEqual(targets["status"],status)
self.assertEqual(targets["code"],code)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":200,"code":500}])
def test_04_normal_NotBankcard_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
Common.deleteALLBankCardByUserId(self.db,self.cursor,userId)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
res=req.json()
code=res["code"]
self.assertEqual(targets["status"],status)
self.assertEqual(targets["code"],code)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","count":10000,"balance":"1000000","termFinancialId":1,"passWord":666666},{"status":400,"code":""}])
def test_05_normal_MoreParams_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
count = values["count"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
params["count"] = values["count"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
self.assertEqual(targets["status"],status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":400,"code":""}])
def test_06_normal_lackUserId_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["termFinancialId"] = termFinancialId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
self.assertEqual(targets["status"],status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":400,"code":""}])
def test_07_normal_lacktermFinancialId_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["passWord"] = values["passWord"]
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
self.assertEqual(targets["status"],status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username":"testlisi","password":"123456","username2":"testlisi","password2":"123456","balance":"1000000","termFinancialId":1,"passWord":666666},{"status":400,"code":""}])
def test_08_normal_lackPassWord_BuyChangeMoney(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params={}
params["username"]=username2
params["password"]= password2
login_req=requests.get(self.login_url,params=params)
cookies=login_req.cookies
cookie=""
for k, v in cookies.items():
cookie+=k+"="+v+";"
headers = {
'Cookie': cookie,
}
userId=Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)[0][0]
termFinancialId=values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
#检查银行卡余额
Common.checkBankCardBalance(self.db,self.cursor,userId,balance)
## 补齐个人信息
Common.checkUserDetail(self.db,self.cursor,Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2),user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
req=requests.post(self.url,params=params,headers=headers)
req.encoding="UTF-8"
status=req.status_code
self.assertEqual(targets["status"],status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username": "testlisi", "password": "123456", "username2": "testlisi", "password2": "123456",
"balance": "1000000", "termFinancialId": 1, "passWord": 666666}, {"status":400 , "code": ""}])
def test_09_normal_lackParams_BuyChangeMoney(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params = {}
params["username"] = username2
params["password"] = password2
login_req = requests.get(self.login_url, params=params)
cookies = login_req.cookies
cookie = ""
for k, v in cookies.items():
cookie += k + "=" + v + ";"
headers = {
'Cookie': cookie,
}
userId = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)[0][0]
termFinancialId = values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
# 检查银行卡余额
Common.checkBankCardBalance(self.db, self.cursor, userId, balance)
## 补齐个人信息
Common.checkUserDetail(self.db, self.cursor,
Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2), user)
params = {}
req = requests.post(self.url, params=params, headers=headers)
req.encoding = "UTF-8"
status = req.status_code
self.assertEqual(targets["status"], status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username": "testlisi", "password": "123456", "username2": "testlisi", "password2": "123456",
"balance": "1000000", "termFinancialId": 1, "passWord": 666666}, {"status": 400, "code": ""}])
def test_09_normal_lackParamsValue_BuyChangeMoney(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params = {}
params["username"] = username2
params["password"] = password2
login_req = requests.get(self.login_url, params=params)
cookies = login_req.cookies
cookie = ""
for k, v in cookies.items():
cookie += k + "=" + v + ";"
headers = {
'Cookie': cookie,
}
userId = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)[0][0]
termFinancialId = values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
# 检查银行卡余额
Common.checkBankCardBalance(self.db, self.cursor, userId, balance)
## 补齐个人信息
Common.checkUserDetail(self.db, self.cursor,
Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2), user)
params = {}
params["userId"] = ""
params["termFinancialId"] = ""
params["passWord"] = ""
req = requests.post(self.url, params=params, headers=headers)
req.encoding = "UTF-8"
status = req.status_code
self.assertEqual(targets["status"], status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username": "testlisi", "password": "123456", "username2": "testlisi", "password2": "123456",
"balance": "1000000", "termFinancialId": 1, "passWord": 666666}, {"status": 400, "code": ""}])
def test_10_normal_SqlInject_BuyChangeMoney(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
params = {}
params["username"] = username2
params["password"] = password2
login_req = requests.get(self.login_url, params=params)
cookies = login_req.cookies
cookie = ""
for k, v in cookies.items():
cookie += k + "=" + v + ";"
headers = {
'Cookie': cookie,
}
userId = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)[0][0]
termFinancialId = values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
# 检查银行卡余额
Common.checkBankCardBalance(self.db, self.cursor, userId, balance)
## 补齐个人信息
Common.checkUserDetail(self.db, self.cursor,
Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2), user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = str(values["passWord"]) +" ; drop table user;"
req = requests.post(self.url, params=params, headers=headers)
req.encoding = "UTF-8"
status = req.status_code
self.assertEqual(targets["status"], status)
@unittest.skipIf(test == finish, testTxt)
@unpack
@data([{"username": "testlisi", "password": "123456", "username2": "testlisi", "password2": "123456",
"balance": "1000000", "termFinancialId": 1, "passWord": 666666}, {"status": 302, "code": ""}])
def test_11_normal_overstep_BuyChangeMoney(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
balance = values["balance"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, username, password, Common.generateRandomNumber(18),
Common.generateRandomNumber(11),
Common.getRandomEmail(), 666666, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
userId = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)[0][0]
termFinancialId = values["termFinancialId"]
bank = ("中国工商银行", "1", "3127843237358576", userId, balance, "1")
Common.getBankIfNotExistAddBankCard(self.db, self.cursor, userId, bank)
# 检查银行卡余额
Common.checkBankCardBalance(self.db, self.cursor, userId, balance)
## 补齐个人信息
Common.checkUserDetail(self.db, self.cursor,
Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2), user)
params = {}
params["userId"] = userId
params["termFinancialId"] = termFinancialId
params["passWord"] = str(values["passWord"]) +" ; drop table user;"
req = requests.post(self.url, params=params)
req.encoding = "UTF-8"
status = req.status_code
self.assertEqual(targets["status"], status)
if __name__ == '__main__':
unittest.main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。