Changeset 5176

Show
Ignore:
Timestamp:
08/20/08 13:22:32 (5 months ago)
Author:
kskuhlman
Message:

Add unicode_response to testutil.BrowsingSession? (#1783)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/tests/test_testutil.py

    r3366 r5176  
    2020    get_name = turbogears.expose()(get_name) 
    2121 
     22    def get_unicode_name(self): 
     23        """Return a nonsense string of non-ascii characters""" 
     24        cherrypy.response.headers['Content-Type'] = 'text/plain; encoding=utf-8' 
     25        return u'\u1234\u9876\u3456'.encode('utf-8') 
     26    get_unicode_name = turbogears.expose()(get_unicode_name) 
    2227 
    2328def test_browser_session(): 
     
    4045    bs2.goto('/get_name') 
    4146    assert bs2.response == 'bs2' 
     47 
     48def test_unicode_response(): 
     49    cherrypy.root = MyRoot() 
     50    bs = testutil.BrowsingSession() 
     51    bs.goto('/get_unicode_name') 
     52    assert bs.response == u'\u1234\u9876\u3456'.encode('utf-8') 
     53    assert bs.unicode_response == u'\u1234\u9876\u3456' 
     54    assert type(bs.unicode_response) == unicode 
  • branches/1.0/turbogears/testutil.py

    r4741 r5176  
    105105            headers['Cookie'] = self.cookie.output() 
    106106        create_request(*args, **kwargs) 
     107        # If we were given an encoding in the content type we should use it to 
     108        # decode the response: 
     109        ctype_parts = cherrypy.response.headers['Content-Type'].split(';') 
     110        for parameter in ctype_parts[1:]: 
     111            attribute, value = parameter.strip().split('=') 
     112            try: 
     113                self.unicode_response = cherrypy.response.body[0].decode(value) 
     114                break 
     115            except: 
     116                # If the named encoding doesn't work then it doesn't work.  We 
     117                # just won't create the unicode_response field. 
     118                pass 
    107119        self.response = cherrypy.response.body[0] 
    108120        self.status = cherrypy.response.status 
  • branches/1.1/turbogears/tests/test_testutil.py

    r4695 r5176  
    2929    get_name = turbogears.expose()(get_name) 
    3030 
     31    def get_unicode_name(self): 
     32        """Return a nonsense string of non-ascii characters""" 
     33        cherrypy.response.headers['Content-Type'] = 'text/plain; encoding=utf-8' 
     34        return u'\u1234\u9876\u3456'.encode('utf-8') 
     35    get_unicode_name = turbogears.expose()(get_unicode_name) 
    3136 
    3237def test_browser_session(): 
     
    4752    bs2.goto('/get_name') 
    4853    assert bs2.response == 'bs2' 
     54 
     55def test_unicode_response(): 
     56    cherrypy.root = MyRoot() 
     57    bs = testutil.BrowsingSession() 
     58    bs.goto('/get_unicode_name') 
     59    assert bs.response == u'\u1234\u9876\u3456'.encode('utf-8') 
     60    assert bs.unicode_response == u'\u1234\u9876\u3456' 
     61    assert type(bs.unicode_response) == unicode 
  • branches/1.1/turbogears/testutil.py

    r5174 r5176  
    195195            headers['Cookie'] = self.cookie_encoded 
    196196        response = self.app.get(*args, **kwargs) 
     197         
     198        # If we were given an encoding in the content type we should use it to 
     199        # decode the response: 
     200        ctype_parts = response.headers['Content-Type'].split(';') 
     201        for parameter in ctype_parts[1:]: 
     202            attribute, value = parameter.strip().split('=') 
     203            try: 
     204                self.unicode_response = response.body.decode(value) 
     205                break 
     206            except: 
     207                # If the named encoding doesn't work then it doesn't work.  We 
     208                # just won't create the unicode_response field. 
     209                pass 
     210 
    197211        self.response = response.body 
    198212        self.status = response.status 
  • branches/1.5/turbogears/tests/test_testutil.py

    r4962 r5176  
    2828    get_name = turbogears.expose()(get_name) 
    2929 
     30    def get_unicode_name(self): 
     31        """Return a nonsense string of non-ascii characters""" 
     32        cherrypy.response.headers['Content-Type'] = 'text/plain; encoding=utf-8' 
     33        return u'\u1234\u9876\u3456'.encode('utf-8') 
     34    get_unicode_name = turbogears.expose()(get_unicode_name) 
    3035 
    3136def test_browser_session(): 
     
    4752    bs2.goto('/get_name') 
    4853    assert bs2.response == 'bs2' 
     54 
     55def test_unicode_response(): 
     56    cherrypy.root = MyRoot() 
     57    bs = testutil.BrowsingSession() 
     58    bs.goto('/get_unicode_name') 
     59    assert bs.response == u'\u1234\u9876\u3456'.encode('utf-8') 
     60    assert bs.unicode_response == u'\u1234\u9876\u3456' 
     61    assert type(bs.unicode_response) == unicode 
  • branches/1.5/turbogears/testutil.py

    r4963 r5176  
    134134        if self.cookie: 
    135135            headers['Cookie'] = self.cookie_encoded 
     136 
    136137        response = self.app.get(path, headers=headers, **kwargs) 
     138 
     139        # If we were given an encoding in the content type we should use it to 
     140        # decode the response: 
     141        ctype_parts = response.headers['Content-Type'].split(';') 
     142        for parameter in ctype_parts[1:]: 
     143            attribute, value = parameter.strip().split('=') 
     144            try: 
     145                self.unicode_response = response.body.decode(value) 
     146                break 
     147            except: 
     148                # If the named encoding doesn't work then it doesn't work.  We 
     149                # just won't create the unicode_response field. 
     150               pass 
     151 
    137152        self.response = response.body 
    138153        self.full_response = response