MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_validate_headers

Method test_validate_headers

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

Source from the content-addressed store, hash-verified

336 assert request.headers.get("x-stainless-lang") == "my-overriding-header"
337
338 def test_validate_headers(self) -> None:
339 client = Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
340 request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
341 assert request.headers.get("X-Api-Key") == api_key
342
343 with update_env(**{"ANTHROPIC_API_KEY": Omit()}):
344 client2 = Anthropic(base_url=base_url, api_key=None, _strict_response_validation=True)
345
346 with pytest.raises(
347 TypeError,
348 match="Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted",
349 ):
350 client2._build_request(FinalRequestOptions(method="get", url="/foo"))
351
352 request2 = client2._build_request(FinalRequestOptions(method="get", url="/foo", headers={"X-Api-Key": Omit()}))
353 assert request2.headers.get("X-Api-Key") is None
354
355 def test_default_query_option(self) -> None:
356 client = Anthropic(

Callers

nothing calls this directly

Calls 6

AnthropicClass · 0.90
FinalRequestOptionsClass · 0.90
OmitClass · 0.90
update_envFunction · 0.85
_build_requestMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected