@@ -38,6 +38,36 @@ def test_default_url(self):
3838 conn = self ._make_one (client )
3939 self .assertEqual (conn ._client , client )
4040
41+ def test_extra_headers (self ):
42+ from google .cloud import _http as base_http
43+ from google .cloud .vision import _http as MUT
44+
45+ http = mock .Mock (spec = ['request' ])
46+ response = mock .Mock (status = 200 , spec = ['status' ])
47+ data = b'brent-spiner'
48+ http .request .return_value = response , data
49+ client = mock .Mock (_http = http , spec = ['_http' ])
50+
51+ conn = self ._make_one (client )
52+ req_data = 'req-data-boring'
53+ result = conn .api_request (
54+ 'GET' , '/rainbow' , data = req_data , expect_json = False )
55+ self .assertEqual (result , data )
56+
57+ expected_headers = {
58+ 'Content-Length' : str (len (req_data )),
59+ 'Accept-Encoding' : 'gzip' ,
60+ base_http .CLIENT_INFO_HEADER : MUT ._CLIENT_INFO ,
61+ 'User-Agent' : conn .USER_AGENT ,
62+ }
63+ expected_uri = conn .build_api_url ('/rainbow' )
64+ http .request .assert_called_once_with (
65+ body = req_data ,
66+ headers = expected_headers ,
67+ method = 'GET' ,
68+ uri = expected_uri ,
69+ )
70+
4171
4272class Test_HTTPVisionAPI (unittest .TestCase ):
4373 def _get_target_class (self ):
0 commit comments