Permalink
Browse files

* Added some tests for the Content-Type header.

  • Loading branch information...
1 parent bf580df commit bfb6e44a7a444a332a6d3c9cf04326d5b3a09709 @breily committed Mar 21, 2009
Showing with 24 additions and 5 deletions.
  1. +24 −5 tests/test.py
View
@@ -30,10 +30,16 @@ def x2(web): juno.status(404)
def x3(web): juno.status(500)
@juno.get('/4/')
-def x4(web): return ''.join(''.join([k,v]) for k,v in web.input().items())
+def x4(web): return
@juno.get('/5/')
-def x5(web): return str(web.input())
+def x5(web): juno.content_type('text/json')
+
+@juno.get('/6/')
+def x6(web): return str(web.input())
+
+@juno.get('/7/')
+def x7(web): return str(web.input())
application = juno.run()
@@ -51,24 +57,37 @@ def test200StatusCode(self):
"""Juno should send a 200 by default"""
status, _, _ = client.request('/1/')
self.assertEqual(status, '200 OK')
+
def test404StatusCode(self):
"""Juno can use status() to set status code"""
status, _, _ = client.request('/2/')
self.assertEqual(status, '404 Not Found')
+
def test500StatusCode(self):
"""Juno can use status() to set status code"""
status, _, _ = client.request('/3/')
self.assertEqual(status, '500 Internal Server Error')
+ def testDefaultContentType(self):
+ client.request('/4/')
+ header = client.get_header('content-type')
+ self.assertEqual(header[1], 'text/html')
+
+ def testSetContentType(self):
+ client.request('/5/')
+ header = client.get_header('content-type')
+ self.assertEqual(header[1], 'text/json')
+
class QueryStringTest(unittest.TestCase):
"""Test Juno's handling of query strings. """
def testQueryStringHeader(self):
"""Juno can read query string and echo it back"""
- _, _, body = client.request('/4/', QUERY_STRING='a=5&b=0')
- self.assertEqual(body, ['a5b0'])
+ _, _, body = client.request('/6/', QUERY_STRING='a=5&b=0')
+ self.assertEqual(body, ["{'a': '5', 'b': '0'}"])
+
def testSameQueryStringKeys(self):
"""Juno can handle query strings with multiple indentical keys"""
- _, _, body = client.request('/5/', QUERY_STRING='a=0&a=1')
+ _, _, body = client.request('/7/', QUERY_STRING='a=0&a=1')
self.assertEqual(body, ["{'a': ['0', '1']}"])

0 comments on commit bfb6e44

Please sign in to comment.