Merge "Account Quota Correction"
This commit is contained in:
commit
4ae0feb60d
@ -84,6 +84,8 @@ class AccountQuotaMiddleware(object):
|
||||
return HTTPForbidden()
|
||||
|
||||
account_info = get_account_info(request.environ, self.app)
|
||||
if not account_info or not account_info['bytes']:
|
||||
return self.app
|
||||
new_size = int(account_info['bytes']) + (request.content_length or 0)
|
||||
quota = int(account_info['meta'].get('quota-bytes', -1))
|
||||
|
||||
|
@ -29,6 +29,15 @@ class FakeCache(object):
|
||||
pass
|
||||
|
||||
|
||||
class FakeBadApp(object):
|
||||
def __init__(self, headers=[]):
|
||||
self.headers = headers
|
||||
|
||||
def __call__(self, env, start_response):
|
||||
start_response('404 NotFound', self.headers)
|
||||
return []
|
||||
|
||||
|
||||
class FakeApp(object):
|
||||
def __init__(self, headers=[]):
|
||||
self.headers = headers
|
||||
@ -88,6 +97,26 @@ class TestAccountQuota(unittest.TestCase):
|
||||
res = req.get_response(app)
|
||||
self.assertEquals(res.status_int, 200)
|
||||
|
||||
def test_bad_application_quota(self):
|
||||
headers = []
|
||||
app = account_quotas.AccountQuotaMiddleware(FakeBadApp(headers))
|
||||
cache = FakeCache(None)
|
||||
req = Request.blank('/v1/a/c/o',
|
||||
environ={'REQUEST_METHOD': 'PUT',
|
||||
'swift.cache': cache})
|
||||
res = req.get_response(app)
|
||||
self.assertEquals(res.status_int, 404)
|
||||
|
||||
def test_no_info_quota(self):
|
||||
headers = []
|
||||
app = account_quotas.AccountQuotaMiddleware(FakeApp(headers))
|
||||
cache = FakeCache(None)
|
||||
req = Request.blank('/v1/a/c/o',
|
||||
environ={'REQUEST_METHOD': 'PUT',
|
||||
'swift.cache': cache})
|
||||
res = req.get_response(app)
|
||||
self.assertEquals(res.status_int, 200)
|
||||
|
||||
def test_not_exceed_bytes_quota(self):
|
||||
headers = [('x-account-bytes-used', '1000'),
|
||||
('x-account-meta-quota-bytes', 2000)]
|
||||
|
Loading…
Reference in New Issue
Block a user