(self)
| 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( |
nothing calls this directly
no test coverage detected