|
|
|
|
@@ -479,18 +479,20 @@ class TestContainerController(unittest.TestCase):
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.status_int, 412)
|
|
|
|
|
|
|
|
|
|
def test_GET_format(self):
|
|
|
|
|
def test_GET_json(self):
|
|
|
|
|
# make a container
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
|
req = Request.blank('/sda1/p/a/jsonc', environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '0'})
|
|
|
|
|
resp = self.controller.PUT(req)
|
|
|
|
|
# test an empty container
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req = Request.blank('/sda1/p/a/jsonc?format=json',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.status_int, 204)
|
|
|
|
|
self.assertEquals(resp.status_int, 200)
|
|
|
|
|
self.assertEquals(eval(resp.body), [])
|
|
|
|
|
# fill the container
|
|
|
|
|
for i in range(3):
|
|
|
|
|
req = Request.blank('/sda1/p/a/c/%s'%i, environ=
|
|
|
|
|
req = Request.blank('/sda1/p/a/jsonc/%s'%i, environ=
|
|
|
|
|
{'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '1',
|
|
|
|
|
'HTTP_X_CONTENT_TYPE': 'text/plain',
|
|
|
|
|
@@ -514,8 +516,88 @@ class TestContainerController(unittest.TestCase):
|
|
|
|
|
"bytes":0,
|
|
|
|
|
"content_type":"text/plain",
|
|
|
|
|
"last_modified":"1970-01-01T00:00:01"}]
|
|
|
|
|
|
|
|
|
|
req = Request.blank('/sda1/p/a/jsonc?format=json',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/json')
|
|
|
|
|
self.assertEquals(eval(resp.body), json_body)
|
|
|
|
|
|
|
|
|
|
for accept in ('application/json', 'application/json;q=1.0,*/*;q=0.9',
|
|
|
|
|
'*/*;q=0.9,application/json;q=1.0', 'application/*'):
|
|
|
|
|
req = Request.blank('/sda1/p/a/jsonc',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = accept
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(eval(resp.body), json_body,
|
|
|
|
|
'Invalid body for Accept: %s' % accept)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/json',
|
|
|
|
|
'Invalid content_type for Accept: %s' % accept)
|
|
|
|
|
|
|
|
|
|
def test_GET_plain(self):
|
|
|
|
|
# make a container
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc', environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '0'})
|
|
|
|
|
resp = self.controller.PUT(req)
|
|
|
|
|
# test an empty container
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.status_int, 204)
|
|
|
|
|
# fill the container
|
|
|
|
|
for i in range(3):
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc/%s'%i, environ=
|
|
|
|
|
{'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '1',
|
|
|
|
|
'HTTP_X_CONTENT_TYPE': 'text/plain',
|
|
|
|
|
'HTTP_X_ETAG': 'x',
|
|
|
|
|
'HTTP_X_SIZE': 0})
|
|
|
|
|
resp = self.controller.PUT(req)
|
|
|
|
|
self.assertEquals(resp.status_int, 201)
|
|
|
|
|
plain_body = '0\n1\n2\n'
|
|
|
|
|
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/plain')
|
|
|
|
|
self.assertEquals(resp.body, plain_body)
|
|
|
|
|
|
|
|
|
|
for accept in ('', 'text/plain', 'application/xml;q=0.8,*/*;q=0.9',
|
|
|
|
|
'*/*;q=0.9,application/xml;q=0.8', '*/*',
|
|
|
|
|
'text/plain,application/xml'):
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = accept
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.body, plain_body,
|
|
|
|
|
'Invalid body for Accept: %s' % accept)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/plain',
|
|
|
|
|
'Invalid content_type for Accept: %s' % accept)
|
|
|
|
|
|
|
|
|
|
# test conflicting formats
|
|
|
|
|
req = Request.blank('/sda1/p/a/plainc?format=plain',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'application/json'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/plain')
|
|
|
|
|
self.assertEquals(resp.body, plain_body)
|
|
|
|
|
|
|
|
|
|
def test_GET_xml(self):
|
|
|
|
|
# make a container
|
|
|
|
|
req = Request.blank('/sda1/p/a/xmlc', environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '0'})
|
|
|
|
|
resp = self.controller.PUT(req)
|
|
|
|
|
# fill the container
|
|
|
|
|
for i in range(3):
|
|
|
|
|
req = Request.blank('/sda1/p/a/xmlc/%s'%i, environ=
|
|
|
|
|
{'REQUEST_METHOD': 'PUT',
|
|
|
|
|
'HTTP_X_TIMESTAMP': '1',
|
|
|
|
|
'HTTP_X_CONTENT_TYPE': 'text/plain',
|
|
|
|
|
'HTTP_X_ETAG': 'x',
|
|
|
|
|
'HTTP_X_SIZE': 0})
|
|
|
|
|
resp = self.controller.PUT(req)
|
|
|
|
|
self.assertEquals(resp.status_int, 201)
|
|
|
|
|
xml_body = '<?xml version="1.0" encoding="UTF-8"?>\n' \
|
|
|
|
|
'<container name="c">' \
|
|
|
|
|
'<container name="xmlc">' \
|
|
|
|
|
'<object><name>0</name><hash>x</hash><bytes>0</bytes>' \
|
|
|
|
|
'<content_type>text/plain</content_type>' \
|
|
|
|
|
'<last_modified>1970-01-01T00:00:01' \
|
|
|
|
|
@@ -529,46 +611,30 @@ class TestContainerController(unittest.TestCase):
|
|
|
|
|
'<last_modified>1970-01-01T00:00:01' \
|
|
|
|
|
'</last_modified></object>' \
|
|
|
|
|
'</container>'
|
|
|
|
|
plain_body = '0\n1\n2\n'
|
|
|
|
|
req = Request.blank('/sda1/p/a/c?format=json', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/json')
|
|
|
|
|
result = eval(resp.body)
|
|
|
|
|
self.assertEquals(result, json_body)
|
|
|
|
|
req = Request.blank('/sda1/p/a/c?format=xml', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
# tests
|
|
|
|
|
req = Request.blank('/sda1/p/a/xmlc?format=xml',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/xml')
|
|
|
|
|
result = resp.body
|
|
|
|
|
self.assertEquals(result, xml_body)
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'application/json'
|
|
|
|
|
self.assertEquals(resp.body, xml_body)
|
|
|
|
|
|
|
|
|
|
for xml_accept in ('application/xml', 'application/xml;q=1.0,*/*;q=0.9',
|
|
|
|
|
'*/*;q=0.9,application/xml;q=1.0', 'application/xml,text/xml'):
|
|
|
|
|
req = Request.blank('/sda1/p/a/xmlc',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = xml_accept
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.body, xml_body,
|
|
|
|
|
'Invalid body for Accept: %s' % xml_accept)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/xml',
|
|
|
|
|
'Invalid content_type for Accept: %s' % xml_accept)
|
|
|
|
|
|
|
|
|
|
req = Request.blank('/sda1/p/a/xmlc',
|
|
|
|
|
environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'text/xml'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'application/json')
|
|
|
|
|
result = eval(resp.body)
|
|
|
|
|
self.assertEquals(result, json_body)
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = '*/*'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/plain')
|
|
|
|
|
result = resp.body
|
|
|
|
|
self.assertEquals(result, plain_body)
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'application/*'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
result = eval(resp.body)
|
|
|
|
|
self.assertEquals(result, json_body)
|
|
|
|
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'application/xml'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
result = resp.body
|
|
|
|
|
self.assertEquals(result, xml_body)
|
|
|
|
|
# test conflicting formats
|
|
|
|
|
req = Request.blank('/sda1/p/a/c?format=plain', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
req.accept = 'application/json'
|
|
|
|
|
resp = self.controller.GET(req)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/plain')
|
|
|
|
|
result = resp.body
|
|
|
|
|
self.assertEquals(result, plain_body)
|
|
|
|
|
self.assertEquals(resp.content_type, 'text/xml')
|
|
|
|
|
self.assertEquals(resp.body, xml_body)
|
|
|
|
|
|
|
|
|
|
def test_GET_marker(self):
|
|
|
|
|
# make a container
|
|
|
|
|
|