return dict(quota_set=result)
def _validate_quota_limit(self, limit):
+ if not isinstance(limit, int):
+ msg = _("Quota limit must be specified as an integer value.")
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+
# NOTE: -1 is a flag value for unlimited
if limit < -1:
msg = _("Quota limit must be -1 or greater.")
project_id = id
for key in body['quota_set'].keys():
if key in QUOTAS:
+ self._validate_quota_limit(body['quota_set'][key])
value = int(body['quota_set'][key])
- self._validate_quota_limit(value)
try:
db.quota_update(context, project_id, key, value)
except exception.ProjectQuotaNotFound:
result = self.controller.update(self.req, 'foo', body)
self.assertDictMatch(result, make_body(tenant_id=None))
+ def test_update_invalid_key_value(self):
+ body = {'quota_set': {'gigabytes': "should_be_int"}}
+ self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
+ self.req, 'foo', body)
+
def test_update_bad_quota_limit(self):
body = {'quota_set': {'gigabytes': -1000}}
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,