Merge "added output error message display by remote ssh execution"
[integration/test.git] / test / csit / libraries / RequestsLibrary.py
index cf66e369c15e2dc5a392d62e2f5cd76363784a07..3ef4375d6fc62ade4cf62597051f1312c28bb489 100644 (file)
@@ -3,6 +3,7 @@ import json
 
 from urllib import urlencode
 
+
 import robot
 
 from robot.libraries.BuiltIn import BuiltIn
@@ -137,6 +138,36 @@ class RequestsLibrary(object):
         self.builtin.log("Post response: " + resp.content, 'DEBUG')
         return resp
 
+    def postjson(self, alias, uri, data={}, headers=None, files={}):
+        """ Send a POST request on the session object found using the
+        given `alias`
+
+        `alias` that will be used to identify the Session object in the cache
+
+        `uri` to send the GET request to
+
+        `data` a dictionary of key-value pairs that will be urlencoded
+               and sent as POST data
+               or binary data that is sent as the raw body content
+
+        `headers` a dictionary of headers to use with the request
+
+        `files` a dictionary of file names containing file data to POST to the server
+        """
+
+        session = self._cache.switch(alias)
+        data = json.dumps(data)
+
+        resp = session.post(self._get_url(session, uri),
+                       data=data, headers=headers,
+                       files=files,
+                       cookies=self.cookies, timeout=self.timeout)
+
+        # store the last response object
+        session.last_resp = resp
+        self.builtin.log("Post response: " + resp.content, 'DEBUG')
+        return resp
+
     def put(self, alias, uri, data=None, headers=None):
         """ Send a PUT request on the session object found using the
         given `alias`
@@ -150,7 +181,7 @@ class RequestsLibrary(object):
         """
 
         session = self._cache.switch(alias)
-        #data = json.dumps(self._utf8_urlencode(data))
+       #data = self._utf8_urlencode(data)
         data = json.dumps(data)
 
         resp = session.put(self._get_url(session, uri),
@@ -163,6 +194,32 @@ class RequestsLibrary(object):
         session.last_resp = resp
         return resp
 
+    def put_xml(self, alias, uri, data=None, headers=None):
+        """ Send a PUT_xml request on the session object found using the
+        given `alias`
+
+        `alias` that will be used to identify the Session object in the cache
+
+        `uri` to send the PUT_xml request to
+
+        `headers` a dictionary of headers to use with the request
+
+        """
+
+        session = self._cache.switch(alias)
+       data = self._utf8_urlencode(data)
+        #data = json.dumps(data)
+
+        resp = session.put(self._get_url(session, uri),
+                    data=data, headers=headers,
+                    cookies=self.cookies, timeout=self.timeout)
+
+        self.builtin.log("PUT response: %s DEBUG" % resp.content)
+
+        # store the last response object
+        session.last_resp = resp
+        return resp
+
     def delete(self, alias, uri, data=(), headers=None):
         """ Send a DELETE request on the session object found using the
         given `alias`
@@ -185,6 +242,7 @@ class RequestsLibrary(object):
         session.last_resp = resp
         return resp
 
+       
     def head(self, alias, uri, headers=None):
         """ Send a HEAD request on the session object found using the
         given `alias`