提交log用例示例和log关键字(Python文件)
This commit is contained in:
56
01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot
Normal file
56
01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
*** Settings ***
|
||||||
|
Resource ../../../03-Variable/BifangApiVariable.txt
|
||||||
|
Library ../../../04-CustomLibrary/Custometest/Schema.py
|
||||||
|
Library DateTime
|
||||||
|
Library json
|
||||||
|
Library OperatingSystem
|
||||||
|
Library Selenium2Library
|
||||||
|
Library RequestsLibrary
|
||||||
|
Library Collections
|
||||||
|
Library String
|
||||||
|
|
||||||
|
*** Variables ***
|
||||||
|
${url} /${version}/report/url/recommend
|
||||||
|
|
||||||
|
*** Test Cases ***
|
||||||
|
LogApiVerifyCase-001
|
||||||
|
[Documentation] 验证api接口
|
||||||
|
${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
|
||||||
|
|
||||||
|
logapiverify ${logurl} ${schemaurl} ${token} ${StartTime1} ${EndTime1} ${logtype}
|
||||||
|
|
||||||
|
|
||||||
|
LogApiVerifyCase-002
|
||||||
|
[Documentation] 验证api接口
|
||||||
|
${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_recv_time = 45535
|
||||||
|
|
||||||
|
${responsebody} loglistverify ${logurl} ${schemaurl} ${token} ${StartTime1} ${EndTime1} ${logtype} ${filter}
|
||||||
|
|
||||||
|
log ${responsebody}
|
||||||
|
|
||||||
@@ -11,16 +11,25 @@ Resource ../tsg_bfapi/ApiRequest.robot
|
|||||||
Resource Log_schema.robot
|
Resource Log_schema.robot
|
||||||
Resource ../tsg_bfapi/Common.robot
|
Resource ../tsg_bfapi/Common.robot
|
||||||
Library ../../04-CustomLibrary/Custometest/Schema.py
|
Library ../../04-CustomLibrary/Custometest/Schema.py
|
||||||
|
Resource ../../03-Variable/BifangApiVariable.txt
|
||||||
|
|
||||||
*** Test Cases ***
|
*** Test Cases ***
|
||||||
Apitext
|
Apitext
|
||||||
|
${logurl} Set Variable http://192.168.44.72:8080/v1/log/list
|
||||||
|
|
||||||
|
${logtype} Set Variable security_event_log
|
||||||
|
|
||||||
|
${schemaurl} Set Variable http://192.168.44.72:8080/v1/log/schema?logType=${logtype}
|
||||||
|
|
||||||
${EndTime} get current date
|
${EndTime} get current date
|
||||||
|
|
||||||
${EndTime1} Get Substring ${EndTime} \ -4
|
${EndTime1} Get Substring ${EndTime} \ -4
|
||||||
|
|
||||||
${StartTime} add time to date ${EndTime} -01:00:00
|
${StartTime} add time to date ${EndTime} -01:00:00
|
||||||
|
|
||||||
${StartTime1} Get Substring ${StartTime} \ -4
|
${StartTime1} Get Substring ${StartTime} \ -4
|
||||||
log ${StartTime1}
|
|
||||||
log ${EndTime1}
|
logapiverify ${logurl} ${schemaurl} ${token} ${StartTime1} ${EndTime1} ${logtype}
|
||||||
LogApiSearch ${StartTime1} ${EndTime1} security_event_log v1/log/list
|
|
||||||
|
|
||||||
*** Keywords ***
|
*** Keywords ***
|
||||||
log_search
|
log_search
|
||||||
@@ -47,10 +56,16 @@ LogApiSearch
|
|||||||
log 11111111${type1}
|
log 11111111${type1}
|
||||||
${schemaresponsedata1} Get From Dictionary ${schemaresponsedata} data
|
${schemaresponsedata1} Get From Dictionary ${schemaresponsedata} data
|
||||||
${filds} Get From Dictionary ${schemaresponsedata1} fields
|
${filds} Get From Dictionary ${schemaresponsedata1} fields
|
||||||
${filedsJson} json.dumps ${filds}
|
${type3} Evaluate "${filds}".replace(' ','')
|
||||||
|
#${type2} Evaluate ${type3}.replace(' ','')
|
||||||
|
${type2} Evaluate type(${type3})
|
||||||
|
log ${type2}
|
||||||
|
log ${type3}
|
||||||
|
#${filedsJson} json.dumps ${type3}
|
||||||
|
log ${type3}
|
||||||
${filter1} run keyword if "${filter}"=="null" Filter1 ${schemaresponsedata}
|
${filter1} run keyword if "${filter}"=="null" Filter1 ${schemaresponsedata}
|
||||||
run keyword if "${filter}"=="null" ForFilter ${start-time} ${end-time} ${logtype} ${url}
|
run keyword if "${filter}"=="null" ForFilter ${start-time} ${end-time} ${logtype} ${url}
|
||||||
... ${filedsJson} ${conditions} ${filter1}
|
... ${type3} ${conditions} ${filter1}
|
||||||
... ELSE LogSearchRequest ${start-time} ${end-time} ${logtype} ${url}
|
... ELSE LogSearchRequest ${start-time} ${end-time} ${logtype} ${url}
|
||||||
... ${conditions} ${filter}
|
... ${conditions} ${filter}
|
||||||
# ${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${type}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":true}
|
# ${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${type}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":true}
|
||||||
@@ -61,10 +76,11 @@ LogSearchRequest
|
|||||||
[Arguments] ${start-time} ${end-time} ${logtype} ${url} ${filedsJson} ${conditions} ${filter}
|
[Arguments] ${start-time} ${end-time} ${logtype} ${url} ${filedsJson} ${conditions} ${filter}
|
||||||
# ${type2} Evaluate type(${filedsJson})
|
# ${type2} Evaluate type(${filedsJson})
|
||||||
# log 7777${type2}
|
# log 7777${type2}
|
||||||
${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${logtype}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":true}
|
${requestbody} Set Variable {"start_common_recv_time":"${start-time}","end_common_recv_time":"${end-time}","logType":"${logtype}","fields":${filedsJson},"conditions":${conditions},"filter":${filter},refuseCode":"true"}
|
||||||
|
log ${requestbody}
|
||||||
#${requestbody1} json.loads ${requestbody}
|
#${requestbody1} json.loads ${requestbody}
|
||||||
#${type1} Evaluate type(${requestbody})
|
# ${type2} Evaluate type(${requestbody})
|
||||||
#log 88888888${type1}
|
# log 88888888${type2}
|
||||||
${response} Post-Request ${url} ${requestbody}
|
${response} Post-Request ${url} ${requestbody}
|
||||||
${code} Get From Dictionary ${response} code
|
${code} Get From Dictionary ${response} code
|
||||||
log 22222222${response}
|
log 22222222${response}
|
||||||
|
|||||||
@@ -3,28 +3,24 @@
|
|||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
|
import allure
|
||||||
number = random.randint(0,100000)
|
number = random.randint(0,100000)
|
||||||
str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
|
str = random.choice('abcdefghijklmnopqrstuvwxyz')
|
||||||
list = []
|
list = []
|
||||||
# def schema():
|
#请求schema接口得到返回数据,用于其他接口
|
||||||
# url = "http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
|
def schema(schemauerl,token):
|
||||||
# headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":"555b5dc2-d69f-44a4-8a00-171e81edd739&889&"}
|
url = schemauerl #"http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
|
||||||
# response = requests.get(url=url,headers=headers)
|
headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":token}
|
||||||
# return response.json()
|
response = requests.get(url=url,headers=headers)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
def Filter1(schema):
|
#根据schema接口返回数据,得出所有属性所支持的比较类型的列表
|
||||||
print("1234")
|
def Filter1(schemauerl,token):
|
||||||
print(type(schema))
|
json_str = schema(schemauerl,token)
|
||||||
json_str = json.dumps(schema)
|
print(type(json_str))
|
||||||
schema1 = json.loads(json_str)
|
fields = json_str["data"]["fields"]
|
||||||
fields = schema1["data"]["fields"]
|
operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"]
|
||||||
#print(fields)
|
|
||||||
|
|
||||||
#print(type(fields))
|
|
||||||
operator = schema1["data"]["doc"]["schema_query"]["references"]["operator"]
|
|
||||||
#print(operator)
|
|
||||||
for i in fields:
|
for i in fields:
|
||||||
print(i)
|
|
||||||
name = i["name"]
|
name = i["name"]
|
||||||
doc = i["doc"]
|
doc = i["doc"]
|
||||||
if doc == None:
|
if doc == None:
|
||||||
@@ -36,14 +32,25 @@ def Filter1(schema):
|
|||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1 = name + " "+v + " "+ f"{value1}"
|
if v=="in" or v == "not in":
|
||||||
|
str1 = name + " "+v + " "+ "(" +f"{value1}" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + f"{value1}"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
elif type1 == "string":
|
elif type1 == "string":
|
||||||
value1 = str
|
value1 = str
|
||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1 = name + " "+v + " "+ value1
|
if v == "not empty" or v == "empty":
|
||||||
|
str1 = v + "(" + " '" + name + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
elif v == "in" or v == "not in":
|
||||||
|
str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + " '"+ value1 + " '"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
else:
|
else:
|
||||||
if i["doc"]["constraints"]== None:
|
if i["doc"]["constraints"]== None:
|
||||||
@@ -55,14 +62,25 @@ def Filter1(schema):
|
|||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1 = name + " "+v + " "+ f"{value1}"
|
if v == "in" or v == "not in":
|
||||||
|
str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + f"{value1}"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
elif type1=="string":
|
elif type1=="string":
|
||||||
value1 = str
|
value1 = str
|
||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1=name + " "+v + " "+ value1
|
if v == "not empty" or v == "empty":
|
||||||
|
str1 = v + "(" + " '" + name + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
elif v == "in" or v == "not in":
|
||||||
|
str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + " '" + value1 + " '"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -75,14 +93,25 @@ def Filter1(schema):
|
|||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1 = name + " "+ v + " "+ f"{value1}"
|
if v == "in" or v == "not in" :
|
||||||
|
str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + f"{value1}"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
elif type1 == "string":
|
elif type1 == "string":
|
||||||
value1 = str
|
value1 = str
|
||||||
functions = j["functions"]
|
functions = j["functions"]
|
||||||
functions1 = functions.split(",")
|
functions1 = functions.split(",")
|
||||||
for v in functions1:
|
for v in functions1:
|
||||||
str1 = name + " "+ v + " "+ value1
|
if v == "not empty" or v == "empty":
|
||||||
|
str1 = v + "(" + " '" + name + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
elif v == "in" or v == "not in":
|
||||||
|
str1 = name + " " + v + " " + "(" + " '" + value1 + " '" + ")"
|
||||||
|
list.append(str1)
|
||||||
|
else:
|
||||||
|
str1 = name + " " + v + " " + " '" + value1 + " '"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
else:
|
else:
|
||||||
type1 = i["type"]
|
type1 = i["type"]
|
||||||
@@ -97,29 +126,79 @@ def Filter1(schema):
|
|||||||
list.append(str1)
|
list.append(str1)
|
||||||
else:
|
else:
|
||||||
for o in operator2:
|
for o in operator2:
|
||||||
str1 = name + " "+ o + " "+ code
|
str1 = name + " "+ o + " "+ " '" + code + " '"
|
||||||
list.append(str1)
|
list.append(str1)
|
||||||
print(list)
|
print(list)
|
||||||
return list
|
return list
|
||||||
# def api():
|
#根据Filter1方法中的的数据,写入log请求接口中,来验证log请求接口
|
||||||
# filter2 = Filter1()
|
def logapiverify(logurl,schemauerl,token,starttime,endtime,logtype):
|
||||||
# a = schema()
|
filter2 = Filter1(schemauerl,token)
|
||||||
# fields = a["data"]["fields"]
|
a = schema(schemauerl,token)
|
||||||
# for i in filter2:
|
fields = a["data"]["fields"]
|
||||||
# url = "http://192.168.32.59:8888/v1/log/list"
|
print(fields)
|
||||||
# headers = {"Content-Type": "application/json",
|
str2 = ""
|
||||||
# "Authorization": "7dda2581-38ca-4c48-9103-98ab852a5be5&807&"}
|
for i in filter2:
|
||||||
# data = {
|
str2 = str2 + i + " " + "and" + " "
|
||||||
# "start_common_recv_time":'2021-03-20 16:36:41',
|
url = logurl #"http://192.168.44.72:8080/v1/log/list"
|
||||||
# "end_common_recv_time":'2021-03-21 17:36:41',
|
headers = {"Content-Type": "application/json",
|
||||||
# "logType":"security_event_log",
|
"Authorization": token}
|
||||||
# "fields":fields,
|
data = {
|
||||||
# "filter":i
|
"start_common_recv_time":starttime,
|
||||||
# }
|
"end_common_recv_time":endtime,
|
||||||
# print(data)
|
"logType":logtype,
|
||||||
# response1 = requests.post(url=url, data=json.dumps(data),headers=headers)
|
"fields":fields,
|
||||||
# print(response1.json())
|
"filter":i
|
||||||
# return response1.json()
|
}
|
||||||
#
|
print(data)
|
||||||
# if __name__ == '__main__':
|
print(json.dumps(data))
|
||||||
# api()
|
response1 = requests.post(url=url, data=json.dumps(data),headers=headers)
|
||||||
|
code = response1.json()["code"]
|
||||||
|
assert code == 200
|
||||||
|
print(response1.json()["code"])
|
||||||
|
return response1.json()
|
||||||
|
print(str2)
|
||||||
|
str3 = str2[0:-4]
|
||||||
|
print(str3)
|
||||||
|
url = logurl # "http://192.168.44.72:8080/v1/log/list"
|
||||||
|
headers = {"Content-Type": "application/json",
|
||||||
|
"Authorization": token}
|
||||||
|
data = {
|
||||||
|
"start_common_recv_time": starttime,
|
||||||
|
"end_common_recv_time": endtime,
|
||||||
|
"logType": logtype,
|
||||||
|
"fields": fields,
|
||||||
|
"filter": str3
|
||||||
|
}
|
||||||
|
print(data)
|
||||||
|
print(json.dumps(data))
|
||||||
|
response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||||
|
code = response1.json()["code"]
|
||||||
|
print(response1.json())
|
||||||
|
assert code == 200
|
||||||
|
print(response1.json()["code"])
|
||||||
|
|
||||||
|
#精确filter,请求日志接口
|
||||||
|
def loglistverify(logurl,schemauerl,token,starttime,endtime,logtype,filtervalue):
|
||||||
|
a = schema(schemauerl,token)
|
||||||
|
fields = a["data"]["fields"]
|
||||||
|
print(fields)
|
||||||
|
url = logurl # "http://192.168.44.72:8080/v1/log/list"
|
||||||
|
headers = {"Content-Type": "application/json",
|
||||||
|
"Authorization": token}
|
||||||
|
data = {
|
||||||
|
"start_common_recv_time": starttime,
|
||||||
|
"end_common_recv_time": endtime,
|
||||||
|
"logType": logtype,
|
||||||
|
"fields": fields,
|
||||||
|
"filter": filtervalue
|
||||||
|
}
|
||||||
|
print(data)
|
||||||
|
print(json.dumps(data))
|
||||||
|
response1 = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||||
|
code = response1.json()["code"]
|
||||||
|
print(response1.json())
|
||||||
|
assert code == 200
|
||||||
|
print(response1.json()["code"])
|
||||||
|
return response1.json()
|
||||||
|
#if __name__ == '__main__':
|
||||||
|
# logapiverify("http://192.168.32.59:8080/v1/log/list","http://192.168.32.59:8080/v1/log/schema?logType=security_event_log","d475b20d-e2b8-4f24-87ee-d54af46e6aff&807&",'2021-03-20 16:36:41','2021-03-21 17:36:41',"security_event_log")
|
||||||
Reference in New Issue
Block a user