GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: verify `Client._connection.extra_headers` functionality (#1932) · chenhance/python-bigquery@67ec0c1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/unit
    • test_client.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/unit/test_client.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_client.py
+24Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.