report接口测试关键字
This commit is contained in:
@@ -4,6 +4,28 @@ Resource ../../../03-Variable/bifangapivariable.txt
|
||||
Library OperatingSystem
|
||||
Resource ../../../02-Keyword/tsg_ui/setting/Settings.robot
|
||||
Library ../../../04-CustomLibrary/Custometest/UIAssert.py
|
||||
Library ../../../04-CustomLibrary/Custometest/ReportSchema.py
|
||||
Library DateTime
|
||||
Library json
|
||||
Library Selenium2Library
|
||||
Library RequestsLibrary
|
||||
Library Collections
|
||||
Library String
|
||||
Library GetTimeLibrary
|
||||
Resource ../../../03-Variable/BifangApiVariable.txt
|
||||
Resource ../../../02-Keyword/tsg_bfapi/Common.robot
|
||||
Resource ../../../02-Keyword/tsg_bfapi/offline_stat_report/ApiRequest1.robot
|
||||
Resource ../../../02-Keyword/tsg_adc/FileOperation.robot
|
||||
|
||||
*** Variables ***
|
||||
${dataset_url} /${version}/report/dataset
|
||||
${datasetId} ${EMPTY}
|
||||
${reportId} ${EMPTY}
|
||||
${report_url} /${version}/report/offlinejob
|
||||
${chartId} ${EMPTY}
|
||||
${chart_url} /${version}/report/chart
|
||||
${result_url} /${version}/report/offlinejob/result
|
||||
${resultId} ${EMPTY}
|
||||
|
||||
*** Test Cases ***
|
||||
CreateAndEdit
|
||||
@@ -19,6 +41,45 @@ NoName
|
||||
ResponsrPageCreateAndEdit ${ResponsrPageInfo}
|
||||
|
||||
|
||||
ReportInterfaceTest
|
||||
log report
|
||||
${logtype} Set Variable security_event_log
|
||||
${schemaurl} Set Variable http://${host}:${port}/${version}/log/schema?logType=${logtype}
|
||||
${dataset_url} Set Variable http://${host}:${port}/${version}/report/dataset
|
||||
${char_url} Set Variable http://${host}:${port}/${version}/report/chart
|
||||
${report_url} Set Variable http://${host}:${port}/${version}/report/offlinejob
|
||||
${dataset_geturl} Set Variable ${dataset_url}?pageSize=20&pageNo=1&id=&name=${TEST NAME}&logType=&opStartTime=&opEndTime=&opUser=
|
||||
${char_geturl} Set Variable ${char_url}?pageSize=20&pageNo=1&id=&name=${TEST NAME}&opUser=
|
||||
ReportInterfaceTest ${schemaurl} ${token} ${dataset_url} ${char_url} ${report_url} ${dataset_geturl} ${char_geturl} ${TEST NAME} ${logtype}
|
||||
# log ${aaaa}
|
||||
# BasePostRequestOK ${chart_url} {"list":{"id":null,"name":"${TEST NAME}","description":"","datasetId":"${id}","chartType":"line","dataTop":0,"orderBy":"","orderDesc":0,"drilldownTop":0,"includeOther":false,"timeline":{"dataBinding":"Receive Time","label":"","format":"Time"},"line":[{"dataBinding":"Client IP","type":"Line Up","format":"Default","legend":"Client IP"}],"groupBy":null},"refuseCode":true}
|
||||
# ${response1} BaseGetRequestOK ${chart_url} pageSize=20&pageNo=1&id=&name=${TEST NAME}&opUser=
|
||||
# ${chartId} Set Variable ${response1}[data][list][0][id]
|
||||
|
||||
# Comment 创建Report
|
||||
# BasePostRequestOK ${report_url} {"reportJobList":{"rangeType":"yesterday","rangeInterval":"","rangeUnit":"","jobName":"${TEST NAME}","scheduleId":"","chartList":[{"chartId":${chartId},"timeGranulartiy":30,"timeUnit":"minute","disabled":false}],"isNotice":0,"noticeMethod":"","receivers":[""],"receiver":"","startTime":"","endTime":"","filterCondition":null,"isDisplayTrafficTrend":0}}
|
||||
|
||||
|
||||
datasetjsontest
|
||||
${schemaurl} Set Variable http://192.168.44.72:8080/v1/log/schema?logType=security_event_log
|
||||
log date1111111
|
||||
datasetjson ${schemaurl} ${token}
|
||||
|
||||
reporttest
|
||||
log 开始
|
||||
BasePostRequestOK ${dataset_url} {"list": {"name": "ReportInterfaceTest", "logType": "security_event_log", "groupColumnList": [{"name": "common_subscriber_id"}, {"name": "common_l7_protocol"}, {"name": "mail_account"}, {"name": "common_device_id"}], "queryColumnList": [{"name": "common_subscriber_id"}, {"name": "common_l7_protocol"}, {"name": "mail_account"}, {"name": "common_device_id"}, {"name": "common_s2c_pkt_num", "expression": "avg"}, {"name": "common_establish_latency_ms", "expression": "max"}], "filterCondition": {"andConditions": [{"orConditions": [{"name": "common_con_duration_ms", "expression": "!=", "value": ["12289"], "type": "int"}]}, {"orConditions": [{"name": "common_establish_latency_ms", "expression": ">", "value": ["12289"], "type": "int"}]}, {"orConditions": [{"name": "common_sled_ip", "expression": "!=", "value": ["192.168.50.11"], "type": "string"}]}]}, "havingCondition": {"andConditions": [{"orConditions": [{"name": "mail_to", "function": "count_distinct", "expression": "=", "value": "97658"}]}, {"orConditions": [{"name": "common_subscriber_id", "function": "count_distinct", "expression": "<", "value": "97658"}]}, {"orConditions": [{"name": "ssl_sni", "function": "count", "expression": "<", "value": "97658"}]}]}}}
|
||||
${response} BaseGetRequestOK ${dataset_url} pageSize=20&pageNo=1&id=&name=test&logType=&opStartTime=&opEndTime=&opUser=
|
||||
${datasetId} Set Variable ${response}[data][list][0][id]
|
||||
|
||||
|
||||
chartest
|
||||
BasePostRequestOK ${chart_url} {"list": {"name": "ReportInterfaceTest", "datasetId": 281, "datasetName": "", "chartType": "pie", "dataTop": 0, "orderBy": "", "orderDesc": "", "xAxis": {"dataBinding": "Client Location", "dataTop": 5, "dataType": 3}, "yAxis": [{"dataBinding": "Establish Latency(ms)", "format": "Default"}]}}
|
||||
# ${response1} BaseGetRequestOK ${chart_url} pageSize=20&pageNo=1&id=&name=${TEST NAME}&opUser=
|
||||
# ${chartId} Set Variable ${response1}[data][list][0][id]
|
||||
|
||||
chartest11
|
||||
log 输出111111
|
||||
${logtype} Set Variable security_event_log
|
||||
${schemaurl} Set Variable http://${host}:${port}/${version}/log/schema?logType=${logtype}
|
||||
chartest ${schemaurl} ${token}
|
||||
|
||||
test
|
||||
ttt
|
||||
@@ -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