#coding:utf-8
importrequestsimporttimefrom test_018.login_chandao importLogin
host= "http://127.0.0.1"
classAddBug():def __init__(self, s):
self.s=sdefup_load(self,
jpg_path= "C:\\001.png",
file_name= "001.png",
file_type= "imgage/jpeg"):'''上传文件
:param jpg_path:
:param file_name:
:param file_type:
:return:'''url= host + "/zentao/file-ajaxUpload-5be120e20b5af.html?dir=image"with open(jpg_path,"rb") as fp:
f={"imgFile": (file_name, fp.read(), file_type),"localUrl": (None, file_name)
}
fp.close()#上传图片,或者文件, files=参数
r = self.s.post(url, files=f)try:print(r.json())return r.json()["url"]except:print("上传文件失败: %s" %r.text)return ""
def add_bug(self, jpg_url=None, title=None):'''添加BUG
:param jpg_url:
:param title:
:return:'''url= host + "/zentao/bug-create-1-0-moduleID=0.html"timestemp=str(time.time())if title ==None:
t= "title_%s" %timestempelse:
t=titleif jpg_url ==None:
jpg= "/zentao/data/upload/1/201811/071737170455846p.png"
else:
jpg=jpg_url
body={"product": "1","module": "0","project": "","openedBuild[]": "trunk","assignedTo": "admin","type": "codeerror","os": "","browser": "","color": "","title": t,"severity": "3","pri": "0","steps": '
[步骤]
\
\
\
[结果]
\[期望]
' %jpg_url,"story": "0","task": "0",#"mailto[]": "",#"keywords": "",
#"files[]": "",
#"labels[]": "",
"uid": "5be120e20b5af","case": "0","caseVersion": "0","result": "0","testtask": "0"}
r= self.s.post(url, data=body)print("添加BUG: %s" %r.text)returnr.textdefis_add_bug_succes(self, result):'''判断是否成功 - 添加BUG
:param result: 返回数据 - 服务器
:return:'''
return "self.location=" inresultif __name__ == '__main__':
s=requests.session()
zen=Login(s)
zen.login()
bug=AddBug(s)
jpg_url=bug.up_load()
bug.add_bug(jpg_url,"title")