*** Variables ***
# 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).
+@{DATA_VALIDATION_ERROR} ${500}
+@{DELETED_STATUS_CODE} ${404} # List of integers, not strings. Used by DELETE if the resource may be not present.
+@{NO_STATUS_CODES}
@{ALLOWED_DELETE_STATUS_CODES} ${200} ${201} ${204} ${404} # List of integers, not strings. Used by DELETE if the resource may be not present.
+@{UNAUTHORIZED_STATUS_CODES} ${401} # List of integers, not strings. Used in Keystone Authentication when the user is not authorized to use the requested resource.
@{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.
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}
[Documentation] Add arguments sensible for XML data, return Post_Templated response text.
... Optionally, verification against response.xml (no iteration) is called.
# In case of iterations, we use endlines in data to send, as it should not matter and it is more readable.
${response_text} = Post_Templated folder=${folder} base_name=data extension=xml accept=${ACCEPT_XML} content_type=${HEADERS_XML}
... mapping=${mapping} session=${session} normalize_json=False endline=${\n} iterations=${iterations} iter_start=${iter_start}
+ ... additional_allowed_status_codes=${additional_allowed_status_codes} explicit_status_codes=${explicit_status_codes}
BuiltIn.Run_Keyword_If ${verify} Verify_Response_As_Xml_Templated response=${response_text} folder=${folder} base_name=response mapping=${mapping}
[Return] ${response_text}
Delete_Templated
- [Arguments] ${folder} ${mapping}={} ${session}=default ${allow_404}=False
+ [Arguments] ${folder} ${mapping}={} ${session}=default ${additional_allowed_status_codes}=${NO_STATUS_CODES}
[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} allow_404=${allow_404}
+ ${response_text} = Delete_From_Uri uri=${uri} session=${session} additional_allowed_status_codes=${additional_allowed_status_codes}
[Return] ${response_text}
Verify_Response_As_Json_Templated
[Return] ${response_text}
Delete_From_Uri
- [Arguments] ${uri} ${session}=default ${allow_404}=False
+ [Arguments] ${uri} ${session}=default ${additional_allowed_status_codes}=${NO_STATUS_CODES}
[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} allow_404=${allow_404}
+ Check_Status_Code ${response} additional_allowed_status_codes=${additional_allowed_status_codes}
[Return] ${response.text}
Get_Templated
Post_Templated
[Arguments] ${folder} ${base_name} ${extension} ${content_type} ${accept} ${mapping}={}
- ... ${session}=default ${normalize_json}=False ${endline}=${\n} ${iterations}=${EMPTY} ${iter_start}=1
+ ... ${session}=default ${normalize_json}=False ${endline}=${\n} ${iterations}=${EMPTY} ${iter_start}=1 ${additional_allowed_status_codes}=${NO_STATUS_CODES}
+ ... ${explicit_status_codes}=${NO_STATUS_CODES}
[Documentation] Resolve URI and data from folder, call Post_To_Uri, return response text.
${uri} = Resolve_Text_From_Template_Folder folder=${folder} base_name=location extension=uri mapping=${mapping}
${data} = Resolve_Text_From_Template_Folder folder=${folder} name_prefix=post_ base_name=${base_name} extension=${extension} mapping=${mapping}
... endline=${endline} iterations=${iterations} iter_start=${iter_start}
${response_text} = Post_To_Uri uri=${uri} data=${data} content_type=${content_type} accept=${accept} session=${session}
- ... normalize_json=${normalize_json}
+ ... normalize_json=${normalize_json} additional_allowed_status_codes=${additional_allowed_status_codes} explicit_status_codes=${explicit_status_codes}
[Return] ${response_text}
Verify_Response_Templated
Post_To_Uri
[Arguments] ${uri} ${data} ${content_type} ${accept} ${session}=default ${normalize_json}=False
+ ... ${additional_allowed_status_codes}=${NO_STATUS_CODES} ${explicit_status_codes}=${NO_STATUS_CODES}
[Documentation] POST data to given URI, check status code and return response text.
... \${content_type} and \${accept} are mandatory Python objects with headers to use.
... If \${normalize_json}, normalize text before returning.
BuiltIn.Log ${accept}
${headers} = Join_Two_Headers first=${content_type} second=${accept}
${response} = RequestsLibrary.Post_Request alias=${session} uri=${uri} data=${data} headers=${headers}
- Check_Status_Code ${response}
+ Check_Status_Code ${response} additional_allowed_status_codes=${additional_allowed_status_codes} explicit_status_codes=${explicit_status_codes}
BuiltIn.Run_Keyword_Unless ${normalize_json} BuiltIn.Return_From_Keyword ${response.text}
${text_normalized} = norm_json.normalize_json_text ${response.text}
[Return] ${text_normalized}
Check_Status_Code
- [Arguments] ${response} ${allow_404}=False
+ [Arguments] ${response} ${additional_allowed_status_codes}=${NO_STATUS_CODES} ${explicit_status_codes}=${NO_STATUS_CODES}
[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}
- 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}
+ 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}
+ Collections.List_Should_Contain_Value ${final_allowd_list} ${response.status_code}
Join_Two_Headers
[Arguments] ${first} ${second}