|
14 | 14 |
|
15 | 15 | import unittest |
16 | 16 |
|
| 17 | +import mock |
| 18 | + |
17 | 19 |
|
18 | 20 | class TestConnection(unittest.TestCase): |
19 | 21 |
|
@@ -48,3 +50,33 @@ def test_build_api_url_w_extra_query_params(self): |
48 | 50 | '/'.join(['', 'bigquery', conn.API_VERSION, 'foo'])) |
49 | 51 | parms = dict(parse_qsl(qs)) |
50 | 52 | self.assertEqual(parms['bar'], 'baz') |
| 53 | + |
| 54 | + def test_extra_headers(self): |
| 55 | + from google.cloud import _http as base_http |
| 56 | + from google.cloud.bigquery import _http as MUT |
| 57 | + |
| 58 | + http = mock.Mock(spec=['request']) |
| 59 | + response = mock.Mock(status=200, spec=['status']) |
| 60 | + data = b'brent-spiner' |
| 61 | + http.request.return_value = response, data |
| 62 | + client = mock.Mock(_http=http, spec=['_http']) |
| 63 | + |
| 64 | + conn = self._make_one(client) |
| 65 | + req_data = 'req-data-boring' |
| 66 | + result = conn.api_request( |
| 67 | + 'GET', '/rainbow', data=req_data, expect_json=False) |
| 68 | + self.assertEqual(result, data) |
| 69 | + |
| 70 | + expected_headers = { |
| 71 | + 'Content-Length': str(len(req_data)), |
| 72 | + 'Accept-Encoding': 'gzip', |
| 73 | + base_http.CLIENT_INFO_HEADER: MUT._CLIENT_INFO, |
| 74 | + 'User-Agent': conn.USER_AGENT, |
| 75 | + } |
| 76 | + expected_uri = conn.build_api_url('/rainbow') |
| 77 | + http.request.assert_called_once_with( |
| 78 | + body=req_data, |
| 79 | + headers=expected_headers, |
| 80 | + method='GET', |
| 81 | + uri=expected_uri, |
| 82 | + ) |
0 commit comments