Fixed checking for stack query parameters so they actually get added to the query paramters.

This commit is contained in:
Joe Gregorio
2011-02-22 19:39:42 -05:00
parent 132179528d
commit ca876e4b9c
3 changed files with 29 additions and 12 deletions

View File

@@ -44,6 +44,8 @@ VARNAME = re.compile('[a-zA-Z0-9_-]+')
DISCOVERY_URI = ('https://www.googleapis.com/discovery/v0.3/describe/'
'{api}/{apiVersion}')
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']
@@ -219,21 +221,29 @@ def createResource(http, baseUrl, model, requestBuilder,
httpMethod = methodDesc['httpMethod']
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 'parameters' not in methodDesc:
methodDesc['parameters'] = {}
methodDesc['parameters']['body'] = {
'description': 'The request body.',
'type': 'object',
}
argmap = {} # Map from method parameter name to query parameter name
required_params = [] # Required parameters
pattern_params = {} # Parameters that must match a regex
query_params = [] # Parameters that will be used in the query string
path_params = {} # Parameters that will be used in the base URL
param_type = {} # The type of the parameter
enum_params = {}
enum_params = {} # Allowable enumeration values for each parameter
if 'parameters' in methodDesc:
for arg, desc in methodDesc['parameters'].iteritems():
param = key2param(arg)
@@ -260,7 +270,7 @@ def createResource(http, baseUrl, model, requestBuilder,
def method(self, **kwargs):
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)
for name in required_params:
@@ -278,16 +288,17 @@ def createResource(http, baseUrl, model, requestBuilder,
if name in kwargs:
if kwargs[name] not in enums:
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)))
actual_query_params = {}
actual_path_params = {}
for key, value in kwargs.iteritems():
value_as_str = _to_string(value, param_type.get(key, 'string'))
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:
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)
if self._developerKey:
@@ -321,6 +332,8 @@ def createResource(http, baseUrl, model, requestBuilder,
if len(argmap) > 0:
docs.append("Args:\n")
for arg in argmap.iterkeys():
if arg in STACK_QUERY_PARAMETERS:
continue
required = ""
if arg in required_params:
required = " (required)"

View File

@@ -37,12 +37,12 @@ class Error(Exception):
class FlowExchangeError(Error):
"""Error occurred during request."""
"""Error trying to exchange an authorization grant for an access token."""
pass
class AccessTokenRefreshError(Error):
"""Error occurred during request."""
"""Error trying to refresh an expired access token."""
pass

View File

@@ -65,14 +65,14 @@ class Discovery(unittest.TestCase):
buzz.activities().list(scope='@myself', userId='me')
self.fail()
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
try:
buzz.activities().list(scope='not@', userId='foo')
self.fail()
except TypeError, e:
self.assertTrue('not in the list' in str(e))
self.assertTrue('not an allowed value' in str(e))
# Unexpected parameter
try:
@@ -108,6 +108,10 @@ class Discovery(unittest.TestCase):
zoo = build('zoo', 'v1', self.http)
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):
self.http = HttpMock(datafile('buzz.json'), {'status': '200'})
buzz = build('buzz', 'v1', self.http)