Variables ${CURDIR}/../variables/Variables.py
*** Variables ***
-# TODO: Make the following list more narrow when Bug 2594 is fixed.
-@{ALLOWED_STATUS_CODES} ${200} ${201} ${204} # List of integers, not strings. Used by both PUT and DELETE.
+# 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 ***
Create_Default_Session
[Return] ${response_text}
Delete_Templated
- [Arguments] ${folder} ${mapping}={} ${session}=default
+ [Arguments] ${folder} ${mapping}={} ${session}=default ${allow_404}=False
[Documentation] Resolve URI from folder, issue DELETE request.
${uri} = Resolve_Text_From_Template_Folder folder=${folder} base_name=location extension=uri mapping=${mapping}
- ${response_text} = Delete_From_Uri uri=${uri} session=${session}
+ ${response_text} = Delete_From_Uri uri=${uri} session=${session} allow_404=${allow_404}
[Return] ${response_text}
Verify_Response_As_Json_Templated
[Return] ${response_text}
Delete_From_Uri
- [Arguments] ${uri} ${session}=default
+ [Arguments] ${uri} ${session}=default ${allow_404}=False
[Documentation] DELETE resource at URI, check status_code and return response text..
BuiltIn.Log ${uri}
${response} = RequestsLibrary.Delete_Request alias=${session} uri=${uri}
- Check_Status_Code ${response}
+ Check_Status_Code ${response} allow_404=${allow_404}
[Return] ${response.text}
Get_Templated
... ELSE BuiltIn.Should_Be_Equal ${expected_text} ${response}
Get_From_Uri
- [Arguments] ${uri} ${accept} ${session}=default ${normalize_json}=False
+ [Arguments] ${uri} ${accept}=${ACCEPT_EMPTY} ${session}=default ${normalize_json}=False
[Documentation] GET data from given URI, check status code and return response text.
- ... \${accept} is a mandatory Python object with headers to use.
- ... If \${normalize_json}, normalize text before returning.
+ ... \${accept} is a Python object with headers to use.
+ ... If \${normalize_json}, normalize as JSON text before returning.
BuiltIn.Log ${uri}
BuiltIn.Log ${accept}
${response} = RequestsLibrary.Get_Request alias=${session} uri=${uri} headers=${accept}
[Return] ${text_normalized}
Check_Status_Code
- [Arguments] ${response}
+ [Arguments] ${response} ${allow_404}=False
[Documentation] Log response text, check status_code is one of allowed ones.
# TODO: Remove overlap with keywords from Utils.robot
BuiltIn.Log ${response.text}
BuiltIn.Log ${response.status_code}
- BuiltIn.Should_Contain ${ALLOWED_STATUS_CODES} ${response.status_code}
- # TODO: Add support for 404 on Delete?
+ Run_Keyword_If ${allow_404} BuiltIn.Should_Contain ${ALLOWED_DELETE_STATUS_CODES} ${response.status_code}
+ ... ELSE BuiltIn.Should_Contain ${ALLOWED_STATUS_CODES} ${response.status_code}
Join_Two_Headers
[Arguments] ${first} ${second}
... where additional template variable ${i} goes from ${iter_start}, by one ${iterations} times.
... POST (as opposed to PUT) needs slightly different data, \${name_prefix} may be used to distinguish.
... (Actually, it is GET who formats data differently when URI is a top-level container.)
- BuiltIn.Run_Keyword_And_Return_If not "${iterations}" Resolve_Text_From_Template_File file_path=${folder}${/}${name_prefix}${base_name}.${extension} mapping=${mapping}
- ${prolog} = Resolve_Text_From_Template_File file_path=${folder}${/}${name_prefix}${base_name}.prolog.${extension} mapping=${mapping}
- ${epilog} = Resolve_Text_From_Template_File file_path=${folder}${/}${name_prefix}${base_name}.epilog.${extension} mapping=${mapping}
+ BuiltIn.Run_Keyword_And_Return_If not "${iterations}" Resolve_Text_From_Template_File folder=${folder} file_name=${name_prefix}${base_name}.${extension} mapping=${mapping}
+ ${prolog} = Resolve_Text_From_Template_File folder=${folder} file_name=${name_prefix}${base_name}.prolog.${extension} mapping=${mapping}
+ ${epilog} = Resolve_Text_From_Template_File folder=${folder} file_name=${name_prefix}${base_name}.epilog.${extension} mapping=${mapping}
# Even POST uses the same item template (except indentation), so name prefix is ignored.
- ${item_template} = Resolve_Text_From_Template_File file_path=${folder}${/}${base_name}.item.${extension} mapping=${mapping}
+ ${item_template} = Resolve_Text_From_Template_File folder=${folder} file_name=${base_name}.item.${extension} mapping=${mapping}
${items} = BuiltIn.Create_List
${separator} = BuiltIn.Set_Variable_If '${extension}' != 'json' ${endline} ,${endline}
: FOR ${iteration} IN RANGE ${iter_start} ${iterations}+${iter_start}
- \ # Add separator only if we are beyond first item.
\ BuiltIn.Run_Keyword_If ${iteration} > ${iter_start} Collections.Append_To_List ${items} ${separator}
\ ${item} = BuiltIn.Evaluate string.Template('''${item_template}''').substitute({"i":"${iteration}"}) modules=string
\ Collections.Append_To_List ${items} ${item}
[Return] ${final_text}
Resolve_Text_From_Template_File
- [Arguments] ${file_path} ${mapping}={}
- [Documentation] Read an Log contents of file, remove endline, perform safe substitution, return result.
+ [Arguments] ${folder} ${file_name} ${mapping}={}
+ [Documentation] Check if ${folder}.${ODL_STREAM}/${file_name} exists. If yes read and Log contents of file ${folder}.${ODL_STREAM}/${file_name},
+ ... remove endline, perform safe substitution, return result.
+ ... If no do it with the default ${folder}/${file_name}.
+ ${file_path_stream}= BuiltIn.Set Variable ${folder}.${ODL_STREAM}${/}${file_name}
+ ${file_stream_exists}= BuiltIn.Run Keyword And Return Status OperatingSystem.File Should Exist ${file_path_stream}
+ ${file_path}= BuiltIn.Set Variable If ${file_stream_exists} ${file_path_stream} ${folder}${/}${file_name}
${template} = OperatingSystem.Get_File ${file_path}
BuiltIn.Log ${template}
${final_text} = BuiltIn.Evaluate string.Template('''${template}'''.rstrip()).safe_substitute(${mapping}) modules=string
# 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}