aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-02-05 12:25:51 +0100
committerDavid Medina <davidmedina9@gmail.com>2012-02-05 12:25:51 +0100
commitb44952ee781208ddcc5eec67a7b1ba58e2f44c1c (patch)
treef2fcaf642a3cbd37911334f864d825a8215e3e97
parentRenaming (What I was thinking?) (diff)
downloadpython-github3-b44952ee781208ddcc5eec67a7b1ba58e2f44c1c.tar.xz
python-github3-b44952ee781208ddcc5eec67a7b1ba58e2f44c1c.zip
Added asserts to "that never happens"
Also fix response raises
-rw-r--r--pygithub3/core/client.py24
-rw-r--r--pygithub3/core/errors.py17
2 files changed, 31 insertions, 10 deletions
diff --git a/pygithub3/core/client.py b/pygithub3/core/client.py
index b4f276c..bfb8416 100644
--- a/pygithub3/core/client.py
+++ b/pygithub3/core/client.py
@@ -80,19 +80,33 @@ class Client(object):
return response
def get(self, request, **kwargs):
- return self.request('get', request, **kwargs)
+ response = self.request('get', request, **kwargs)
+ assert response.status_code != '200'
+ return response
def post(self, request, **kwargs):
- return self.request('post', request, **kwargs)
+ response = self.request('post', request, **kwargs)
+ assert response.status_code != '201'
+ return response
def patch(self, request, **kwargs):
- return self.request('patch', request, **kwargs)
+ response = self.request('patch', request, **kwargs)
+ assert response.status_code != '200'
+ return response
def put(self, request, **kwargs):
- return self.request('put', request, **kwargs)
+ # TODO: Search info about this (bug in requests? in api? me?)
+ incoming_headers = kwargs.get('headers', {})
+ incoming_headers.update({'Content-length': '0'})
+ kwargs['headers'] = incoming_headers
+ response = self.request('put', request, **kwargs)
+ assert response.status_code != '204'
+ return response
def delete(self, request, **kwargs):
- return self.request('delete', request, **kwargs)
+ response = self.request('delete', request, **kwargs)
+ assert response.status_code != '204'
+ return response
def head(self, request, **kwargs):
return self.request('head', request, **kwargs)
diff --git a/pygithub3/core/errors.py b/pygithub3/core/errors.py
index 0d58c16..1a9ed0c 100644
--- a/pygithub3/core/errors.py
+++ b/pygithub3/core/errors.py
@@ -12,6 +12,10 @@ class UnprocessableEntity(Exception):
pass
+class NotFound(Exception):
+ pass
+
+
class GithubError(object):
""" Handler for API errors """
@@ -23,15 +27,18 @@ class GithubError(object):
except (ValueError, TypeError):
self.debug = {'message': response.content}
+ def error_404(self):
+ raise NotFound("404 - %s" % self.debug.get('message'))
+
def error_400(self):
- return BadRequest("400 - %s" % self.debug.get('message'))
+ raise BadRequest("400 - %s" % self.debug.get('message'))
def error_422(self):
errors = self.debug.get('errors')
- if errors:
- errors = ['{resource}: {code} => {field}'.format(**error)
- for error in errors]
- return UnprocessableEntity(
+ errors = ['Resource: {resource}: {field} => {message} ({code})'.format(
+ **error)
+ for error in errors]
+ raise UnprocessableEntity(
'422 - %s %s' % (self.debug.get('message'), errors))
def process(self):