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

Method test_validate_headers

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

Source from the content-addressed store, hash-verified

417 test_client2.close()
418
419 def test_validate_headers(self) -> None:
420 client = Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
421 request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
422 assert request.headers.get("X-Api-Key") == api_key
423
424 with mock.patch("anthropic._client.default_credentials", return_value=None):
425 with update_env(**{"ANTHROPIC_API_KEY": Omit()}):
426 client2 = Anthropic(base_url=base_url, api_key=None, _strict_response_validation=True)
427
428 with pytest.raises(
429 TypeError,
430 match="Could not resolve authentication method. Expected one of api_key, auth_token, or credentials to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted",
431 ):
432 client2._build_request(FinalRequestOptions(method="get", url="/foo"))
433
434 request2 = client2._build_request(FinalRequestOptions(method="get", url="/foo", headers={"X-Api-Key": Omit()}))
435 assert request2.headers.get("X-Api-Key") is None
436
437 def test_default_query_option(self) -> None:
438 client = Anthropic(

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected