提交log用例示例和log关键字(Python文件)

This commit is contained in:
lyf
2021-03-26 10:50:43 +08:00
parent e987c67721
commit bf2def3ecd
3 changed files with 212 additions and 61 deletions

View File

@@ -3,28 +3,24 @@
import requests
import random
import json
import allure
number = random.randint(0,100000)
str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
str = random.choice('abcdefghijklmnopqrstuvwxyz')
list = []
# def schema():
# url = "http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
# headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":"555b5dc2-d69f-44a4-8a00-171e81edd739&889&"}
# response = requests.get(url=url,headers=headers)
# return response.json()
#请求schema接口得到返回数据用于其他接口
def schema(schemauerl,token):
url = schemauerl #"http://192.168.44.72:8080/v1/log/schema?logType=security_event_log"
headers = {"Content-Type":"application/x-www-form-urlencoded","Authorization":token}
response = requests.get(url=url,headers=headers)
return response.json()
def Filter1(schema):
print("1234")
print(type(schema))
json_str = json.dumps(schema)
schema1 = json.loads(json_str)
fields = schema1["data"]["fields"]
#print(fields)
#print(type(fields))
operator = schema1["data"]["doc"]["schema_query"]["references"]["operator"]
#print(operator)
#根据schema接口返回数据得出所有属性所支持的比较类型的列表
def Filter1(schemauerl,token):
json_str = schema(schemauerl,token)
print(type(json_str))
fields = json_str["data"]["fields"]
operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"]
for i in fields:
print(i)
name = i["name"]
doc = i["doc"]
if doc == None:
@@ -36,15 +32,26 @@ def Filter1(schema):
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1 = name + " "+v + " "+ f"{value1}"
list.append(str1)
if v=="in" or v == "not in":
str1 = name + " "+v + " "+ "(" +f"{value1}" + ")"
list.append(str1)
else:
str1 = name + " " + v + " " + f"{value1}"
list.append(str1)
elif type1 == "string":
value1 = str
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1 = name + " "+v + " "+ value1
list.append(str1)
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)
else:
if i["doc"]["constraints"]== None:
type1 = i["type"]
@@ -55,15 +62,26 @@ def Filter1(schema):
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1 = name + " "+v + " "+ f"{value1}"
list.append(str1)
if v == "in" or v == "not in":
str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
list.append(str1)
else:
str1 = name + " " + v + " " + f"{value1}"
list.append(str1)
elif type1=="string":
value1 = str
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1=name + " "+v + " "+ value1
list.append(str1)
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)
else:
if i["doc"]["constraints"]["operator_functions"]==None:
@@ -75,15 +93,26 @@ def Filter1(schema):
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1 = name + " "+ v + " "+ f"{value1}"
list.append(str1)
if v == "in" or v == "not in" :
str1 = name + " " + v + " " + "(" + f"{value1}" + ")"
list.append(str1)
else:
str1 = name + " " + v + " " + f"{value1}"
list.append(str1)
elif type1 == "string":
value1 = str
functions = j["functions"]
functions1 = functions.split(",")
for v in functions1:
str1 = name + " "+ v + " "+ value1
list.append(str1)
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)
else:
type1 = i["type"]
operator1 = i["doc"]["constraints"]["operator_functions"]
@@ -97,29 +126,79 @@ def Filter1(schema):
list.append(str1)
else:
for o in operator2:
str1 = name + " "+ o + " "+ code
str1 = name + " "+ o + " "+ " '" + code + " '"
list.append(str1)
print(list)
return list
# def api():
# filter2 = Filter1()
# a = schema()
# fields = a["data"]["fields"]
# for i in filter2:
# url = "http://192.168.32.59:8888/v1/log/list"
# headers = {"Content-Type": "application/json",
# "Authorization": "7dda2581-38ca-4c48-9103-98ab852a5be5&807&"}
# data = {
# "start_common_recv_time":'2021-03-20 16:36:41',
# "end_common_recv_time":'2021-03-21 17:36:41',
# "logType":"security_event_log",
# "fields":fields,
# "filter":i
# }
# print(data)
# response1 = requests.post(url=url, data=json.dumps(data),headers=headers)
# print(response1.json())
# return response1.json()
#
# if __name__ == '__main__':
# api()
#根据Filter1方法中的的数据写入log请求接口中来验证log请求接口
def logapiverify(logurl,schemauerl,token,starttime,endtime,logtype):
filter2 = Filter1(schemauerl,token)
a = schema(schemauerl,token)
fields = a["data"]["fields"]
print(fields)
str2 = ""
for i in filter2:
str2 = str2 + i + " " + "and" + " "
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":i
}
print(data)
print(json.dumps(data))
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")