implementing https://trello.com/c/SavMOS52/332-int-test-create-a-new-kw-in-templatedrequests-for-comparison
Change-Id: I7ecd79b2c5e2763067d2fc3c1138e3b3b5268fe7
Signed-off-by: Peter Gubka <pgubka@cisco.com>
# TODO: Make the following list more narrow when streams without Bug 2594 fix (up to beryllium) are no longer used.
@{ALLOWED_STATUS_CODES} ${200} ${201} ${204} # List of integers, not strings. Used by both PUT and DELETE (if the resource should have been present).
@{ALLOWED_DELETE_STATUS_CODES} ${200} ${201} ${204} ${404} # List of integers, not strings. Used by DELETE if the resource may be not present.
+@{KEYS_WITH_BITS} op # the default list with keys to be sorted when norm_json libray is used
# TODO: Add option for delete to require 404.
*** Keywords ***
# Should_Be_Equal shall print nice diff-style line comparison.
BuiltIn.Should_Be_Equal ${expected_normalized} ${actual_normalized}
# TODO: Add garbage collection? Check whether the temporary data accumulates.
+
+Normalize_Jsons_With_Bits_And_Compare
+ [Arguments] ${expected_raw} ${actual_raw} ${keys_with_bits}=${KEYS_WITH_BITS}
+ [Documentation] Use norm_json to normalize both JSON arguments, call Should_Be_Equal.
+ ${expected_normalized} = norm_json.normalize_json_text ${expected_raw} keys_with_bits=${keys_with_bits}
+ ${actual_normalized} = norm_json.normalize_json_text ${actual_raw} keys_with_bits=${keys_with_bits}
+ BuiltIn.Should_Be_Equal ${expected_normalized} ${actual_normalized}
Resource ${CURDIR}/../../../libraries/SetupUtils.robot
Resource ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
Resource ${CURDIR}/../../../libraries/CompareStream.robot
-Library ${CURDIR}/../../../libraries/norm_json.py
+Resource ${CURDIR}/../../../libraries/TemplatedRequests.robot
*** Variables ***
${HOLDTIME} 180
${keys_with_bits}= BuiltIn.Create_List
CompareStream.Run_Keyword_If_At_Most boron Collections.Append_To_List ${keys_with_bits} op
${expected_rsp}= Get Expected Response From File ${exprspfile}
- ${expected_json}= norm_json.Normalize Json Text ${expected_rsp} keys_with_bits=${keys_with_bits}
${rsp}= RequestsLibrary.Get Request session ${FLOWSPEC_URL}
- BuiltIn.Log ${rsp.content}
- ${received_json}= norm_json.Normalize Json Text ${rsp.content} keys_with_bits=${keys_with_bits}
- BuiltIn.Log ${received_json}
- BuiltIn.Log ${expected_json}
- BuiltIn.Should Be Equal ${received_json} ${expected_json}
+ TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare ${expected_rsp} ${rsp.content} keys_with_bits=${keys_with_bits}
Get Expected Response From File
[Arguments] ${exprspfile}
Resource ${CURDIR}/../../../libraries/TemplatedRequests.robot
Resource ${CURDIR}/../../../libraries/KarafKeywords.robot
Resource ${CURDIR}/../../../libraries/SSHKeywords.robot
-Library ${CURDIR}/../../../libraries/norm_json.py
Library ${CURDIR}/../../../libraries/BgpRpcClient.py ${TOOLS_SYSTEM_IP}
*** Variables ***
${exp_update}= Get_Expected_Response_From_File ${exp_update_fn}
${rcv_update_dict}= BgpRpcClient.exa_get_update_message msg_only=${True}
${rcv_update}= BuiltIn.Evaluate json.dumps(${rcv_update_dict}) modules=json
- ${received_json}= norm_json.Normalize_Json_Text ${rcv_update}
- ${expected_json}= norm_json.Normalize_Json_Text ${exp_update}
- BuiltIn.Log ${received_json}
- BuiltIn.Log ${expected_json}
- BuiltIn.Should_Be_Equal ${received_json} ${expected_json}
+ TemplatedRequests.Normalize_Jsons_And_Compare ${exp_update} ${rcv_update}
Verify_Reported_Data
[Arguments] ${url} ${exprspfile}
[Documentation] Verifies expected response
${expected_rsp}= Get_Expected_Response_From_File ${exprspfile}
- ${expected_json}= norm_json.Normalize_Json_Text ${expected_rsp}
${rsp}= RequestsLibrary.Get_Request ${CONFIG_SESSION} ${url}
- BuiltIn.Log ${rsp.content}
- ${received_json}= norm_json.Normalize_Json_Text ${rsp.content}
- BuiltIn.Log ${received_json}
- BuiltIn.Log ${expected_json}
- BuiltIn.Should_Be_Equal ${received_json} ${expected_json}
+ TemplatedRequests.Normalize_Jsons_And_Compare ${expected_rsp} ${rsp.content}
Get_Expected_Response_From_File
[Arguments] ${exprspfile}
Resource ${CURDIR}/../../../libraries/Utils.robot
Resource ${CURDIR}/../../../libraries/SetupUtils.robot
Resource ${CURDIR}/../../../libraries/TemplatedRequests.robot
-Library ${CURDIR}/../../../libraries/norm_json.py
Library ${CURDIR}/../../../libraries/BgpRpcClient.py ${TOOLS_SYSTEM_IP}
Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot
Resource ${CURDIR}/../../../libraries/KarafKeywords.robot
Resource ${CURDIR}/../../../libraries/Utils.robot
Resource ${CURDIR}/../../../libraries/SetupUtils.robot
Resource ${CURDIR}/../../../libraries/TemplatedRequests.robot
-Library ${CURDIR}/../../../libraries/norm_json.py
Library ${CURDIR}/../../../libraries/BgpRpcClient.py ${TOOLS_SYSTEM_IP}
Resource ${CURDIR}/../../../libraries/BGPcliKeywords.robot
Resource ${CURDIR}/../../../libraries/BGPSpeaker.robot
[Arguments] ${exp_content}
[Documentation] Verifies if loc-rib contains expected data
${rsp}= RequestsLibrary.Get_Request ${CONFIG_SESSION} ${LOC_RIB_URL} headers=${HEADERS}
- Log ${rsp.content}
- ${received_json}= norm_json.Normalize_Json_Text ${rsp.content}
- BuiltIn.Log ${received_json}
- ${expected_json}= norm_json.Normalize_Json_Text ${exp_content}
- BuiltIn.Log ${expected_json}
- BuiltIn.Should_Be_Equal ${received_json} ${expected_json}
+ TemplatedRequests.Normalize_Jsons_And_Compare ${exp_content} ${rsp.content}
Resource ${CURDIR}/../../../libraries/TemplatedRequests.robot
Resource ${CURDIR}/../../../libraries/KarafKeywords.robot
Resource ${CURDIR}/../../../libraries/SSHKeywords.robot
-Library ${CURDIR}/../../../libraries/norm_json.py
Library ${CURDIR}/../../../libraries/BgpRpcClient.py ${TOOLS_SYSTEM_IP}
*** Variables ***