From 8a58604003093966cd0358aec2bcceff6c74e416 Mon Sep 17 00:00:00 2001 From: wangxin Date: Sun, 28 Jun 2020 14:10:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:(=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA)?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E5=AF=BC=E5=87=BA=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/PolicyObjectTests.robot | 16 ++++++- 02-Keyword/tsg_bfapi/Common.robot | 15 +++++- 02-Keyword/tsg_bfapi/policy_object/Log.robot | 46 ++++++++++++++----- .../tsg_bfapi/policy_object/Policy.robot | 1 - 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot index 60b9b39..5dcb213 100644 --- a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -6,6 +6,7 @@ Resource ../../../02-Keyword/tsg_bfapi/policy_object/Object.robot Resource ../../../02-Keyword/tsg_bfapi/policy_object/Log.robot Resource ../../../02-Keyword/tsg_bfapi/Common.robot Library json +Library DateTime *** Variables *** @{policyIds} @{profiles} @@ -542,4 +543,17 @@ Policy-log-v1-00027 ... conditions=common_server_port|int|in|${80}^${8080} ... orderBy=common_server_ip|true ... common_log_ids=162273027957354498 - ${resData} QueryLogs ${params} count \ No newline at end of file + ${resData} QueryLogs ${params} count +Policy-log-v1-00028 + ${objectIds} Set Variable ${EMPTY} + Comment 查询schema + ${schema_query} ${schema_type} ${default_columns} ${fields} GetLogSchema security_event_log + Comment 处理schema,构造查询条件 + ${params} Create Dictionary pageSize=${10} logType=security_event_log + ... start_common_recv_time=2020-06-01 00:00:00 + ... end_common_recv_time=2020-06-24 00:00:00 + ... fields=common_log_id|long|ID,http_url|string|地址,common_client_ip|string|客户端IP,common_client_port|int|客户端端口,common_server_ip|string|服务端IP,common_server_port|int|服务端端口 + ... conditions=common_server_port|int|in|${80}^${8080} + ... orderBy=common_server_ip|true + ... common_log_ids=162273027957354498 + ${resData} QueryLogs ${params} batch \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/Common.robot b/02-Keyword/tsg_bfapi/Common.robot index 7664247..66c589c 100644 --- a/02-Keyword/tsg_bfapi/Common.robot +++ b/02-Keyword/tsg_bfapi/Common.robot @@ -168,4 +168,17 @@ BaseMultipartPostRequest log return data =${response} Should Be Equal As Strings ${response.status_code} 200 ${response} to json ${response.content} - [Return] ${response} \ No newline at end of file + [Return] ${response} +BasePostRequestReturnBinary + [Documentation] + ... 下载文件专用 + ... 返回二进制数据 + [Arguments] ${requestUri} ${data} ${apiVersion} + Log Call BasePostRequestReturnBinary + ${headers} set variable {"Authorization":"${token}","Content-Type":"application/json"} + create session api http://${host}:${port}/${apiVersion} ${headers} + Log ${data} + ${response} Post Request api ${requestUri} data=${data} + log return data =${response} + Should Be Equal As Strings ${response.status_code} 200 + [Return] ${response.content} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Log.robot b/02-Keyword/tsg_bfapi/policy_object/Log.robot index 0c206a4..94881ab 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Log.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Log.robot @@ -1,7 +1,8 @@ -*** Settings *** + *** Settings *** Library json Library Collections Library RequestsLibrary +Library DateTime Resource ../../../03-Variable/BifangApiVariable.txt Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot Resource ../Common.robot @@ -16,7 +17,7 @@ GetLogSchema [Arguments] ${logType} ${response} BaseFormRequest ${logUrl}/schema logType=${logType} ${version} ${rescode} Set Variable ${response['code']} - Should Be Equal As Integers ${rescode} 200 + Should Be Equal As Strings ${rescode} 200 ${resData} Set Variable ${response['data']} ${schema_query} Get From Dictionary ${resData['doc']} schema_query ${schema_type} Get From Dictionary ${resData['doc']} schema_type @@ -29,28 +30,31 @@ QueryLogs ... 注意如下字典字段格式 ... orderBy=field名字1|true,field名字2|false ... fields=name1|type,name2|type + ... 当path为batch时,fields=name1|type|lang1,name2|type|lang2 ... conditions=field1|type|symbol|value1^value2,field2|type|symbol|value3^value4 ... value1^value2是使用^分隔的字符串解析后为[value1,value2]格式的数组 [Arguments] ${params} ${path} Should Not Be Empty ${params} ${return} ${pageSize} Run Keyword And Ignore Error Get From Dictionary ${params} pageSize Run Keyword If "${return}"=="PASS" and "${pageSize}"=="${EMPTY}" Remove From Dictionary ${params} pageSize + Run Keyword If "${path}"=="batch" Remove From Dictionary ${params} pageSize ${return} ${pageNo} Run Keyword And Ignore Error Get From Dictionary ${params} pageNo Run Keyword If "${return}"=="PASS" and "${pageNo}"=="${EMPTY}" Remove From Dictionary ${params} pageNo + Run Keyword If "${path}"=="batch" Remove From Dictionary ${params} pageNo Dictionary Should Contain Key ${params} logType ${logType} Get From Dictionary ${params} logType #处理排序 ${return} ${orderBy} Run Keyword And Ignore Error Get From Dictionary ${params} orderBy ${orderBy} Run Keyword If "${return}"=="FAIL" or "${orderBy}"=="${EMPTY}" Create List - ... ELSE IF "${path}"=="list" ManageOrderBy ${orderBy} ELSE IF "${path}"=="count" + ... ELSE IF "${path}"=="list" or "${path}"=="batch" ManageOrderBy ${orderBy} ELSE IF "${path}"=="count" ... Set Variable ${orderBy} - Run Keyword If "${path}"=="list" Set To Dictionary ${params} orderBy=${orderBy} + Run Keyword If "${path}"=="list" or "${path}"=="batch" Set To Dictionary ${params} orderBy=${orderBy} Run Keyword If "${path}"=="count" Remove From Dictionary ${params} orderBy ${return} ${fields} Run Keyword And Ignore Error Get From Dictionary ${params} fields Run Keyword If "${path}"=="list" Should Not Be Empty ${fields} - ${fields} Run Keyword If "${path}"=="list" ManageFields ${fields} + ${fields} Run Keyword If "${path}"=="list" or "${path}"=="batch" ManageFields ${fields} ... ELSE Create List - Run Keyword If "${path}"=="list" Set To Dictionary ${params} fields=${fields} + Run Keyword If "${path}"=="list" or "${path}"=="batch" Set To Dictionary ${params} fields=${fields} Run Keyword If "${path}"=="count" Remove From Dictionary ${params} fields ${start_common_recv_time} Get From Dictionary ${params} start_common_recv_time Should Not Be Empty ${start_common_recv_time} @@ -64,14 +68,17 @@ QueryLogs ... ELSE Create List Set To Dictionary ${params} conditions=${conditions} ${bodyJson} json.Dumps ${params} ensure_ascii=False - ${response} BasePostRequestForV2 ${logUrl}/${path} ${bodyJson} ${version} - ${rescode} Set Variable ${response['code']} - Should Be Equal As Integers ${rescode} 200 - ${resData} Set Variable ${response['data']} + ${response} Run Keyword If "${path}"!="batch" BasePostRequestForV2 ${logUrl}/${path} ${bodyJson} ${version} + ... ELSE BasePostRequestReturnBinary ${logUrl}/${path} ${bodyJson} ${version} + + Run Keyword If "${path}"!="batch" Should Be Equal As Integers ${response['code']} 200 + ${time} Get Current Date result_format=datetime exclude_millis=True + ${resData} Run Keyword If "${path}"!="batch" Set Variable ${response['data']} + ... ELSE WriteExcel downloads ${logType}${time.year}${time.month}${time.day}${time.hour}${time.minute}${time.second}.xlsx ${response} [Return] ${resData} ManageOrderBy [Documentation] - ... + ... 处理 order by [Arguments] ${orderBy} ${orderByList} Create List @{orderByArr} Split String ${orderBy} , @@ -82,16 +89,23 @@ QueryLogs END [Return] ${orderByList} ManageFields + [Documentation] + ... 处理fields [Arguments] ${fields} ${fieldsList} Create List @{fieldsArr} Split String ${fields} , FOR ${field} IN @{fieldsArr} @{fieldsArr} Split String ${field} | ${dict} Create Dictionary name=${fieldsArr}[0] type=${fieldsArr}[1] + ${len} Get Length ${fieldsArr} + # batch时有lang字段 + Run Keyword If ${len}==3 Set To Dictionary ${dict} lang=${fieldsArr}[2] Append To List ${fieldsList} ${dict} END [Return] ${fieldsList} ManageConditions + [Documentation] + ... 处理conditions [Arguments] ${conditions} ${conditionsList} Create List @{conditionsArr} Split String ${conditions} , @@ -106,6 +120,8 @@ QueryLogs END [Return] ${conditionsList} toDigitList + [Documentation] + ... 转换为int 或者long型的list [Arguments] ${values} ${type} ${list} Create List FOR ${var} IN @{values} @@ -113,4 +129,10 @@ toDigitList ... ELSE Evaluate long('${var}') Append To List ${list} ${var} END - [Return] ${list} \ No newline at end of file + [Return] ${list} +WriteExcel + [Documentation] + ... 二进制文件导出为Excel + [Arguments] ${filePath} ${fileName} ${content} + Create Binary File ${path}/${filePath}/${fileName} ${content} + [Return] ${path}/${filePath}/${fileName} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Policy.robot b/02-Keyword/tsg_bfapi/policy_object/Policy.robot index ef9c028..f61e597 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Policy.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Policy.robot @@ -4,7 +4,6 @@ Library RequestsLibrary Resource ../../../03-Variable/BifangApiVariable.txt Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot Resource ProcessPolicyBody.robot -Library Collections Resource ../Common.robot *** Variables *** ${policyUrl} /policy/compile