Skip to content

Commit

Permalink
Merge pull request #36 from Erolstt/master
Browse files Browse the repository at this point in the history
Patch Request Added
  • Loading branch information
bulkan committed Jun 11, 2014
2 parents 3d323cd + 1d2a909 commit fd1bb49
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/RequestsLibrary/RequestsKeywords.py
Expand Up @@ -199,6 +199,31 @@ def post(self, alias, uri, data={}, headers=None, files={}, cassette=None):

return response

def patch(self, alias, uri, data={}, headers=None, files={}, cassette=None):
""" Send a PATCH 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 PATCH request to
`data` a dictionary of key-value pairs that will be urlencoded
and sent as PATCH 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 PATCH to the server
"""
session = self._cache.switch(alias)
data = self._utf8_urlencode(data)
if cassette:
with vcr.use_cassette(cassette, serializer='json', cassette_library_dir = 'cassettes/PATCH', record_mode='new_episodes', match_on=['url', 'method', 'headers', 'body']):
response = self.patch_request(session, uri, data, headers, files)
else:
response = self.patch_request(session, uri, data, headers, files)

return response

def put(self, alias, uri, data=None, headers=None, cassette=None):
""" Send a PUT request on the session object found using the
Expand Down Expand Up @@ -270,6 +295,7 @@ def head(self, alias, uri, headers=None, cassette=None):
return response



def get_request(self, session, uri, headers, params):
resp = session.get(self._get_url(session, uri),
headers=headers,
Expand All @@ -291,6 +317,17 @@ def post_request(self, session, uri, data, headers, files):
self.builtin.log("Post response: " + resp.content, 'DEBUG')
return resp

def patch_request(self, session, uri, data, headers, files):
resp = session.patch(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("Patch response: " + resp.content, 'DEBUG')
return resp

def put_request(self, session, uri, data, headers):
resp = session.put(self._get_url(session, uri),
data=data, headers=headers,
Expand Down

0 comments on commit fd1bb49

Please sign in to comment.