[mq]: smallfixes
This commit is contained in:
@@ -267,6 +267,8 @@ def _cast(value, schema_type):
|
||||
if type(value) == type('') or type(value) == type(u''):
|
||||
return value
|
||||
else:
|
||||
if value is None:
|
||||
raise ValueError('String parameters can not be None.')
|
||||
return str(value)
|
||||
elif schema_type == 'integer':
|
||||
return str(int(value))
|
||||
|
||||
@@ -593,7 +593,7 @@ class OAuth2Credentials(Credentials):
|
||||
body = self._generate_refresh_request_body()
|
||||
headers = self._generate_refresh_request_headers()
|
||||
|
||||
logger.info('Refresing access_token')
|
||||
logger.info('Refreshing access_token')
|
||||
resp, content = http_request(
|
||||
self.token_uri, method='POST', body=body, headers=headers)
|
||||
if resp.status == 200:
|
||||
@@ -1028,10 +1028,24 @@ class OAuth2WebServerFlow(Flow):
|
||||
of the query parameters to the redirect_uri, which contains
|
||||
the code.
|
||||
http: httplib2.Http, optional http instance to use to do the fetch
|
||||
|
||||
Returns:
|
||||
An OAuth2Credentials object that can be used to authorize requests.
|
||||
|
||||
Raises:
|
||||
FlowExchangeError if a problem occured exchanging the code for a
|
||||
refresh_token.
|
||||
"""
|
||||
|
||||
if not (isinstance(code, str) or isinstance(code, unicode)):
|
||||
code = code['code']
|
||||
if 'code' not in code:
|
||||
if 'error' in code:
|
||||
error_msg = code['error']
|
||||
else:
|
||||
error_msg = 'No code was supplied in the query parameters.'
|
||||
raise FlowExchangeError(error_msg)
|
||||
else:
|
||||
code = code['code']
|
||||
|
||||
body = urllib.urlencode({
|
||||
'grant_type': 'authorization_code',
|
||||
|
||||
@@ -193,6 +193,16 @@ class Discovery(unittest.TestCase):
|
||||
self.assertEqual(q['trace'], ['html'])
|
||||
self.assertEqual(q['fields'], ['description'])
|
||||
|
||||
def test_string_params_none_is_invalid(self):
|
||||
http = HttpMock(datafile('zoo.json'), {'status': '200'})
|
||||
zoo = build('zoo', 'v1', http)
|
||||
# String isn't None
|
||||
try:
|
||||
request = zoo.query(trace=None, fields='description')
|
||||
self.fail()
|
||||
except ValueError, e:
|
||||
self.assertTrue('None' in str(e))
|
||||
|
||||
def test_model_added_query_parameters(self):
|
||||
http = HttpMock(datafile('zoo.json'), {'status': '200'})
|
||||
zoo = build('zoo', 'v1', http)
|
||||
|
||||
@@ -279,6 +279,19 @@ class OAuth2WebServerFlowTest(unittest.TestCase):
|
||||
credentials = self.flow.step2_exchange('some random code', http)
|
||||
self.assertEqual(None, credentials.token_expiry)
|
||||
|
||||
def test_exchange_fails_if_no_code(self):
|
||||
http = HttpMockSequence([
|
||||
({'status': '200'}, """{ "access_token":"SlAV32hkKG",
|
||||
"refresh_token":"8xLOxBtZp8" }"""),
|
||||
])
|
||||
|
||||
code = {'error': 'thou shall not pass'}
|
||||
try:
|
||||
credentials = self.flow.step2_exchange(code, http)
|
||||
self.fail('should raise exception if no code in dictionary.')
|
||||
except FlowExchangeError, e:
|
||||
self.assertTrue('shall not pass' in str(e))
|
||||
|
||||
def test_exchange_id_token_fail(self):
|
||||
http = HttpMockSequence([
|
||||
({'status': '200'}, """{ "access_token":"SlAV32hkKG",
|
||||
|
||||
Reference in New Issue
Block a user