35
35
from oauth2client import client
36
36
from oauth2client import clientsecrets
37
37
from oauth2client import service_account
38
+ from oauth2client import transport
38
39
from . import http_mock
39
40
40
41
__author__ = '[email protected] (Joe Gregorio)'
@@ -899,7 +900,7 @@ def test_token_refresh_success(self):
899
900
({'status' : http_client .OK }, 'echo_request_headers' ),
900
901
])
901
902
http = self .credentials .authorize (http )
902
- resp , content = http .request ('http://example.com' )
903
+ resp , content = transport .request (http , 'http://example.com' )
903
904
self .assertEqual (b'Bearer 1/3w' , content [b'Authorization' ])
904
905
self .assertFalse (self .credentials .access_token_expired )
905
906
self .assertEqual (token_response , self .credentials .token_response )
@@ -918,7 +919,7 @@ def test_recursive_authorize(self):
918
919
http = http_mock .HttpMock (data = encoded_response )
919
920
http = self .credentials .authorize (http )
920
921
http = self .credentials .authorize (http )
921
- http .request ('http://example.com' )
922
+ transport .request (http , 'http://example.com' )
922
923
923
924
def test_token_refresh_failure (self ):
924
925
for status_code in client .REFRESH_STATUS_CODES :
@@ -930,7 +931,7 @@ def test_token_refresh_failure(self):
930
931
http = self .credentials .authorize (http )
931
932
with self .assertRaises (
932
933
client .HttpAccessTokenRefreshError ) as exc_manager :
933
- http .request ('http://example.com' )
934
+ transport .request (http , 'http://example.com' )
934
935
self .assertEqual (http_client .BAD_REQUEST ,
935
936
exc_manager .exception .status )
936
937
self .assertTrue (self .credentials .access_token_expired )
@@ -957,7 +958,7 @@ def test_token_revoke_fallback(self):
957
958
def test_non_401_error_response (self ):
958
959
http = http_mock .HttpMock (headers = {'status' : http_client .BAD_REQUEST })
959
960
http = self .credentials .authorize (http )
960
- resp , content = http .request ('http://example.com' )
961
+ resp , content = transport .request (http , 'http://example.com' )
961
962
self .assertEqual (http_client .BAD_REQUEST , resp .status )
962
963
self .assertEqual (None , self .credentials .token_response )
963
964
@@ -1001,16 +1002,18 @@ def test_unicode_header_checks(self):
1001
1002
http = credentials .authorize (http_mock .HttpMock ())
1002
1003
headers = {u'foo' : 3 , b'bar' : True , 'baz' : b'abc' }
1003
1004
cleaned_headers = {b'foo' : b'3' , b'bar' : b'True' , b'baz' : b'abc' }
1004
- http .request (u'http://example.com' , method = u'GET' , headers = headers )
1005
+ transport .request (
1006
+ http , u'http://example.com' , method = u'GET' , headers = headers )
1005
1007
for k , v in cleaned_headers .items ():
1006
1008
self .assertTrue (k in http .headers )
1007
1009
self .assertEqual (v , http .headers [k ])
1008
1010
1009
1011
# Next, test that we do fail on unicode.
1010
1012
unicode_str = six .unichr (40960 ) + 'abcd'
1011
1013
with self .assertRaises (client .NonAsciiHeaderError ):
1012
- http .request (u'http://example.com' , method = u'GET' ,
1013
- headers = {u'foo' : unicode_str })
1014
+ transport .request (
1015
+ http , u'http://example.com' , method = u'GET' ,
1016
+ headers = {u'foo' : unicode_str })
1014
1017
1015
1018
def test_no_unicode_in_request_params (self ):
1016
1019
access_token = u'foo'
@@ -1027,17 +1030,18 @@ def test_no_unicode_in_request_params(self):
1027
1030
1028
1031
http = http_mock .HttpMock ()
1029
1032
http = credentials .authorize (http )
1030
- http .request (u'http://example.com' , method = u'GET' ,
1031
- headers = {u'foo' : u'bar' })
1033
+ transport .request (
1034
+ http , u'http://example.com' , method = u'GET' ,
1035
+ headers = {u'foo' : u'bar' })
1032
1036
for k , v in six .iteritems (http .headers ):
1033
1037
self .assertIsInstance (k , six .binary_type )
1034
1038
self .assertIsInstance (v , six .binary_type )
1035
1039
1036
1040
# Test again with unicode strings that can't simply be converted
1037
1041
# to ASCII.
1038
1042
with self .assertRaises (client .NonAsciiHeaderError ):
1039
- http .request (
1040
- u'http://example.com' , method = u'GET' ,
1043
+ transport .request (
1044
+ http , u'http://example.com' , method = u'GET' ,
1041
1045
headers = {u'foo' : u'\N{COMET} ' })
1042
1046
1043
1047
self .credentials .token_response = 'foobar'
@@ -1473,7 +1477,7 @@ def test_refresh_updates_id_token(self):
1473
1477
({'status' : '200' }, 'echo_request_headers' ),
1474
1478
])
1475
1479
http = self .credentials .authorize (http )
1476
- resp , content = http .request ('http://example.com' )
1480
+ resp , content = transport .request (http , 'http://example.com' )
1477
1481
self .assertEqual (self .credentials .id_token , body )
1478
1482
1479
1483
@@ -1492,7 +1496,7 @@ def test_token_refresh_success(self):
1492
1496
headers = {'status' : status_code }, data = b'' )
1493
1497
http = self .credentials .authorize (http )
1494
1498
with self .assertRaises (client .AccessTokenCredentialsError ):
1495
- resp , content = http .request ('http://example.com' )
1499
+ resp , content = transport .request (http , 'http://example.com' )
1496
1500
1497
1501
def test_token_revoke_success (self ):
1498
1502
_token_revoke_test_helper (
@@ -1507,15 +1511,15 @@ def test_token_revoke_failure(self):
1507
1511
def test_non_401_error_response (self ):
1508
1512
http = http_mock .HttpMock (headers = {'status' : http_client .BAD_REQUEST })
1509
1513
http = self .credentials .authorize (http )
1510
- resp , content = http .request ('http://example.com' )
1514
+ resp , content = transport .request (http , 'http://example.com' )
1511
1515
self .assertEqual (http_client .BAD_REQUEST , resp .status )
1512
1516
1513
1517
def test_auth_header_sent (self ):
1514
1518
http = http_mock .HttpMockSequence ([
1515
1519
({'status' : '200' }, 'echo_request_headers' ),
1516
1520
])
1517
1521
http = self .credentials .authorize (http )
1518
- resp , content = http .request ('http://example.com' )
1522
+ resp , content = transport .request (http , 'http://example.com' )
1519
1523
self .assertEqual (b'Bearer foo' , content [b'Authorization' ])
1520
1524
1521
1525
@@ -1551,7 +1555,7 @@ def test_assertion_refresh(self):
1551
1555
({'status' : '200' }, 'echo_request_headers' ),
1552
1556
])
1553
1557
http = self .credentials .authorize (http )
1554
- resp , content = http .request ('http://example.com' )
1558
+ resp , content = transport .request (http , 'http://example.com' )
1555
1559
self .assertEqual (b'Bearer 1/3w' , content [b'Authorization' ])
1556
1560
1557
1561
def test_token_revoke_success (self ):
@@ -1742,16 +1746,17 @@ def _step1_get_device_and_user_codes_helper(
1742
1746
device_code , user_code , None , ver_url , None )
1743
1747
self .assertEqual (result , expected )
1744
1748
self .assertEqual (len (http .requests ), 1 )
1745
- self .assertEqual (
1746
- http .requests [0 ]['uri' ], oauth2client .GOOGLE_DEVICE_URI )
1747
- body = http .requests [0 ]['body' ]
1748
- self .assertEqual (urllib .parse .parse_qs (body ),
1749
- {'client_id' : [flow .client_id ],
1750
- 'scope' : [flow .scope ]})
1749
+ info = http .requests [0 ]
1750
+ self .assertEqual (info ['uri' ], oauth2client .GOOGLE_DEVICE_URI )
1751
+ expected_body = {
1752
+ 'client_id' : [flow .client_id ],
1753
+ 'scope' : [flow .scope ],
1754
+ }
1755
+ self .assertEqual (urllib .parse .parse_qs (info ['body' ]), expected_body )
1751
1756
headers = {'content-type' : 'application/x-www-form-urlencoded' }
1752
1757
if extra_headers is not None :
1753
1758
headers .update (extra_headers )
1754
- self .assertEqual (http . requests [ 0 ] ['headers' ], headers )
1759
+ self .assertEqual (info ['headers' ], headers )
1755
1760
1756
1761
def test_step1_get_device_and_user_codes (self ):
1757
1762
self ._step1_get_device_and_user_codes_helper ()
0 commit comments