mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
fix: Resolve TypeError in SSL verification tests by mocking Model class
This commit is contained in:
parent
e5a85108d7
commit
85b9bdd8f4
2 changed files with 37 additions and 24 deletions
|
@ -687,12 +687,18 @@ class TestMain(TestCase):
|
||||||
@patch("aider.models.ModelInfoManager.set_verify_ssl")
|
@patch("aider.models.ModelInfoManager.set_verify_ssl")
|
||||||
def test_no_verify_ssl_sets_model_info_manager(self, mock_set_verify_ssl):
|
def test_no_verify_ssl_sets_model_info_manager(self, mock_set_verify_ssl):
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
main(
|
# Mock Model class to avoid actual model initialization
|
||||||
["--no-verify-ssl", "--exit", "--yes"],
|
with patch("aider.models.Model") as mock_model:
|
||||||
input=DummyInput(),
|
# Configure the mock to avoid the TypeError
|
||||||
output=DummyOutput(),
|
mock_model.return_value.info = {}
|
||||||
)
|
mock_model.return_value.validate_environment.return_value = {"missing_keys": [], "keys_in_environment": []}
|
||||||
mock_set_verify_ssl.assert_called_once_with(False)
|
|
||||||
|
main(
|
||||||
|
["--no-verify-ssl", "--exit", "--yes"],
|
||||||
|
input=DummyInput(),
|
||||||
|
output=DummyOutput(),
|
||||||
|
)
|
||||||
|
mock_set_verify_ssl.assert_called_once_with(False)
|
||||||
|
|
||||||
def test_pytest_env_vars(self):
|
def test_pytest_env_vars(self):
|
||||||
# Verify that environment variables from pytest.ini are properly set
|
# Verify that environment variables from pytest.ini are properly set
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TestSSLVerification(TestCase):
|
||||||
os.environ.clear()
|
os.environ.clear()
|
||||||
os.environ.update(self.original_env)
|
os.environ.update(self.original_env)
|
||||||
|
|
||||||
@patch("aider.models.model_info_manager.set_verify_ssl")
|
@patch("aider.models.ModelInfoManager.set_verify_ssl")
|
||||||
@patch("aider.llm.litellm._load_litellm")
|
@patch("aider.llm.litellm._load_litellm")
|
||||||
@patch("httpx.Client")
|
@patch("httpx.Client")
|
||||||
@patch("httpx.AsyncClient")
|
@patch("httpx.AsyncClient")
|
||||||
|
@ -29,23 +29,30 @@ class TestSSLVerification(TestCase):
|
||||||
# Mock the litellm._lazy_module to avoid AttributeError
|
# Mock the litellm._lazy_module to avoid AttributeError
|
||||||
mock_load_litellm.return_value = None
|
mock_load_litellm.return_value = None
|
||||||
mock_module = MagicMock()
|
mock_module = MagicMock()
|
||||||
with patch("aider.llm.litellm._lazy_module", mock_module):
|
|
||||||
# Run main with --no-verify-ssl flag
|
# Mock Model class to avoid actual model initialization
|
||||||
main(
|
with patch("aider.models.Model") as mock_model:
|
||||||
["--no-verify-ssl", "--exit", "--yes"],
|
# Configure the mock to avoid the TypeError
|
||||||
input=DummyInput(),
|
mock_model.return_value.info = {}
|
||||||
output=DummyOutput(),
|
mock_model.return_value.validate_environment.return_value = {"missing_keys": [], "keys_in_environment": []}
|
||||||
)
|
|
||||||
|
with patch("aider.llm.litellm._lazy_module", mock_module):
|
||||||
# Verify model_info_manager.set_verify_ssl was called with False
|
# Run main with --no-verify-ssl flag
|
||||||
mock_set_verify_ssl.assert_called_once_with(False)
|
main(
|
||||||
|
["--no-verify-ssl", "--exit", "--yes"],
|
||||||
# Verify httpx clients were created with verify=False
|
input=DummyInput(),
|
||||||
mock_client.assert_called_once_with(verify=False)
|
output=DummyOutput(),
|
||||||
mock_async_client.assert_called_once_with(verify=False)
|
)
|
||||||
|
|
||||||
# Verify SSL_VERIFY environment variable was set to empty string
|
# Verify model_info_manager.set_verify_ssl was called with False
|
||||||
self.assertEqual(os.environ.get("SSL_VERIFY"), "")
|
mock_set_verify_ssl.assert_called_once_with(False)
|
||||||
|
|
||||||
|
# Verify httpx clients were created with verify=False
|
||||||
|
mock_client.assert_called_once_with(verify=False)
|
||||||
|
mock_async_client.assert_called_once_with(verify=False)
|
||||||
|
|
||||||
|
# Verify SSL_VERIFY environment variable was set to empty string
|
||||||
|
self.assertEqual(os.environ.get("SSL_VERIFY"), "")
|
||||||
|
|
||||||
@patch("aider.models.model_info_manager.set_verify_ssl")
|
@patch("aider.models.model_info_manager.set_verify_ssl")
|
||||||
def test_default_ssl_verification(self, mock_set_verify_ssl):
|
def test_default_ssl_verification(self, mock_set_verify_ssl):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue