Extra unit tests for check_delete_headers
A few extra tests to verify check_delete_headers in constraints.py. A little duplication of coverage of existing proxy/controllers/test_obj.py:TestObjController.test_POST_delete_at but these tests call the recently refactored function directly, and also add tests for X-Delete-After taking precedence over X-Delete-At. Change-Id: I129cef15a6feac8a60fd4efbb3535d93f0eaab36
This commit is contained in:
parent
9dcf15f8b5
commit
4dc718e8c3
@ -325,6 +325,49 @@ class TestConstraints(unittest.TestCase):
|
||||
else:
|
||||
self.fail("Should have failed with HTTPBadRequest")
|
||||
|
||||
def test_check_delete_headers_sets_delete_at(self):
|
||||
t = time.time() + 1000
|
||||
# check delete-at is passed through
|
||||
headers = {'Content-Length': '0',
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Delete-At': str(int(t))}
|
||||
req = Request.blank('/', headers=headers)
|
||||
constraints.check_delete_headers(req)
|
||||
self.assertTrue('X-Delete-At' in req.headers)
|
||||
self.assertEqual(req.headers['X-Delete-At'], str(int(t)))
|
||||
|
||||
# check delete-after is converted to delete-at
|
||||
headers = {'Content-Length': '0',
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Delete-After': '42'}
|
||||
req = Request.blank('/', headers=headers)
|
||||
with mock.patch('time.time', lambda: t):
|
||||
constraints.check_delete_headers(req)
|
||||
self.assertTrue('X-Delete-At' in req.headers)
|
||||
expected = str(int(t) + 42)
|
||||
self.assertEqual(req.headers['X-Delete-At'], expected)
|
||||
|
||||
# check delete-after takes precedence over delete-at
|
||||
headers = {'Content-Length': '0',
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Delete-After': '42',
|
||||
'X-Delete-At': str(int(t) + 40)}
|
||||
req = Request.blank('/', headers=headers)
|
||||
with mock.patch('time.time', lambda: t):
|
||||
constraints.check_delete_headers(req)
|
||||
self.assertTrue('X-Delete-At' in req.headers)
|
||||
self.assertEqual(req.headers['X-Delete-At'], expected)
|
||||
|
||||
headers = {'Content-Length': '0',
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Delete-After': '42',
|
||||
'X-Delete-At': str(int(t) + 44)}
|
||||
req = Request.blank('/', headers=headers)
|
||||
with mock.patch('time.time', lambda: t):
|
||||
constraints.check_delete_headers(req)
|
||||
self.assertTrue('X-Delete-At' in req.headers)
|
||||
self.assertEqual(req.headers['X-Delete-At'], expected)
|
||||
|
||||
def test_check_mount(self):
|
||||
self.assertFalse(constraints.check_mount('', ''))
|
||||
with mock.patch("swift.common.utils.ismount", MockTrue()):
|
||||
|
Loading…
Reference in New Issue
Block a user