thirdparty/google_appengine/lib/webob/tests/test_response.py
changeset 109 620f9b141567
equal deleted inserted replaced
108:261778de26ff 109:620f9b141567
       
     1 from webob import *
       
     2 
       
     3 def simple_app(environ, start_response):
       
     4     start_response('200 OK', [
       
     5         ('Content-Type', 'text/html; charset=utf8'),
       
     6         ])
       
     7     return ['OK']
       
     8 
       
     9 def test_response():
       
    10     req = Request.blank('/')
       
    11     res = req.get_response(simple_app)
       
    12     assert res.status == '200 OK'
       
    13     assert res.status_int == 200
       
    14     assert res.body == "OK"
       
    15     assert res.charset == 'utf8'
       
    16     assert res.content_type == 'text/html'
       
    17     res.status = 404
       
    18     assert res.status == '404 Not Found'
       
    19     assert res.status_int == 404
       
    20     res.body = 'Not OK'
       
    21     assert ''.join(res.app_iter) == 'Not OK'
       
    22     res.charset = 'iso8859-1'
       
    23     assert res.headers['content-type'] == 'text/html; charset=iso8859-1'
       
    24     res.content_type = 'text/xml'
       
    25     assert res.headers['content-type'] == 'text/xml; charset=iso8859-1'
       
    26     res.headers = {'content-type': 'text/html'}
       
    27     assert res.headers['content-type'] == 'text/html'
       
    28     assert res.headerlist == [('content-type', 'text/html')]
       
    29     res.set_cookie('x', 'y')
       
    30     assert res.headers['set-cookie'].strip(';') == 'x=y; Path=/'
       
    31     res = Response('a body', '200 OK', content_type='text/html')
       
    32     res.encode_content()
       
    33     assert res.content_encoding == 'gzip'
       
    34     assert res.body == '\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xffKTH\xcaO\xa9\x04\x00\xf6\x86GI\x06\x00\x00\x00'
       
    35     res.decode_content()
       
    36     assert res.content_encoding is None
       
    37     assert res.body == 'a body'