Skip to content

Commit 67ec0c1

Browse files
authored
test: verify Client._connection.extra_headers functionality (#1932)
1 parent b844eef commit 67ec0c1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/unit/test_client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,30 @@ def test_ctor_w_load_job_config(self):
271271
self.assertIsInstance(client._default_load_job_config, LoadJobConfig)
272272
self.assertTrue(client._default_load_job_config.create_session)
273273

274+
def test__call_api_extra_headers(self):
275+
# Note: We test at a lower layer to ensure that extra headers are
276+
# populated when we actually make the call in requests.
277+
# Arrange
278+
http = mock.create_autospec(requests.Session, instance=True)
279+
http.is_mtls = False
280+
response = mock.create_autospec(requests.Response, instance=True)
281+
response.status_code = 200
282+
http.request.return_value = response
283+
creds = _make_credentials()
284+
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
285+
286+
# Act
287+
client._connection.extra_headers = {"x-goog-request-reason": "because-friday"}
288+
client._call_api(
289+
retry=None, method="GET", path="/bigquery/v2/projects/my-proj/jobs/my-job"
290+
)
291+
292+
# Assert
293+
http.request.assert_called_once()
294+
_, kwargs = http.request.call_args
295+
headers = kwargs["headers"]
296+
assert headers["x-goog-request-reason"] == "because-friday"
297+
274298
def test__call_api_applying_custom_retry_on_timeout(self):
275299
from concurrent.futures import TimeoutError
276300
from google.cloud.bigquery.retry import DEFAULT_RETRY

0 commit comments

Comments
 (0)