From: Jozef Behran Date: Mon, 28 Sep 2015 10:18:22 +0000 (+0200) Subject: API for GET requests with automatic error handling X-Git-Tag: release/lithium-sr3~90 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F27525%2F11;p=integration%2Ftest.git API for GET requests with automatic error handling The keyword "Get Data From URI" issues a GET request for the specified URI through the specified session, FAILs if the request returns an error (with logging that error into Robot logs and returns the data on success. Success is currently defined as "returned status code 200" and the method is hardwired to GET so this keyword is not useful for making non-data-getting requests like POST or for GET requests that don't return any data and return an OK-like status code (2XX where XX != 00). Change-Id: Iee5e894687aa9576bc4968fe851d6ab72e386872 Signed-off-by: Jozef Behran --- diff --git a/csit/libraries/Utils.robot b/csit/libraries/Utils.robot index 58f409046e..89603cbc40 100644 --- a/csit/libraries/Utils.robot +++ b/csit/libraries/Utils.robot @@ -308,3 +308,14 @@ Run Process With Logging And Status Check Log ${result.stderr} Should Be Equal As Integers ${result.rc} 0 [Return] ${result} + +Get Data From URI + [Arguments] ${session} ${uri} ${headers}=${NONE} + [Documentation] Issue a GET request and return the data obtained or on error log the error and fail. + ... Issues a GET request for ${uri} in ${session} using headers from + ... ${headers}. If the request returns a HTTP error, fails. Otherwise + ... returns the data obtained by the request. + ${response}= RequestsLibrary.Get ${session} ${uri} ${headers} + Builtin.Return_From_Keyword_If ${response.status_code} == 200 ${response.text} + Builtin.Log ${response.text} + Builtin.Fail The request failed with code ${response.status_code}