Fixed checking for stack query parameters so they actually get added to the query paramters.
This commit is contained in:
@@ -44,6 +44,8 @@ VARNAME = re.compile('[a-zA-Z0-9_-]+')
|
|||||||
DISCOVERY_URI = ('https://www.googleapis.com/discovery/v0.3/describe/'
|
DISCOVERY_URI = ('https://www.googleapis.com/discovery/v0.3/describe/'
|
||||||
'{api}/{apiVersion}')
|
'{api}/{apiVersion}')
|
||||||
DEFAULT_METHOD_DOC = 'A description of how to use this function'
|
DEFAULT_METHOD_DOC = 'A description of how to use this function'
|
||||||
|
|
||||||
|
# Query parameters that work, but don't appear in discovery
|
||||||
STACK_QUERY_PARAMETERS = ['trace']
|
STACK_QUERY_PARAMETERS = ['trace']
|
||||||
|
|
||||||
|
|
||||||
@@ -219,21 +221,29 @@ def createResource(http, baseUrl, model, requestBuilder,
|
|||||||
httpMethod = methodDesc['httpMethod']
|
httpMethod = methodDesc['httpMethod']
|
||||||
methodId = methodDesc['rpcMethod']
|
methodId = methodDesc['rpcMethod']
|
||||||
|
|
||||||
argmap = {}
|
if 'parameters' not in methodDesc:
|
||||||
|
methodDesc['parameters'] = {}
|
||||||
|
for name in STACK_QUERY_PARAMETERS:
|
||||||
|
methodDesc['parameters'][name] = {
|
||||||
|
'type': 'string',
|
||||||
|
'restParameterType': 'query'
|
||||||
|
}
|
||||||
|
|
||||||
if httpMethod in ['PUT', 'POST']:
|
if httpMethod in ['PUT', 'POST']:
|
||||||
if 'parameters' not in methodDesc:
|
|
||||||
methodDesc['parameters'] = {}
|
|
||||||
methodDesc['parameters']['body'] = {
|
methodDesc['parameters']['body'] = {
|
||||||
'description': 'The request body.',
|
'description': 'The request body.',
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argmap = {} # Map from method parameter name to query parameter name
|
||||||
required_params = [] # Required parameters
|
required_params = [] # Required parameters
|
||||||
pattern_params = {} # Parameters that must match a regex
|
pattern_params = {} # Parameters that must match a regex
|
||||||
query_params = [] # Parameters that will be used in the query string
|
query_params = [] # Parameters that will be used in the query string
|
||||||
path_params = {} # Parameters that will be used in the base URL
|
path_params = {} # Parameters that will be used in the base URL
|
||||||
param_type = {} # The type of the parameter
|
param_type = {} # The type of the parameter
|
||||||
enum_params = {}
|
enum_params = {} # Allowable enumeration values for each parameter
|
||||||
|
|
||||||
|
|
||||||
if 'parameters' in methodDesc:
|
if 'parameters' in methodDesc:
|
||||||
for arg, desc in methodDesc['parameters'].iteritems():
|
for arg, desc in methodDesc['parameters'].iteritems():
|
||||||
param = key2param(arg)
|
param = key2param(arg)
|
||||||
@@ -260,7 +270,7 @@ def createResource(http, baseUrl, model, requestBuilder,
|
|||||||
|
|
||||||
def method(self, **kwargs):
|
def method(self, **kwargs):
|
||||||
for name in kwargs.iterkeys():
|
for name in kwargs.iterkeys():
|
||||||
if name not in argmap and name not in STACK_QUERY_PARAMETERS:
|
if name not in argmap:
|
||||||
raise TypeError('Got an unexpected keyword argument "%s"' % name)
|
raise TypeError('Got an unexpected keyword argument "%s"' % name)
|
||||||
|
|
||||||
for name in required_params:
|
for name in required_params:
|
||||||
@@ -278,16 +288,17 @@ def createResource(http, baseUrl, model, requestBuilder,
|
|||||||
if name in kwargs:
|
if name in kwargs:
|
||||||
if kwargs[name] not in enums:
|
if kwargs[name] not in enums:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'Parameter "%s" value "%s" is not in the list of allowed values "%s"' %
|
'Parameter "%s" value "%s" is not an allowed value in "%s"' %
|
||||||
(name, kwargs[name], str(enums)))
|
(name, kwargs[name], str(enums)))
|
||||||
|
|
||||||
actual_query_params = {}
|
actual_query_params = {}
|
||||||
actual_path_params = {}
|
actual_path_params = {}
|
||||||
for key, value in kwargs.iteritems():
|
for key, value in kwargs.iteritems():
|
||||||
|
value_as_str = _to_string(value, param_type.get(key, 'string'))
|
||||||
if key in query_params:
|
if key in query_params:
|
||||||
actual_query_params[argmap[key]] = _to_string(value, param_type[key])
|
actual_query_params[argmap[key]] = value_as_str
|
||||||
if key in path_params:
|
if key in path_params:
|
||||||
actual_path_params[argmap[key]] = _to_string(value, param_type[key])
|
actual_path_params[argmap[key]] = value_as_str
|
||||||
body_value = kwargs.get('body', None)
|
body_value = kwargs.get('body', None)
|
||||||
|
|
||||||
if self._developerKey:
|
if self._developerKey:
|
||||||
@@ -321,6 +332,8 @@ def createResource(http, baseUrl, model, requestBuilder,
|
|||||||
if len(argmap) > 0:
|
if len(argmap) > 0:
|
||||||
docs.append("Args:\n")
|
docs.append("Args:\n")
|
||||||
for arg in argmap.iterkeys():
|
for arg in argmap.iterkeys():
|
||||||
|
if arg in STACK_QUERY_PARAMETERS:
|
||||||
|
continue
|
||||||
required = ""
|
required = ""
|
||||||
if arg in required_params:
|
if arg in required_params:
|
||||||
required = " (required)"
|
required = " (required)"
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ class Error(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class FlowExchangeError(Error):
|
class FlowExchangeError(Error):
|
||||||
"""Error occurred during request."""
|
"""Error trying to exchange an authorization grant for an access token."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AccessTokenRefreshError(Error):
|
class AccessTokenRefreshError(Error):
|
||||||
"""Error occurred during request."""
|
"""Error trying to refresh an expired access token."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,14 +65,14 @@ class Discovery(unittest.TestCase):
|
|||||||
buzz.activities().list(scope='@myself', userId='me')
|
buzz.activities().list(scope='@myself', userId='me')
|
||||||
self.fail()
|
self.fail()
|
||||||
except TypeError, e:
|
except TypeError, e:
|
||||||
self.assertTrue('not in the list' in str(e))
|
self.assertTrue('not an allowed value' in str(e))
|
||||||
|
|
||||||
# Parameter doesn't match regex
|
# Parameter doesn't match regex
|
||||||
try:
|
try:
|
||||||
buzz.activities().list(scope='not@', userId='foo')
|
buzz.activities().list(scope='not@', userId='foo')
|
||||||
self.fail()
|
self.fail()
|
||||||
except TypeError, e:
|
except TypeError, e:
|
||||||
self.assertTrue('not in the list' in str(e))
|
self.assertTrue('not an allowed value' in str(e))
|
||||||
|
|
||||||
# Unexpected parameter
|
# Unexpected parameter
|
||||||
try:
|
try:
|
||||||
@@ -108,6 +108,10 @@ class Discovery(unittest.TestCase):
|
|||||||
zoo = build('zoo', 'v1', self.http)
|
zoo = build('zoo', 'v1', self.http)
|
||||||
request = zoo.query(trace='html')
|
request = zoo.query(trace='html')
|
||||||
|
|
||||||
|
parsed = urlparse.urlparse(request.uri)
|
||||||
|
q = parse_qs(parsed[4])
|
||||||
|
self.assertEqual(q['trace'], ['html'])
|
||||||
|
|
||||||
def test_buzz_resources(self):
|
def test_buzz_resources(self):
|
||||||
self.http = HttpMock(datafile('buzz.json'), {'status': '200'})
|
self.http = HttpMock(datafile('buzz.json'), {'status': '200'})
|
||||||
buzz = build('buzz', 'v1', self.http)
|
buzz = build('buzz', 'v1', self.http)
|
||||||
|
|||||||
Reference in New Issue
Block a user