代码拉取完成,页面将自动刷新
import unittest
from ddt import ddt,data,unpack
import requests
import Common
@ddt
class UpdateUserTest(unittest.TestCase):
test = "test"
finish = "finish"
testTxt = "测好了"
db=""
cursor=""
url="http://localhost:90/user/updateUserProfile"
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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com"},{"status":200,"code":100}])
def test_01_normal_user_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":"男"},{"status":400,"code":""}])
def test_02_normal_MoreParams_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2
params["sex"] = values["sex"]
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":""},{"status":400,"code":""}])
def test_03_normal_lackRealname_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":""},{"status":400,"code":""}])
def test_04_normal_lackidcard_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["realname"] = realname2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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",
"realname": "李四", "idcard": "333890950506954816", "paypwd": 666666, "phone": "54392600993",
"email": "1542043225@qq.com", "realname2": "李四一", "idcard2": "855745919747169214", "paypwd2": "123457",
"phone2": "15527756021", "email2": "1542043226@qq.com", "sex": ""}, {"status": 400, "code": ""}])
def test_05_normal_lackpaypwd_update(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)
userDetail = [username, realname, password2, idcard, phone, email, paypwd, 1, "良好"]
Common.checkUserDetail(self.db, self.cursor, user, userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params = {}
params["realname"] = realname2
params["idcard"] = idcard2
params["phone"] = phone2
params["email"] = email2
self.url = self.url + "/" + str(user[0][0])
req = requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":""},{"status":400,"code":""}])
def test_06_normal_lackphone_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["email"] = email2
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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",
"realname": "李四", "idcard": "333890950506954816", "paypwd": 666666, "phone": "54392600993",
"email": "1542043225@qq.com", "realname2": "李四一", "idcard2": "855745919747169214", "paypwd2": "123457",
"phone2": "15527756021", "email2": "1542043226@qq.com", "sex": ""}, {"status": 400, "code": ""}])
def test_07_normal_lackemail_update(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)
userDetail = [username, realname, password2, idcard, phone, email, paypwd, 1, "良好"]
Common.checkUserDetail(self.db, self.cursor, user, userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params = {}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
self.url = self.url + "/" + str(user[0][0])
req = requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":""},{"status":400,"code":""}])
def test_08_normal_lackParams_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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",
"realname": "李四", "idcard": "333890950506954816", "paypwd": 666666, "phone": "54392600993",
"email": "1542043225@qq.com", "realname2": "李四一", "idcard2": "855745919747169214", "paypwd2": "123457",
"phone2": "15527756021", "email2": "1542043226@qq.com", "sex": ""}, {"status": 400, "code": ""}])
def test_09_normal_lackParamsValue_update(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)
userDetail = [username, realname, password2, idcard, phone, email, paypwd, 1, "良好"]
Common.checkUserDetail(self.db, self.cursor, user, userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params = {}
params["realname"] = ""
params["idcard"] = ""
params["paypwd"] = ""
params["phone"] = ""
params["email"] = ""
self.url = self.url + "/" + str(user[0][0])
req = requests.put(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","realname":"李四","idcard":"333890950506954816","paypwd":666666,"phone":"54392600993","email":"1542043225@qq.com","realname2": "李四一", "idcard2":"855745919747169214", "paypwd2":"123457","phone2":"15527756021","email2":"1542043226@qq.com","sex":""},{"status":400,"code":""}])
def test_10_normal_SqlInject_update(self,values,targets):
username=values["username"]
password=values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password=Common.getEncryptPassword(self.db,self.cursor,password)
password2 =Common.getEncryptPassword(self.db,self.cursor,password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db,self.cursor,username2, password2)
userDetail=[username,realname,password2,idcard,phone,email,paypwd,1,"良好"]
Common.checkUserDetail(self.db,self.cursor,user,userDetail)
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,
}
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params={}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2+"; drop table user;"
self.url=self.url+"/"+str(user[0][0])
req=requests.put(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",
"realname": "李四", "idcard": "333890950506954816", "paypwd": 666666, "phone": "54392600993",
"email": "1542043225@qq.com", "realname2": "李四一", "idcard2": "855745919747169214", "paypwd2": "123457",
"phone2": "15527756021", "email2": "1542043226@qq.com", "sex": ""}, {"status": 302, "code": ""}])
def test_11_normal_overstep_update(self, values, targets):
username = values["username"]
password = values["password"]
username2 = values["username2"]
password2 = values["password2"]
realname = values["realname"]
idcard = values["idcard"]
paypwd = values["paypwd"]
phone = values["phone"]
email = values["email"]
password = Common.getEncryptPassword(self.db, self.cursor, password)
password2 = Common.getEncryptPassword(self.db, self.cursor, password2)
user = (
username, realname, password, idcard,
phone,
email, paypwd, 0, "良好")
Common.getUserIfNotExistAddUser(self.db, self.cursor, username, password, user)
user = Common.getUserByUsernameAndPassword(self.db, self.cursor, username2, password2)
userDetail = [username, realname, password2, idcard, phone, email, paypwd, 1, "良好"]
Common.checkUserDetail(self.db, self.cursor, user, userDetail)
realname2 = values["realname2"]
idcard2 = values["idcard2"]
paypwd2 = values["paypwd2"]
phone2 = values["phone2"]
email2 = values["email2"]
params = {}
params["realname"] = realname2
params["idcard"] = idcard2
params["paypwd"] = paypwd2
params["phone"] = phone2
params["email"] = email2
self.url = self.url + "/" + str(user[0][0])
req = requests.put(self.url, params=params)
req.encoding = "UTF-8"
status = req.status_code
self.assertEqual(targets["status"], status)
if __name__ == '__main__':
unittest.main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。