more timeouts

This commit is contained in:
Brandon Hancock
2025-01-02 11:08:51 -05:00
parent e7696f9b07
commit ab93fdd348
9 changed files with 378 additions and 185 deletions

View File

@@ -1,6 +1,7 @@
import unittest
from unittest.mock import MagicMock, patch
import pytest
import requests
from crewai.cli.authentication.main import AuthenticationCommand
@@ -10,6 +11,7 @@ class TestAuthenticationCommand(unittest.TestCase):
def setUp(self):
self.auth_command = AuthenticationCommand()
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.main.requests.post")
def test_get_device_code(self, mock_post):
mock_response = MagicMock()
@@ -30,6 +32,7 @@ class TestAuthenticationCommand(unittest.TestCase):
)
self.assertEqual(device_code_data["interval"], 5)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.main.console.print")
@patch("crewai.cli.authentication.main.webbrowser.open")
def test_display_auth_instructions(self, mock_open, mock_print):
@@ -44,6 +47,7 @@ class TestAuthenticationCommand(unittest.TestCase):
mock_print.assert_any_call("2. Enter the following code: ", "ABCDEF")
mock_open.assert_called_once_with("https://example.com")
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.main.ToolCommand")
@patch("crewai.cli.authentication.main.requests.post")
@patch("crewai.cli.authentication.main.validate_token")
@@ -69,6 +73,7 @@ class TestAuthenticationCommand(unittest.TestCase):
"\n[bold green]Welcome to CrewAI Enterprise![/bold green]\n"
)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.main.requests.post")
@patch("crewai.cli.authentication.main.console.print")
def test_poll_for_token_error(self, mock_print, mock_post):
@@ -85,6 +90,7 @@ class TestAuthenticationCommand(unittest.TestCase):
mock_print.assert_not_called()
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.main.requests.post")
@patch("crewai.cli.authentication.main.console.print")
def test_poll_for_token_timeout(self, mock_print, mock_post):

View File

@@ -3,12 +3,14 @@ import unittest
from datetime import datetime, timedelta
from unittest.mock import MagicMock, patch
import pytest
from cryptography.fernet import Fernet
from crewai.cli.authentication.utils import TokenManager, validate_token
class TestValidateToken(unittest.TestCase):
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.AsymmetricSignatureVerifier")
@patch("crewai.cli.authentication.utils.TokenVerifier")
def test_validate_token(self, mock_token_verifier, mock_asymmetric_verifier):
@@ -32,6 +34,7 @@ class TestTokenManager(unittest.TestCase):
def setUp(self):
self.token_manager = TokenManager()
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.read_secure_file")
@patch("crewai.cli.authentication.utils.TokenManager.save_secure_file")
@patch("crewai.cli.authentication.utils.TokenManager._get_or_create_key")
@@ -44,6 +47,7 @@ class TestTokenManager(unittest.TestCase):
self.assertEqual(result, mock_key)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.Fernet.generate_key")
@patch("crewai.cli.authentication.utils.TokenManager.read_secure_file")
@patch("crewai.cli.authentication.utils.TokenManager.save_secure_file")
@@ -59,6 +63,7 @@ class TestTokenManager(unittest.TestCase):
mock_generate.assert_called_once()
mock_save.assert_called_once_with("secret.key", mock_key)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.save_secure_file")
def test_save_tokens(self, mock_save):
access_token = "test_token"
@@ -79,6 +84,7 @@ class TestTokenManager(unittest.TestCase):
delta=timedelta(seconds=1),
)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.read_secure_file")
def test_get_token_valid(self, mock_read):
access_token = "test_token"
@@ -91,6 +97,7 @@ class TestTokenManager(unittest.TestCase):
self.assertEqual(result, access_token)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.read_secure_file")
def test_get_token_expired(self, mock_read):
access_token = "test_token"
@@ -103,6 +110,7 @@ class TestTokenManager(unittest.TestCase):
self.assertIsNone(result)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.get_secure_storage_path")
@patch("builtins.open", new_callable=unittest.mock.mock_open)
@patch("crewai.cli.authentication.utils.os.chmod")
@@ -119,6 +127,7 @@ class TestTokenManager(unittest.TestCase):
mock_open().write.assert_called_once_with(content)
mock_chmod.assert_called_once_with(mock_path.__truediv__.return_value, 0o600)
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.get_secure_storage_path")
@patch(
"builtins.open", new_callable=unittest.mock.mock_open, read_data=b"test_content"
@@ -135,6 +144,7 @@ class TestTokenManager(unittest.TestCase):
mock_path.__truediv__.assert_called_once_with(filename)
mock_open.assert_called_once_with(mock_path.__truediv__.return_value, "rb")
@pytest.mark.timeout(60)
@patch("crewai.cli.authentication.utils.TokenManager.get_secure_storage_path")
def test_read_secure_file_not_exists(self, mock_get_path):
mock_path = MagicMock()