CSIT for Yang 1.1 actions
[integration/test.git] / csit / libraries / TemplatedRequests.robot
index 9bbf0875e80bbe0ef0b845c277eacc43761cd34f..e514d1f10bb5343258f7626dd2db65e132c6cb82 100644 (file)
@@ -113,7 +113,7 @@ Library           OperatingSystem
 Library           String
 Library           RequestsLibrary
 Library           ${CURDIR}/norm_json.py
-Variables         ${CURDIR}/../variables/Variables.py
+Resource          ${CURDIR}/../variables/Variables.robot
 
 *** Variables ***
 # TODO: Make the following list more narrow when streams without Bug 2594 fix (up to beryllium) are no longer used.
@@ -198,6 +198,23 @@ Post_As_Json_Templated
     BuiltIn.Run_Keyword_If    ${verify}    Verify_Response_As_Json_Templated    response=${response_text}    folder=${folder}    base_name=response    mapping=${mapping}
     [Return]    ${response_text}
 
+Post_As_Json_Rfc8040_Templated
+    [Arguments]    ${folder}    ${mapping}={}    ${session}=default    ${verify}=False    ${iterations}=${EMPTY}    ${iter_start}=1
+    ...    ${additional_allowed_status_codes}=${NO_STATUS_CODES}    ${explicit_status_codes}=${NO_STATUS_CODES}    ${http_timeout}=${EMPTY}
+    [Documentation]    Add arguments sensible for JSON data, return Post_Templated response text.
+    ...    Optionally, verification against response.json (no iteration) is called.
+    ...    Only subset of JSON data is verified and returned if JMES path is specified in
+    ...    file ${folder}${/}jmespath.expr.
+    ...    Response status code must be one of values from ${explicit_status_codes} if specified or one of set
+    ...    created from all positive HTTP status codes together with ${additional_allowed_status_codes}.
+    ...    RFC8040 defines RESTCONF protocol, for configuring data defined in YANG version 1
+    ...    or YANG version 1.1, using the datastore concepts defined in NETCONF.
+    ${response_text} =    Post_Templated    folder=${folder}    base_name=data    extension=json    accept=${ACCEPT_EMPTY}    content_type=${HEADERS_YANG_RFC8040_JSON}
+    ...    mapping=${mapping}    session=${session}    normalize_json=True    endline=${\n}    iterations=${iterations}    iter_start=${iter_start}
+    ...    additional_allowed_status_codes=${additional_allowed_status_codes}    explicit_status_codes=${explicit_status_codes}    http_timeout=${http_timeout}
+    BuiltIn.Run_Keyword_If    ${verify}    Verify_Response_As_Json_Templated    response=${response_text}    folder=${folder}    base_name=response    mapping=${mapping}
+    [Return]    ${response_text}
+
 Post_As_Xml_Templated
     [Arguments]    ${folder}    ${mapping}={}    ${session}=default    ${verify}=False    ${iterations}=${EMPTY}    ${iter_start}=1
     ...    ${additional_allowed_status_codes}=${NO_STATUS_CODES}    ${explicit_status_codes}=${NO_STATUS_CODES}    ${http_timeout}=${EMPTY}
@@ -411,8 +428,16 @@ Check_Status_Code
     # TODO: Remove overlap with keywords from Utils.robot
     BuiltIn.Log    ${response.text}
     BuiltIn.Log    ${response.status_code}
-    BuiltIn.Run_Keyword_And_Return_If    """${explicit_status_codes}""" != """${NO_STATUS_CODES}"""    Collections.List_Should_Contain_Value    ${explicit_status_codes}    ${response.status_code}
-    ${final_allowd_list} =    Collections.Combine_Lists    ${ALLOWED_STATUS_CODES}    ${additional_allowed_status_codes}
+    # In order to allow other existing keywords to consume this keyword by passing a single non-list status code, we need to
+    # check the type of the argument passed and convert those single non-list codes in to a one item list
+    ${status_codes_type} =    Evaluate    type($additional_allowed_status_codes).__name__
+    ${allowed_status_codes_list} =    Run Keyword If    "${status_codes_type}"!="list"    Create List    ${additional_allowed_status_codes}
+    ...    ELSE    Set Variable    ${additional_allowed_status_codes}
+    ${status_codes_type} =    Evaluate    type($explicit_status_codes).__name__
+    ${explicit_status_codes_list} =    Run Keyword If    "${status_codes_type}"!="list"    Create List    ${explicit_status_codes}
+    ...    ELSE    Set Variable    ${explicit_status_codes}
+    BuiltIn.Run_Keyword_And_Return_If    """${explicit_status_codes_list}""" != """${NO_STATUS_CODES}"""    Collections.List_Should_Contain_Value    ${explicit_status_codes_list}    ${response.status_code}
+    ${final_allowd_list} =    Collections.Combine_Lists    ${ALLOWED_STATUS_CODES}    ${allowed_status_codes_list}
     Collections.List_Should_Contain_Value    ${final_allowd_list}    ${response.status_code}
 
 Join_Two_Headers