Commit 295502f3 authored by Wallen姚文辉's avatar Wallen姚文辉

新增用例上传及绑定

parent 32308a49
*/__pycache__/
__pycache__/
config.yml
uploadfile/
......@@ -6,6 +6,10 @@ import base64
import requests
from bs4 import BeautifulSoup
from manager.tools import sqlOrmToJson
import xmindparser
from copy import deepcopy
from manager.tools import par_path
import os
db=server.db
tool = Blueprint("tools", __name__, url_prefix='/tool')
......@@ -30,8 +34,6 @@ def sendport():
user = 'wallen.ywh@galaxyoversea.com'
password = 'Ywh940509'
yag = yagmail.SMTP( user=user, password=password, host='smtp.exmail.qq.com',port=465)
print(data["to"])
print(data["subject"])
yag.send(to=data["to"],cc=data["cc"],subject=data.get("subject"),contents=data.get("contents"))
return jsonify({"code": 200, "message": f"{data.get('subject')}邮件发送成功"}),200
......@@ -171,4 +173,85 @@ def editemailuser():
db.session.commit()
db.session.close()
return jsonify({"code": 200, "message": "请求成功"}),200
@tool.route('/testcase/uploadcase', methods=["POST"])
def uplooadcase():
data_=request.json
headers=getheader(session.get("id"))
result=requests.request("get",jiraAddress+"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="+str(data_.get("project")),headers=headers).json()
projectId,projectkey=result["projects"][0]["id"],result["projects"][0]["key"]
data={ "fields": {
"project": {
"key": projectkey
},
"summary": "测试占位",
"description": "文辉的测试",
"issuetype": {
"name": "测试用例"
},
}
}
result=requests.request("post",jiraAddress+"/rest/api/2/issue/",json=data,headers=headers).json()
globalcaseId=result["id"]
print(par_path)
print(data_)
file_path=par_path+'/uploadfile/'+data_.get("file_name")
content= xmindparser.xmind_to_dict(file_path)
def a(suiteName,suiteId,info,new,type):
for each in info:
oldinfo,newtype=deepcopy(new),type
if not ((each["title"])=="Map" or (each["title"])=="测试用例" or (each["title"])=="sheet" or (each["title"])=="思维导图" or (each["title"])=="逻辑图" or (each["title"])=="括号图"):
if not suiteName:
suiteName = each.get("title")
params={"tcIssueId":globalcaseId,"projectId":projectId,"sourcePage":"TEST_SUITE_TEST_CASE_PAGE","decorator":"dialog","inline":True}
requests.request("post",jiraAddress+"/secure/CreateTestSuite.jspa?projectId="+str(projectId),data={"inline":True,"decorator":"dialog","testSuiteName":suiteName},headers=headers)
text=requests.request("get",jiraAddress+"/secure/ShowLinkTestSuiteInPanel.jspa",params=params,headers=headers).content
soup=BeautifulSoup(text,"html.parser")
suiteId=soup.find("strong",string=suiteName).parent.find("input").attrs.get("value")
if type=="name":
string=each.get("title")
if "tc:" in each.get("title") or "tc:" in each.get("title") or "tc:" in each.get("title"):
string,newtype=each.get("title").replace("tc:","").replace("tc:","").replace("tc:",""),"step"
oldinfo["name"]=oldinfo.get("name") and oldinfo.get("name")+"->"+string or string
elif type=="step":
newtype,oldinfo["step"]="expect",each.get("title")
else:
oldinfo["expect"]=each.get("title")
if each.get("topic") or each.get("topics"):
each.get("topic") and a(suiteName,suiteId,[each.get("topic")],oldinfo,newtype)
each.get("topics") and a(suiteName,suiteId,each.get("topics"),oldinfo,newtype)
else:
testId=requests.request("post",jiraAddress+"/rest/api/2/issue/",json={ "fields": {
"project": {
"key": projectkey
},
"summary": oldinfo["name"],
"issuetype": {
"name": "测试用例"
},
}
},headers=headers).json()["id"]
requests.request("post",jiraAddress+"/rest/synapse/1.0/testStep/addTestStep",json={"tcId":testId,"step":oldinfo.get("step"),"expectedResult":oldinfo.get("expect"),"sequenceNumber":None},headers=headers)
requests.request("post",jiraAddress+"/rest/synapse/latest/testSuite/addTestCaseMemberToTestSuites",json={"testSuiteIds":[suiteId],"testCaseId":testId},headers=headers)
a(None,None,content,{},"name")
requests.request("delete",jiraAddress+"/rest/api/2/issue/"+globalcaseId,headers=headers)
os.remove(file_path)
return jsonify({"code": 200, "message": "用例创建成功"}),200
@tool.route('/testcase/relevancycase/<id_>', methods=["POST"])
def relevancycase(id_):
headers=getheader(session.get("id"))
result=requests.request("get",jiraAddress+"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="+str(id_),headers=headers).json()
projectkey=result["projects"][0]["key"]
result=requests.request("get",jiraAddress+"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="+str(id_)+"&selectedProjectKey="+projectkey,headers=headers).json()
all,type_,storyids=result.get("issues"),{},{}
for k,v in result["entityData"]["types"].items():
type_[str(k)]=v["typeName"]
[storyids.update({i.get("key"):[]}) for i in list(filter(lambda x:type_[x["typeId"]]=="Story",all))]
for item in list(filter(lambda x:type_[x["typeId"]]=="测试用例",all)):
for each in storyids.keys():
each in item.get("summary") and storyids[each].append(item.get("key"))
for k,v in storyids.items():
requests.request("post",jiraAddress+"/rest/synapse/latest/requirementTestCase/addTestCase",headers=headers,json={"currentReqkey":k,"testCaseKeys":v,"history":"yes"})
return jsonify({"code": 200, "message": "用例关联执行结束"}),200
import os
import sys
import uuid
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from manager.serverCenter import server
from manager.tools import par_path
class Config(object):
JOBS = []
......@@ -31,6 +33,21 @@ def token():
pass
else:
return jsonify({"code": 401, "message": "登陆已过期"}),401
@server.app.route('/upload',methods=["POST"])
def upload():
if 'file' not in request.files:
return jsonify({"code": 503, "message": "请选择文件"}),503
file = request.files['file']
l=file.filename.split(".")
if file:
if len(l)==2:
file_name=str(uuid.uuid1())+'.'+l[-1]
else:
return jsonify({"code": 503, "message": "文件格式错误"}),503
# 存储文件
file.save(par_path+"/uploadfile/"+file_name)
return jsonify({"code": 200, "message": "上传成功","data":{"filename":file_name}}),200
if __name__ == '__main__':
rel_path = os.path.dirname(os.path.realpath(__file__))
......
import base64
import requests
import pandas as pd
import xmindparser
from copy import deepcopy
xmindparser.config = {
'showTopicId': True, # 是否展示主题ID
'hideEmptyValue': True # 是否隐藏空值
}
def relational_case(project):
jiraAddress,user,password="http://jira.galaxy-immi.com","wallen.ywh","ywh940509"
headers={
"Authorization":"Basic "+base64.b64encode((user+":"+password).encode('utf-8')).decode(),
"accept":"application/json,text/javascript,*/*;q=0.01"
}
id_=requests.request("get",jiraAddress+"/rest/agile/1.0/board?projectKeyOrId="+project,headers=headers).json().get("values")[0].get("id")
result=requests.request("get",jiraAddress+"/rest/greenhopper/1.0/xboard/plan/backlog/data.json?rapidViewId="+str(id_)+"&selectedProjectKey="+project,headers=headers).json()
all=result.get("issues")
type_={}
for k,v in result["entityData"]["types"].items():
type_[str(k)]=v["typeName"]
storyids={}
[storyids.update({i.get("key"):[]}) for i in list(filter(lambda x:type_[x["typeId"]]=="Story",all))]
for item in list(filter(lambda x:type_[x["typeId"]]=="测试用例",all)):
for each in storyids.keys():
each in item.get("summary") and storyids[each].append(item.get("key"))
for k,v in storyids.items():
print(k,v)
res=requests.request("post",jiraAddress+"/rest/synapse/latest/requirementTestCase/addTestCase",headers=headers,json={"currentReqkey":k,"testCaseKeys":v,"history":"yes"})
print(res.status_code)
print(res.url)
print(res.headers)
# print(res.)
def makecase(filePath):
content = xmindparser.xmind_to_dict(filePath)
case_list=[]
# print(content)
def a(info,new,type):
for each in info:
oldinfo=deepcopy(new)
newtype=type
if not ((each["title"])=="Map" or (each["title"])=="测试用例" or (each["title"])=="sheet"):
if type=="name":
string=each.get("title")
if "tc:" in each.get("title") or "tc:" in each.get("title") or "tc:" in each.get("title"):
string=each.get("title").replace("tc:","").replace("tc:","").replace("tc:","")
newtype="step"
if oldinfo.get("name"):
oldinfo["name"]=oldinfo.get("name") and oldinfo.get("name")+"->"+string or string
else:
oldinfo["name"]=string
elif type=="step":
newtype="expect"
oldinfo["step"]=each.get("title")
else:
oldinfo["expect"]=each.get("title")
if each.get("topic") or each.get("topics"):
(each.get("topic") and a([each.get("topic")],oldinfo,newtype))
(each.get("topics") and a(each.get("topics"),oldinfo,newtype))
else:
case_list.append(oldinfo)
a(content,{},"name")
name=list(map(lambda x:x.get("name"),case_list))
step=list(map(lambda x:x.get("step"),case_list))
expect=list(map(lambda x:x.get("expect"),case_list))
dataframe = pd.DataFrame({"用例名":name,"用例步骤":step,"预期结果":expect})
dataframe.to_csv("test.csv",index=False,sep=',')
# makecase("/home/yaowenhui/galaxTestCenter/1.07.xmind")
# relational_case("STARCOM")
a=1
b= a and 12 or 13
print(b)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment