report接口测试关键字
This commit is contained in:
@@ -7,16 +7,11 @@ import ipaddress
|
||||
MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1
|
||||
MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1
|
||||
def random_ipv4():
|
||||
# return ipaddress.IPv4Address._randomstring_from_ip_int(
|
||||
# random.randint(0, MAX_IPV4)
|
||||
# )
|
||||
re="192.168.50.11"
|
||||
return re
|
||||
|
||||
return ipaddress.IPv4Address._string_from_ip_int(
|
||||
random.randint(0, MAX_IPV4))
|
||||
def random_ipv6():
|
||||
return ipaddress.IPv6Address._randomstring_from_ip_int(
|
||||
random.randint(0, MAX_IPV6)
|
||||
)
|
||||
return ipaddress.IPv6Address._string_from_ip_int(
|
||||
random.randint(0, MAX_IPV6))
|
||||
|
||||
#随机生成邮箱地址
|
||||
def RandomEmail( emailType=None, rang=None):
|
||||
@@ -37,8 +32,8 @@ def RandomEmail( emailType=None, rang=None):
|
||||
return _email
|
||||
|
||||
#获取Schema
|
||||
def schema(schemauerl,token):
|
||||
url ="http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
|
||||
def schema(schemauerl,token,logtype):
|
||||
url ="http://192.168.44.72:8080/v1/log/schema?logType="+logtype
|
||||
headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":token}
|
||||
response = requests.get(url=url,headers=headers)
|
||||
return response.json()
|
||||
@@ -266,7 +261,7 @@ def filterCondition(schemajson):
|
||||
return filterCondition
|
||||
|
||||
#获取having条件的串
|
||||
def Havinginfo(schemajson):
|
||||
def havingjson(schemajson):
|
||||
number = random.randint(0,100000)
|
||||
schemametrics=schemajson["data"]["doc"]["schema_query"]["metrics"]
|
||||
aggregation = schemajson["data"]["doc"]["schema_query"]["references"]["aggregation"]
|
||||
@@ -293,24 +288,20 @@ def Havinginfo(schemajson):
|
||||
havingdict={"name":name,"function":str.lower(functions_1[0]),"expression":operator_1[0],"value":str(number)}
|
||||
orConditions_list.append(havingdict)
|
||||
orConditions={"orConditions":orConditions_list}
|
||||
andConditions_list.append(orConditions)
|
||||
|
||||
|
||||
andConditions_list.append(orConditions)
|
||||
havingCondition={"andConditions":andConditions_list}
|
||||
print(havingCondition)
|
||||
return havingCondition
|
||||
|
||||
#拼接字符串
|
||||
def datasetjson(schemauerl,token,testname):
|
||||
#获取Schema
|
||||
# aaa=["common_sled_ip","common_device_id","common_sessions","common_c2s_pkt_num"]
|
||||
schema_new=schema(schemauerl,token)
|
||||
def datasetjson(schemauerl,token,testname,logtype):
|
||||
schema_new=schema(schemauerl,token,logtype)
|
||||
group_re=groupby(schema_new)
|
||||
groupColumnList=group_re[0]
|
||||
group_randomstr=group_re[1]
|
||||
queryColumnList=DataBindings(schema_new,group_randomstr)
|
||||
filterCondition_1=filterCondition(schema_new)
|
||||
Havinginfo_1=Havinginfo(schema_new)
|
||||
havingjson_1=havingjson(schema_new)
|
||||
datasetdict = {
|
||||
"list": {
|
||||
"name":testname,
|
||||
@@ -318,80 +309,207 @@ def datasetjson(schemauerl,token,testname):
|
||||
"groupColumnList":groupColumnList,
|
||||
"queryColumnList":queryColumnList,
|
||||
"filterCondition":filterCondition_1,
|
||||
"havingCondition":Havinginfo_1
|
||||
# "isInitialize":0
|
||||
"havingCondition":havingjson_1
|
||||
}
|
||||
}
|
||||
print(datasetdict)
|
||||
print(json.dumps(datasetdict))
|
||||
return json.dumps(datasetdict)
|
||||
|
||||
#拼接char得串
|
||||
def charjson(schemaurl,token,datasetjson):
|
||||
schema_new=schema(schemauerl,token)
|
||||
queryColumnList=datasetjson["list"]["queryColumnList"]
|
||||
#拼接char的json串
|
||||
def charjson(schemaurl,token,queryColumnList,groupColumnList,datasetid,testname,logtype):
|
||||
print("queryColumnList",queryColumnList)
|
||||
schema_new=schema(schemaurl,token,logtype)
|
||||
fields = schema_new["data"]["fields"]
|
||||
# 获取条件的label
|
||||
namelist=[]
|
||||
#获取条件得label
|
||||
for i in queryColumnList:
|
||||
for j in fields:
|
||||
if i == j["name"]:
|
||||
namelist.append(j[label])
|
||||
if i["name"] == j["name"]:
|
||||
j_label=j["label"]
|
||||
namelist.append(j_label)
|
||||
print("namelist",namelist)
|
||||
#获取聚合条件的label
|
||||
groupColumnlaberList=[]
|
||||
for i in groupColumnList:
|
||||
for j in fields:
|
||||
if i["name"] == j["name"]:
|
||||
j_label=j["label"]
|
||||
groupColumnlaberList.append(j_label)
|
||||
print("groupColumnlaberList",groupColumnlaberList)
|
||||
#图表类型列表
|
||||
chartType_1=["line","pie","bar","area","table"]
|
||||
chartType_2=["pie","bar","table"]
|
||||
chartType=[]
|
||||
#随机选择图表类型
|
||||
# #随机选择图表类型
|
||||
s=1
|
||||
for i in namelist:
|
||||
if i == "Receive Time" or i == "Start Time" or i == "End Time":
|
||||
chartType=random.sample(chartType_1, 1)
|
||||
else:
|
||||
chartType=random.sample(chartType_2, 1)
|
||||
|
||||
if chartType[0] == "line":
|
||||
s+=1
|
||||
if s != 1:
|
||||
chartType=random.sample(chartType_1, 1)
|
||||
else:
|
||||
chartType=random.sample(chartType_2, 1)
|
||||
chardict={}
|
||||
print("chartType",chartType)
|
||||
if chartType[0] == "line" or chartType[0] == "area":
|
||||
dataBinding=[]
|
||||
#将时间条件赋值给dataBinding
|
||||
for j in namelist:
|
||||
if j == "Receive Time" or j == "Start Time" or j == "End Time":
|
||||
dataBinding.append(j)
|
||||
timelin={
|
||||
"dataBinding": dataBinding[0],
|
||||
"format": "Time"
|
||||
}
|
||||
print("timelin",timelin)
|
||||
namelist.remove(dataBinding[0]) #从统计查询数据列对象内去掉时间条件
|
||||
groupColumnlaberList.remove(dataBinding[0]) #从聚合条件内去掉时间的条件
|
||||
for i in groupColumnlaberList: #从统计查询条件内去掉聚合条件内的值
|
||||
namelist.remove(i)
|
||||
print("namelistrome",namelist)
|
||||
linlist=[]
|
||||
for i in namelist:
|
||||
lindict={
|
||||
"dataBinding": i,
|
||||
"type": "Line Up",
|
||||
"format": "Default",
|
||||
}
|
||||
linlist.append(lindict)
|
||||
listdict={
|
||||
"name": testname,
|
||||
"datasetId": datasetid,
|
||||
"datasetName": "",
|
||||
"chartType": chartType[0],
|
||||
"dataTop": 0,
|
||||
"orderBy": "",
|
||||
"orderDesc": 0,
|
||||
"drilldownTop": 0,
|
||||
"timeline": timelin,
|
||||
"line": linlist
|
||||
}
|
||||
chardict={"list": listdict}
|
||||
elif chartType[0] == "pie" or chartType[0] == "bar":
|
||||
xAxisdataBinding=random.sample(groupColumnlaberList, 1)
|
||||
xAxisdict={
|
||||
"dataBinding": xAxisdataBinding[0],
|
||||
"dataTop": 5,
|
||||
"dataType": ""
|
||||
}
|
||||
for i in groupColumnlaberList:
|
||||
namelist.remove(i)
|
||||
yAxisBinding=random.sample(namelist, 1)
|
||||
yAxisdict={
|
||||
"dataBinding": yAxisBinding[0],
|
||||
"format": "Default",
|
||||
}
|
||||
yAxislist=[yAxisdict]
|
||||
listdict={
|
||||
"name": testname,
|
||||
"datasetId": datasetid,
|
||||
"datasetName": "",
|
||||
"chartType": chartType[0],
|
||||
"dataTop": 0,
|
||||
"orderBy": "",
|
||||
"orderDesc": "",
|
||||
"xAxis": xAxisdict,
|
||||
"yAxis": yAxislist
|
||||
}
|
||||
chardict={"list": listdict}
|
||||
elif chartType[0] == "table":
|
||||
columnslist=[]
|
||||
for i in namelist:
|
||||
dataBindings={
|
||||
"dataType": "",
|
||||
"dataBinding": i,
|
||||
"format": "Default",
|
||||
}
|
||||
dataBindingslist=[]
|
||||
dataBindingslist.append(dataBindings)
|
||||
columnsdict={
|
||||
"title": i,
|
||||
"width": 0,
|
||||
"dataBindings": dataBindingslist
|
||||
}
|
||||
columnslist.append(columnsdict)
|
||||
|
||||
listdict={
|
||||
"name": testname,
|
||||
"datasetId": datasetid,
|
||||
"datasetName": "",
|
||||
"chartType": "table",
|
||||
"dataTop": 5,
|
||||
"orderBy": "",
|
||||
"orderDesc": "",
|
||||
"drilldownTop": 5,
|
||||
"tableType": "Regular",
|
||||
"columns": columnslist
|
||||
}
|
||||
chardict={"list": listdict}
|
||||
print(json.dumps(chardict))
|
||||
return json.dumps(chardict)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
elif chartType[0] == "pie":
|
||||
print(111)
|
||||
elif chartType[0] == "bar":
|
||||
print(111)
|
||||
|
||||
elif chartType[0] == "area":
|
||||
print(111)
|
||||
|
||||
elif chartType[0] == "table":
|
||||
print(111)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def ReportInterfaceTest(schemaurl,token,dataseturl,datasetgeturl,testname):
|
||||
def Reportsjson(chartId,testname):
|
||||
charlist=[]
|
||||
chardict={
|
||||
"chartId": chartId,
|
||||
"timeGranulartiy": 1,
|
||||
"timeUnit": "",
|
||||
# "disabled": true
|
||||
}
|
||||
charlist.append(chardict)
|
||||
reportJobList=[]
|
||||
reportJobdct_1={
|
||||
"rangeType": "last",
|
||||
"rangeInterval": 1,
|
||||
"rangeUnit": "week",
|
||||
"jobName": testname,
|
||||
"scheduleId": "",
|
||||
"chartList": charlist,
|
||||
"isNotice": 0,
|
||||
"noticeMethod": "",
|
||||
"startTime": "",
|
||||
"endTime": "",
|
||||
"filterCondition": None,
|
||||
"isDisplayTrafficTrend": 1
|
||||
}
|
||||
reportJobdct_2={"reportJobList": reportJobdct_1}
|
||||
print(json.dumps(reportJobdct_2))
|
||||
return json.dumps(reportJobdct_2)
|
||||
|
||||
def ReportInterfaceTest(schemaurl,token,dataseturl,charurl,repporturl,datasetgeturl,chargeturl,testname,logtype):
|
||||
headers = {"Content-Type": "application/json","Authorization": token}
|
||||
reportjsom=datasetjson(schemaurl, token,testname)
|
||||
response1 = requests.post(url=dataseturl, data=reportjsom, headers=headers)
|
||||
print("返回数据",response1)
|
||||
#dataset生成json串并发送请求
|
||||
_datasetjson=datasetjson(schemaurl, token,testname,logtype)
|
||||
response1 = requests.post(url=dataseturl, data=_datasetjson, headers=headers)
|
||||
print("返回数据1",response1)
|
||||
code = response1.json()["code"]
|
||||
print("code:",code)
|
||||
print("datasetcode:",code)
|
||||
assert code == 200
|
||||
#获取id
|
||||
|
||||
#获取dataset的id
|
||||
datasetget=requests.get(url=datasetgeturl,headers=headers)
|
||||
print(datasetget.json())
|
||||
dasetget=datasetget.json()
|
||||
id=dasetget["data"]["list"][0]["id"]
|
||||
return id
|
||||
|
||||
|
||||
datesetid=dasetget["data"]["list"][0]["id"]
|
||||
_datasetjson=json.loads(_datasetjson)
|
||||
queryColumnList=_datasetjson["list"]["queryColumnList"]
|
||||
groupColumnList=_datasetjson["list"]["groupColumnList"]
|
||||
#生成charlibrariesjson串
|
||||
charlibrariesjson=charjson(schemaurl, token,queryColumnList,groupColumnList,datesetid,testname,logtype)
|
||||
response2 = requests.post(url=charurl, data=charlibrariesjson, headers=headers)
|
||||
code = response2.json()["code"]
|
||||
assert code == 200
|
||||
|
||||
#获取char libraries的id
|
||||
charget=requests.get(url=chargeturl,headers=headers)
|
||||
charget=charget.json()
|
||||
charid=charget["data"]["list"][0]["id"]
|
||||
|
||||
#report生成json串并发送请求
|
||||
reportjson=Reportsjson(charid,testname)
|
||||
response3 = requests.post(url=repporturl, data=reportjson, headers=headers)
|
||||
code = response3.json()["code"]
|
||||
assert code == 200
|
||||
|
||||
|
||||
|
||||
@@ -400,3 +518,4 @@ def ReportInterfaceTest(schemaurl,token,dataseturl,datasetgeturl,testname):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user