more tests

This commit is contained in:
Michael Barton 2010-10-29 10:28:19 +00:00
parent 655dba5cb2
commit cefcd568cd

View File

@ -481,16 +481,18 @@ class TestContainerController(unittest.TestCase):
def test_GET_json(self): def test_GET_json(self):
# make a container # 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'}) 'HTTP_X_TIMESTAMP': '0'})
resp = self.controller.PUT(req) resp = self.controller.PUT(req)
# test an empty container # 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) 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 # fill the container
for i in range(3): 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', {'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '1', 'HTTP_X_TIMESTAMP': '1',
'HTTP_X_CONTENT_TYPE': 'text/plain', 'HTTP_X_CONTENT_TYPE': 'text/plain',
@ -514,28 +516,33 @@ class TestContainerController(unittest.TestCase):
"bytes":0, "bytes":0,
"content_type":"text/plain", "content_type":"text/plain",
"last_modified":"1970-01-01T00:00:01"}] "last_modified":"1970-01-01T00:00:01"}]
req = Request.blank('/sda1/p/a/c?format=json', environ={'REQUEST_METHOD': 'GET'})
req = Request.blank('/sda1/p/a/jsonc?format=json',
environ={'REQUEST_METHOD': 'GET'})
resp = self.controller.GET(req) resp = self.controller.GET(req)
self.assertEquals(resp.content_type, 'application/json') self.assertEquals(resp.content_type, 'application/json')
result = eval(resp.body) self.assertEquals(eval(resp.body), json_body)
self.assertEquals(result, json_body)
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'}) for accept in ('application/json', 'application/json;q=1.0,*/*;q=0.9',
req.accept = 'application/json' '*/*;q=0.9,application/json;q=1.0', 'application/*'):
resp = self.controller.GET(req) req = Request.blank('/sda1/p/a/jsonc',
self.assertEquals(resp.content_type, 'application/json') environ={'REQUEST_METHOD': 'GET'})
result = eval(resp.body) req.accept = accept
self.assertEquals(result, json_body) resp = self.controller.GET(req)
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'}) self.assertEquals(eval(resp.body), json_body,
req.accept = 'application/*' 'Invalid body for Accept: %s' % accept)
resp = self.controller.GET(req) self.assertEquals(resp.content_type, 'application/json',
result = eval(resp.body) 'Invalid content_type for Accept: %s' % accept)
self.assertEquals(result, json_body)
def test_GET_plain(self): def test_GET_plain(self):
# make a container # make a container
req = Request.blank('/sda1/p/a/plainc', environ={'REQUEST_METHOD': 'PUT', req = Request.blank('/sda1/p/a/plainc', environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
resp = self.controller.PUT(req) 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 # fill the container
for i in range(3): for i in range(3):
req = Request.blank('/sda1/p/a/plainc/%s'%i, environ= req = Request.blank('/sda1/p/a/plainc/%s'%i, environ=
@ -555,13 +562,16 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(resp.body, plain_body) self.assertEquals(resp.body, plain_body)
for accept in ('', 'text/plain', 'application/xml;q=0.8,*/*;q=0.9', for accept in ('', 'text/plain', 'application/xml;q=0.8,*/*;q=0.9',
'*/*;q=0.9,application/xml;q=0.8', '*/*'): '*/*;q=0.9,application/xml;q=0.8', '*/*',
'text/plain,application/xml'):
req = Request.blank('/sda1/p/a/plainc', req = Request.blank('/sda1/p/a/plainc',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
req.accept = accept req.accept = accept
resp = self.controller.GET(req) resp = self.controller.GET(req)
self.assertEquals(resp.body, plain_body) self.assertEquals(resp.body, plain_body,
self.assertEquals(resp.content_type, 'text/plain') 'Invalid body for Accept: %s' % accept)
self.assertEquals(resp.content_type, 'text/plain',
'Invalid content_type for Accept: %s' % accept)
# test conflicting formats # test conflicting formats
req = Request.blank('/sda1/p/a/plainc?format=plain', req = Request.blank('/sda1/p/a/plainc?format=plain',
@ -609,13 +619,15 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(resp.body, xml_body) self.assertEquals(resp.body, xml_body)
for xml_accept in ('application/xml', 'application/xml;q=1.0,*/*;q=0.9', for xml_accept in ('application/xml', 'application/xml;q=1.0,*/*;q=0.9',
'*/*;q=0.9,application/xml;q=1.0'): '*/*;q=0.9,application/xml;q=1.0'):
req = Request.blank('/sda1/p/a/xmlc', req = Request.blank('/sda1/p/a/xmlc',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
req.accept = xml_accept req.accept = xml_accept
resp = self.controller.GET(req) resp = self.controller.GET(req)
self.assertEquals(resp.body, xml_body) self.assertEquals(resp.body, xml_body,
self.assertEquals(resp.content_type, 'application/xml') 'Invalid body for Accept: %s' % xml_accept)
self.assertEquals(resp.content_type, 'application/xml',
'Invalid content_type for Accept: %s' % xml_accept)
def test_GET_marker(self): def test_GET_marker(self):
# make a container # make a container