2020Unit tests for oauth2client.
2121"""
2222
23+ # pylint: disable=bad-indentation
2324__author__ = '[email protected] (Joe Gregorio)' 2425
2526import base64
@@ -531,7 +532,7 @@ def test_token_refresh_success(self):
531532 ])
532533 http = self .credentials .authorize (http )
533534 resp , content = http .request ('http://example.com' )
534- self .assertEqual (b 'Bearer 1/3w' , content [b 'Authorization' ])
535+ self .assertEqual ('Bearer 1/3w' , content ['Authorization' ])
535536 self .assertFalse (self .credentials .access_token_expired )
536537 self .assertEqual (token_response , self .credentials .token_response )
537538
@@ -599,17 +600,17 @@ def test_unicode_header_checks(self):
599600
600601 # First, test that we correctly encode basic objects, making sure
601602 # to include a bytes object. Note that oauth2client will normalize
602- # everything to bytes , no matter what python version we're in.
603+ # everything to strings , no matter what python version we're in.
603604 http = credentials .authorize (HttpMock (headers = {'status' : '200' }))
604605 headers = {u'foo' : 3 , b'bar' : True , 'baz' : b'abc' }
605- cleaned_headers = {b 'foo' : b '3' , b 'bar' : b 'True' , b 'baz' : b 'abc' }
606+ cleaned_headers = {'foo' : '3' , 'bar' : 'True' , 'baz' : 'abc' }
606607 http .request (u'http://example.com' , method = u'GET' , headers = headers )
607608 for k , v in cleaned_headers .items ():
608609 self .assertTrue (k in http .headers )
609610 self .assertEqual (v , http .headers [k ])
610611
611612 # Next, test that we do fail on unicode.
612- unicode_str = six . unichr ( 40960 ) + 'abcd'
613+ unicode_str = u' \u2602 ' + 'abcd'
613614 self .assertRaises (
614615 NonAsciiHeaderError ,
615616 http .request ,
@@ -631,14 +632,21 @@ def test_no_unicode_in_request_params(self):
631632 http = HttpMock (headers = {'status' : '200' })
632633 http = credentials .authorize (http )
633634 http .request (u'http://example.com' , method = u'GET' , headers = {u'foo' : u'bar' })
635+
636+ # oauth2client uses httplib2 and httplib2 says:
637+ # "** THE RESPONSE HEADERS ARE STRINGS, BUT THE CONTENT BODY IS BYTES **"
638+ # and from https://github.com/jcgregorio/httplib2/wiki/Examples-Python3
639+ # "In httplib2, the response headers are strings..."
640+ #
641+ # So, the headers should be of type str.
634642 for k , v in six .iteritems (http .headers ):
635- self .assertEqual ( six . binary_type , type ( k ))
636- self .assertEqual ( six . binary_type , type ( v ))
643+ self .assertTrue ( isinstance ( k , str ))
644+ self .assertTrue ( isinstance ( v , str ))
637645
638646 # Test again with unicode strings that can't simply be converted to ASCII.
639647 try :
640648 http .request (
641- u'http://example.com' , method = u'GET' , headers = {u'foo' : u'\N{COMET} ' })
649+ u'http://example.com' , method = u'GET' , headers = {u'foo' : u'\u2602 ' })
642650 self .fail ('Expected exception to be raised.' )
643651 except NonAsciiHeaderError :
644652 pass
@@ -724,7 +732,7 @@ def test_auth_header_sent(self):
724732 ])
725733 http = self .credentials .authorize (http )
726734 resp , content = http .request ('http://example.com' )
727- self .assertEqual (b 'Bearer foo' , content [b 'Authorization' ])
735+ self .assertEqual ('Bearer foo' , content ['Authorization' ])
728736
729737
730738class TestAssertionCredentials (unittest .TestCase ):
@@ -755,7 +763,7 @@ def test_assertion_refresh(self):
755763 ])
756764 http = self .credentials .authorize (http )
757765 resp , content = http .request ('http://example.com' )
758- self .assertEqual (b 'Bearer 1/3w' , content [b 'Authorization' ])
766+ self .assertEqual ('Bearer 1/3w' , content ['Authorization' ])
759767
760768 def test_token_revoke_success (self ):
761769 _token_revoke_test_helper (
0 commit comments