from urllib import urlencode
+
import robot
from robot.libraries.BuiltIn import BuiltIn
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`
"""
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),
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`
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`