上传log查询返回数据验证方法及样例
This commit is contained in:
@@ -4,6 +4,10 @@ Resource ../../../03-Variable/bifangapivariable.txt
|
|||||||
Library OperatingSystem
|
Library OperatingSystem
|
||||||
Resource ../../../02-Keyword/tsg_ui/setting/Settings.robot
|
Resource ../../../02-Keyword/tsg_ui/setting/Settings.robot
|
||||||
Library ../../../04-CustomLibrary/Custometest/UIAssert.py
|
Library ../../../04-CustomLibrary/Custometest/UIAssert.py
|
||||||
|
Library ../../../04-CustomLibrary/Custometest/Schema.py
|
||||||
|
Library ../../../04-CustomLibrary/Custometest/LogResponseVAL.py
|
||||||
|
Library DateTime
|
||||||
|
Library String
|
||||||
Library Selenium2Library
|
Library Selenium2Library
|
||||||
|
|
||||||
*** Variables ***
|
*** Variables ***
|
||||||
@@ -22,5 +26,25 @@ NoName
|
|||||||
ResponsrPageCreateAndEdit ${ResponsrPageInfo}
|
ResponsrPageCreateAndEdit ${ResponsrPageInfo}
|
||||||
|
|
||||||
|
|
||||||
|
logtest
|
||||||
|
log logtest11111111111111111
|
||||||
|
${Logurl} Set Variable http://${host}:${port}/v1/log/list
|
||||||
|
${logType} Set Variable security_event_log
|
||||||
|
${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType}
|
||||||
|
${EndTime} get current date
|
||||||
|
${EndTime1} Get Substring ${EndTime} \ -4
|
||||||
|
${StartTime} add time to date ${EndTime} -01:00:00
|
||||||
|
${StartTime1} Get Substring ${StartTime} \ -4
|
||||||
|
${filter} Set Variable common_log_id=238347398589845504 OR common_log_id=238347398522859520
|
||||||
|
${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter}
|
||||||
|
${targetdict} create list common_log_id = 237434463277422592
|
||||||
|
log ${responsebody}
|
||||||
|
${strlist} FieldValidation ${responsebody} ${targetdict}
|
||||||
|
log ${strlist}
|
||||||
|
Assertresults ${strlist}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
141
04-CustomLibrary/Custometest/LogResponseVAL.py
Normal file
141
04-CustomLibrary/Custometest/LogResponseVAL.py
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
def conditional(conditions,value2,targetkey,sum,value=None):
|
||||||
|
str1=""
|
||||||
|
if conditions == "=":
|
||||||
|
if value != value2:
|
||||||
|
str1= "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符"
|
||||||
|
|
||||||
|
if conditions == "!=":
|
||||||
|
if value == value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
print(str1)
|
||||||
|
|
||||||
|
if conditions == ">":
|
||||||
|
if int(value2) <= int(value):
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "<":
|
||||||
|
if int(value2) >= int(value):
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == ">=":
|
||||||
|
if int(value2) < int(value):
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "<=":
|
||||||
|
if int(value2) > int(value):
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "in":
|
||||||
|
value=value.split(",")
|
||||||
|
if value2 not in value:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "notin":
|
||||||
|
value=value.split(",")
|
||||||
|
if value2 in value:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "like":
|
||||||
|
left= value[0]
|
||||||
|
right=value[-1]
|
||||||
|
if left == "%" and right == "%":
|
||||||
|
value=value[1:len(value)-1]
|
||||||
|
if value not in value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
elif left == "%" and right != "%":
|
||||||
|
v=len(value)
|
||||||
|
_value = value[1:]
|
||||||
|
_value2 = value2[-(v-1):]
|
||||||
|
print(_value,_value2)
|
||||||
|
if _value != _value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
elif left != "%" and right == "%":
|
||||||
|
v=len(value)
|
||||||
|
_value = value[0:-1]
|
||||||
|
_value2=value2[0:v-1]
|
||||||
|
if _value != _value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "notlike":
|
||||||
|
left = value[0]
|
||||||
|
right = value[-1]
|
||||||
|
if left == "%" and right == "%":
|
||||||
|
value = value[1:len(value) - 1]
|
||||||
|
if value in value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
elif left == "%" and right != "%":
|
||||||
|
v = len(value)
|
||||||
|
_value = value[1:]
|
||||||
|
_value2 = value2[-(v-1):]
|
||||||
|
if _value == _value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
elif left != "%" and right == "%":
|
||||||
|
v = len(value)
|
||||||
|
_value = value[0:-1]
|
||||||
|
_value2 = value2[0:v - 1]
|
||||||
|
if _value == _value2:
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "notEmpty":
|
||||||
|
if value2 == "":
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
if conditions == "Empty":
|
||||||
|
if value2 != "":
|
||||||
|
str1 = "返回数据第" + str(sum) + "组数据中," + targetkey + "的值与和条件不符。"
|
||||||
|
|
||||||
|
return str1
|
||||||
|
|
||||||
|
|
||||||
|
def FieldValidation(responsedict, targetlist):
|
||||||
|
responselist = responsedict["data"]["list"]
|
||||||
|
strlist = []
|
||||||
|
if responselist:
|
||||||
|
#循环返回数据列表
|
||||||
|
sum = 1
|
||||||
|
for response in responselist:
|
||||||
|
# 循环目地列表
|
||||||
|
for t in targetlist:
|
||||||
|
#将目的根据空格分割成列表 (“key值”,“判断条件”,“value值”)
|
||||||
|
target=t.split(" ")
|
||||||
|
print("target",target)
|
||||||
|
#判断目的条件的Key在数据中是否存在
|
||||||
|
if target[0] in response:
|
||||||
|
targetkey = target[0]
|
||||||
|
#判断条件
|
||||||
|
conditions=target[1]
|
||||||
|
#目的Value
|
||||||
|
# 对应Key返回数据的Value
|
||||||
|
responsevalue = response[target[0]]
|
||||||
|
print(targetkey,conditions,responsevalue)
|
||||||
|
print(len(target))
|
||||||
|
if len(target) == 3:
|
||||||
|
targetvalue=target[2]
|
||||||
|
p=conditional(conditions,responsevalue,targetkey,sum,targetvalue)
|
||||||
|
strlist.append(p)
|
||||||
|
elif len(target) == 2:
|
||||||
|
p=conditional(conditions, responsevalue, targetkey, sum)
|
||||||
|
strlist.append(p)
|
||||||
|
else:
|
||||||
|
str2 = "返回数据第" + str(sum) + "组数据中不存在该字段:" + target[0]
|
||||||
|
print(str2)
|
||||||
|
strlist.append(str2)
|
||||||
|
sum+=1
|
||||||
|
else:
|
||||||
|
str3 = "返回数据中无数据"
|
||||||
|
strlist.append(str3)
|
||||||
|
|
||||||
|
return strlist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def Assertresults(resultslist):
|
||||||
|
print(resultslist)
|
||||||
|
for i in resultslist:
|
||||||
|
if i != "":
|
||||||
|
assert 1==2
|
||||||
|
|
||||||
Reference in New Issue
Block a user