MCPcopy Index your code
hub / github.com/openai/openai-python / test_copy_default_headers

Method test_copy_default_headers

tests/test_client.py:1438–1475  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1436 assert isinstance(async_client.timeout, httpx.Timeout)
1437
1438 async def test_copy_default_headers(self) -> None:
1439 client = AsyncOpenAI(
1440 base_url=base_url,
1441 api_key=api_key,
1442 admin_api_key=admin_api_key,
1443 _strict_response_validation=True,
1444 default_headers={"X-Foo": "bar"},
1445 )
1446 assert client.default_headers["X-Foo"] == "bar"
1447
1448 # does not override the already given value when not specified
1449 copied = client.copy()
1450 assert copied.default_headers["X-Foo"] == "bar"
1451
1452 # merges already given headers
1453 copied = client.copy(default_headers={"X-Bar": "stainless"})
1454 assert copied.default_headers["X-Foo"] == "bar"
1455 assert copied.default_headers["X-Bar"] == "stainless"
1456
1457 # uses new values for any already given headers
1458 copied = client.copy(default_headers={"X-Foo": "stainless"})
1459 assert copied.default_headers["X-Foo"] == "stainless"
1460
1461 # set_default_headers
1462
1463 # completely overrides already set values
1464 copied = client.copy(set_default_headers={})
1465 assert copied.default_headers.get("X-Foo") is None
1466
1467 copied = client.copy(set_default_headers={"X-Bar": "Robert"})
1468 assert copied.default_headers["X-Bar"] == "Robert"
1469
1470 with pytest.raises(
1471 ValueError,
1472 match="`default_headers` and `set_default_headers` arguments are mutually exclusive",
1473 ):
1474 client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"})
1475 await client.close()
1476
1477 async def test_copy_default_query(self) -> None:
1478 client = AsyncOpenAI(

Callers

nothing calls this directly

Calls 4

copyMethod · 0.95
AsyncOpenAIClass · 0.90
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected