Step 1: Move vm scripts to the right place
[integration/test.git] / test / csit / libraries / RequestsLibrary.py
index 3ef4375d6fc62ade4cf62597051f1312c28bb489..e120972c6dd8a79eb332798c2214ce41a5743c65 100644 (file)
@@ -21,7 +21,7 @@ class RequestsLibrary(object):
             return data
 
         utf8_data = {}
-        for k,v in data.iteritems():
+        for k, v in data.iteritems():
             utf8_data[k] = unicode(v).encode('utf-8')
         return urlencode(utf8_data)
 
@@ -51,7 +51,7 @@ class RequestsLibrary(object):
         s = session = requests.Session()
         s.headers.update(headers)
         s.auth = auth if auth else s.auth
-        s.proxies = proxies if proxies else  s.proxies
+        s.proxies = proxies if proxies else s.proxies
 
         s.verify = self.builtin.convert_to_boolean(verify)
 
@@ -67,30 +67,27 @@ class RequestsLibrary(object):
         return session
 
     def delete_all_sessions(self):
-        """ Removes all the session objects """
+        """Removes all the session objects"""
 
         self._cache.empty_cache()
 
     def to_json(self, content):
-        """ Convert a string to a JSON object
+        """Convert a string to a JSON object
 
         `content` String content to convert into JSON
         """
         return json.loads(content)
 
-    
     def _get_url(self, session, uri):
-        ''' Helpere method to get the full url
-        '''
+        """Helpere method to get the full url"""
         url = session.url
         if uri:
             slash = '' if uri.startswith('/') else '/'
-            url = "%s%s%s" %(session.url, slash, uri)
+            url = "%s%s%s" % (session.url, slash, uri)
         return url
 
     def get(self, alias, uri, headers=None):
-        """ Send a GET request on the session object found using the
-            given `alias`
+        """Send a GET request on the session object found using the given `alias`
 
         `alias` that will be used to identify the Session object in the cache
 
@@ -109,8 +106,7 @@ class RequestsLibrary(object):
         return resp
 
     def post(self, alias, uri, data={}, headers=None, files={}):
-        """ Send a POST request on the session object found using the
-        given `alias`
+        """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
 
@@ -129,9 +125,9 @@ class RequestsLibrary(object):
         data = self._utf8_urlencode(data)
 
         resp = session.post(self._get_url(session, uri),
-                       data=data, headers=headers,
-                       files=files,
-                       cookies=self.cookies, timeout=self.timeout)
+                            data=data, headers=headers,
+                            files=files,
+                            cookies=self.cookies, timeout=self.timeout)
 
         # store the last response object
         session.last_resp = resp
@@ -139,8 +135,7 @@ class RequestsLibrary(object):
         return resp
 
     def postjson(self, alias, uri, data={}, headers=None, files={}):
-        """ Send a POST request on the session object found using the
-        given `alias`
+        """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
 
@@ -159,9 +154,9 @@ class RequestsLibrary(object):
         data = json.dumps(data)
 
         resp = session.post(self._get_url(session, uri),
-                       data=data, headers=headers,
-                       files=files,
-                       cookies=self.cookies, timeout=self.timeout)
+                            data=data, headers=headers,
+                            files=files,
+                            cookies=self.cookies, timeout=self.timeout)
 
         # store the last response object
         session.last_resp = resp
@@ -169,8 +164,7 @@ class RequestsLibrary(object):
         return resp
 
     def put(self, alias, uri, data=None, headers=None):
-        """ Send a PUT request on the session object found using the
-        given `alias`
+        """Send a PUT request on the session object found using the given `alias`
 
         `alias` that will be used to identify the Session object in the cache
 
@@ -181,12 +175,12 @@ class RequestsLibrary(object):
         """
 
         session = self._cache.switch(alias)
-       #data = self._utf8_urlencode(data)
+        # 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)
+                           data=data, headers=headers,
+                           cookies=self.cookies, timeout=self.timeout)
 
         self.builtin.log("PUT response: %s DEBUG" % resp.content)
 
@@ -195,8 +189,7 @@ class RequestsLibrary(object):
         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`
+        """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
 
@@ -207,12 +200,12 @@ class RequestsLibrary(object):
         """
 
         session = self._cache.switch(alias)
-       data = self._utf8_urlencode(data)
-        #data = json.dumps(data)
+        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)
+                           data=data, headers=headers,
+                           cookies=self.cookies, timeout=self.timeout)
 
         self.builtin.log("PUT response: %s DEBUG" % resp.content)
 
@@ -221,8 +214,7 @@ class RequestsLibrary(object):
         return resp
 
     def delete(self, alias, uri, data=(), headers=None):
-        """ Send a DELETE request on the session object found using the
-        given `alias`
+        """Send a DELETE request on the session object found using the given `alias`
 
         `alias` that will be used to identify the Session object in the cache
 
@@ -235,17 +227,15 @@ class RequestsLibrary(object):
         session = self._cache.switch(alias)
         args = "?%s" % urlencode(data) if data else ''
         resp = session.delete("%s%s" % (self._get_url(session, uri), args),
-                            headers=headers, cookies=self.cookies,
-                            timeout=self.timeout)
+                              headers=headers, cookies=self.cookies,
+                              timeout=self.timeout)
 
         # store the last response 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`
+        """Send a HEAD request on the session object found using the given `alias`
 
         `alias` that will be used to identify the Session object in the cache
 
@@ -257,7 +247,7 @@ class RequestsLibrary(object):
 
         session = self._cache.switch(alias)
         resp = session.head(self._get_url(session, uri), headers=headers,
-                           cookies=self.cookies, timeout=self.timeout)
+                            cookies=self.cookies, timeout=self.timeout)
 
         # store the last response object
         session.last_resp = resp