Skip to content
Browse files

having OAuth1Service.get_request_token return response.content on error

Previously we would use response.raise_for_status to ensure errored responses
did not percolate beyond the method call. Now we instead identify bad requests
via response.ok and then condtionally return the raw content on an error. This
should make rauth more transparent when things go wrong in the request token
retrieval process.
  • Loading branch information...
1 parent 7f1cc2a commit 33142b4836849bf79534e36fc7c8e3e1965402f6 @maxcountryman maxcountryman committed Jun 10, 2012
Showing with 14 additions and 14 deletions.
  1. +1 −1 rauth/__init__.py
  2. +2 −1 rauth/service.py
  3. +11 −12 tests/test_service.py
View
2 rauth/__init__.py
@@ -6,4 +6,4 @@
'''
-__version__ = '0.4.7'
+__version__ = '0.4.8'
View
3 rauth/service.py
@@ -420,7 +420,8 @@ def get_request_token(self, method='GET', **kwargs):
self.request_token_url,
**kwargs)
- response.raise_for_status()
+ if not response.ok:
+ return response.content
data = parse_utf8_qsl(response.content)
return data['oauth_token'], data['oauth_token_secret']
View
23 tests/test_service.py
@@ -281,14 +281,13 @@ def test_get_request_token_header_auth(self, mock_request):
@patch.object(requests.Session, 'request')
def test_get_request_token_bad_response(self, mock_request):
self.response.ok = False
+ self.response.content = 'Oops, something went wrong :('
self.response.raise_for_status = self.raise_for_status
- mock_request.return_value = self.response
- with self.assertRaises(Exception) as e:
- self.service.get_request_token('GET')
- self.assertEqual('Response not OK!', str(e))
+ mock_request.return_value = self.response
- self.assertRaises(Exception, self.service.get_request_token, ('GET'))
+ response = self.service.get_request_token('GET')
+ self.assertEqual(response, 'Oops, something went wrong :(')
def test_get_authorize_url(self):
authorize_url = self.service.get_authorize_url(request_token='123')
@@ -316,16 +315,16 @@ def test_get_access_token(self, mock_request):
@patch.object(requests.Session, 'request')
def test_get_access_token_bad_response(self, mock_request):
self.response.ok = False
- self.response.raise_for_status = self.raise_for_status
+ self.response.content = \
+ json.dumps(dict(error='Oops, something went wrong :('))
mock_request.return_value = self.response
- with self.assertRaises(Exception) as e:
- self.service.get_access_token('123', '456', 'GET')
- self.assertEqual('Response not OK!', str(e))
+ response = self.service.get_access_token('GET',
+ request_token='123',
+ request_token_secret='456')
- self.assertRaises(Exception,
- self.service.get_access_token,
- ('123', '456', 'GET'))
+ expected = dict(error='Oops, something went wrong :(')
+ self.assertEqual(response.content, expected)
def test_get_authenticated_session(self):
auth_session = \

0 comments on commit 33142b4

Please sign in to comment.
Something went wrong with that request. Please try again.