mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix: patch authenticator instance directly in TestResponsesAPIMiscMethods
setup_method creates a real Authenticator instance in __init__. @patch on the class doesn't affect the already-created instance. Instead, mock self.config.authenticator.get_api_key directly.
This commit is contained in:
parent
b4f1c64a4b
commit
07d390b2b8
1 changed files with 7 additions and 12 deletions
|
|
@ -604,29 +604,24 @@ class TestResponsesAPIMiscMethods:
|
|||
)
|
||||
assert url == "https://custom.example.com/v1/responses"
|
||||
|
||||
@patch("litellm.llms.github_copilot.responses.transformation.Authenticator")
|
||||
def test_validate_environment_no_api_key_raises(self, mock_authenticator_class):
|
||||
mock_authenticator_class.return_value.get_api_key.return_value = None
|
||||
def test_validate_environment_no_api_key_raises(self):
|
||||
self.config.authenticator.get_api_key = MagicMock(return_value=None)
|
||||
with pytest.raises(AuthenticationError):
|
||||
self.config.validate_environment(
|
||||
headers={}, model="gpt-4", litellm_params=None
|
||||
)
|
||||
|
||||
@patch("litellm.llms.github_copilot.responses.transformation.Authenticator")
|
||||
def test_validate_environment_get_api_key_error_raises(
|
||||
self, mock_authenticator_class
|
||||
):
|
||||
mock_authenticator_class.return_value.get_api_key.side_effect = GetAPIKeyError(
|
||||
status_code=401, message="key expired"
|
||||
def test_validate_environment_get_api_key_error_raises(self):
|
||||
self.config.authenticator.get_api_key = MagicMock(
|
||||
side_effect=GetAPIKeyError(status_code=401, message="key expired")
|
||||
)
|
||||
with pytest.raises(AuthenticationError):
|
||||
self.config.validate_environment(
|
||||
headers={}, model="gpt-4", litellm_params=None
|
||||
)
|
||||
|
||||
@patch("litellm.llms.github_copilot.responses.transformation.Authenticator")
|
||||
def test_validate_environment_with_conversation_key(self, mock_authenticator_class):
|
||||
mock_authenticator_class.return_value.get_api_key.return_value = "test-key"
|
||||
def test_validate_environment_with_conversation_key(self):
|
||||
self.config.authenticator.get_api_key = MagicMock(return_value="test-key")
|
||||
lp = GenericLiteLLMParams(metadata={"copilot_conversation_id": "test-conv"})
|
||||
headers = self.config.validate_environment(
|
||||
headers={}, model="gpt-4", litellm_params=lp
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue