Commit 56f2988c authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

quotaholder: Unify included data in overLimit errors

Replace `available' with `usage' and `limit' in NoQuantityError
to make it similar to NoCapacityError.
parent fc5e138f
......@@ -258,10 +258,8 @@ for the commission. On failure, in the case of ``overLimit`` (413) or
``itemNotFound`` (404), the returned cloudFault contains an extra field
``data`` with additional application-specific information. It contains at
least the ``provision`` that is to blame and the actual ``name`` of the
exception raised. In case of ``NoCapacityError``, ``limit`` and ``usage`` are
also included; in case of ``NoQuantityError`` (that is, when attempting to
release a value greater than what is registered), the ``available`` quantity
is provided.
exception raised. In the case of ``overLimit``, ``limit`` and ``usage`` are
also included.
**Example Successful Response**:
......
......@@ -118,7 +118,8 @@ class Release(Operation):
provision = cls.provision(holding, quantity, importing=False)
raise NoQuantityError(m,
provision=provision,
available=usage_min)
limit=0,
usage=usage_min)
holding.usage_min = new_usage_min
holding.save()
......
......@@ -63,17 +63,19 @@ class CommissionException(QuotaholderError):
QuotaholderError.__init__(self, *args, **kwargs)
class NoCapacityError(CommissionException):
class OverLimitError(CommissionException):
def __init__(self, *args, **kwargs):
self.add_data(kwargs, 'usage')
self.add_data(kwargs, 'limit')
CommissionException.__init__(self, *args, **kwargs)
class NoQuantityError(CommissionException):
def __init__(self, *args, **kwargs):
self.add_data(kwargs, 'available')
CommissionException.__init__(self, *args, **kwargs)
class NoCapacityError(OverLimitError):
pass
class NoQuantityError(OverLimitError):
pass
class NoHoldingError(CommissionException):
......
......@@ -124,7 +124,8 @@ class QuotaholderTest(TestCase):
self.assertEqual(provision['source'], source)
self.assertEqual(provision['resource'], resource1)
self.assertEqual(provision['quantity'], -1)
self.assertEqual(e.data['available'], 0)
self.assertEqual(e.data['usage'], 0)
self.assertEqual(e.data['limit'], 0)
with self.assertRaises(NoHoldingError) as cm:
self.issue_commission([((holder, source, resource1), 1),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment