mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-14 18:48:29 +00:00
Apply automatic linting fixes to tests directory
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -15,7 +15,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
@patch("crewai.cli.command.get_auth_token")
|
||||
@patch("crewai.cli.deploy.main.get_project_name")
|
||||
@patch("crewai.cli.command.PlusAPI")
|
||||
def setUp(self, mock_plus_api, mock_get_project_name, mock_get_auth_token):
|
||||
def setUp(self, mock_plus_api, mock_get_project_name, mock_get_auth_token) -> None:
|
||||
self.mock_get_auth_token = mock_get_auth_token
|
||||
self.mock_get_project_name = mock_get_project_name
|
||||
self.mock_plus_api = mock_plus_api
|
||||
@@ -26,18 +26,18 @@ class TestDeployCommand(unittest.TestCase):
|
||||
self.deploy_command = DeployCommand()
|
||||
self.mock_client = self.deploy_command.plus_api_client
|
||||
|
||||
def test_init_success(self):
|
||||
self.assertEqual(self.deploy_command.project_name, "test_project")
|
||||
def test_init_success(self) -> None:
|
||||
assert self.deploy_command.project_name == "test_project"
|
||||
self.mock_plus_api.assert_called_once_with(api_key="test_token")
|
||||
|
||||
@patch("crewai.cli.command.get_auth_token")
|
||||
def test_init_failure(self, mock_get_auth_token):
|
||||
def test_init_failure(self, mock_get_auth_token) -> None:
|
||||
mock_get_auth_token.side_effect = Exception("Auth failed")
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
with pytest.raises(SystemExit):
|
||||
DeployCommand()
|
||||
|
||||
def test_validate_response_successful_response(self):
|
||||
def test_validate_response_successful_response(self) -> None:
|
||||
mock_response = Mock(spec=requests.Response)
|
||||
mock_response.json.return_value = {"message": "Success"}
|
||||
mock_response.status_code = 200
|
||||
@@ -47,7 +47,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
self.deploy_command._validate_response(mock_response)
|
||||
assert fake_out.getvalue() == ""
|
||||
|
||||
def test_validate_response_json_decode_error(self):
|
||||
def test_validate_response_json_decode_error(self) -> None:
|
||||
mock_response = Mock(spec=requests.Response)
|
||||
mock_response.json.side_effect = JSONDecodeError("Decode error", "", 0)
|
||||
mock_response.status_code = 500
|
||||
@@ -64,7 +64,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
assert "Status Code: 500" in output
|
||||
assert "Response:\nb'Invalid JSON'" in output
|
||||
|
||||
def test_validate_response_422_error(self):
|
||||
def test_validate_response_422_error(self) -> None:
|
||||
mock_response = Mock(spec=requests.Response)
|
||||
mock_response.json.return_value = {
|
||||
"field1": ["Error message 1"],
|
||||
@@ -84,7 +84,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
assert "Field1 Error message 1" in output
|
||||
assert "Field2 Error message 2" in output
|
||||
|
||||
def test_validate_response_other_error(self):
|
||||
def test_validate_response_other_error(self) -> None:
|
||||
mock_response = Mock(spec=requests.Response)
|
||||
mock_response.json.return_value = {"error": "Something went wrong"}
|
||||
mock_response.status_code = 500
|
||||
@@ -97,29 +97,29 @@ class TestDeployCommand(unittest.TestCase):
|
||||
assert "Request to Enterprise API failed. Details:" in output
|
||||
assert "Details:\nSomething went wrong" in output
|
||||
|
||||
def test_standard_no_param_error_message(self):
|
||||
def test_standard_no_param_error_message(self) -> None:
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command._standard_no_param_error_message()
|
||||
self.assertIn("No UUID provided", fake_out.getvalue())
|
||||
assert "No UUID provided" in fake_out.getvalue()
|
||||
|
||||
def test_display_deployment_info(self):
|
||||
def test_display_deployment_info(self) -> None:
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command._display_deployment_info(
|
||||
{"uuid": "test-uuid", "status": "deployed"}
|
||||
{"uuid": "test-uuid", "status": "deployed"},
|
||||
)
|
||||
self.assertIn("Deploying the crew...", fake_out.getvalue())
|
||||
self.assertIn("test-uuid", fake_out.getvalue())
|
||||
self.assertIn("deployed", fake_out.getvalue())
|
||||
assert "Deploying the crew..." in fake_out.getvalue()
|
||||
assert "test-uuid" in fake_out.getvalue()
|
||||
assert "deployed" in fake_out.getvalue()
|
||||
|
||||
def test_display_logs(self):
|
||||
def test_display_logs(self) -> None:
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command._display_logs(
|
||||
[{"timestamp": "2023-01-01", "level": "INFO", "message": "Test log"}]
|
||||
[{"timestamp": "2023-01-01", "level": "INFO", "message": "Test log"}],
|
||||
)
|
||||
self.assertIn("2023-01-01 - INFO: Test log", fake_out.getvalue())
|
||||
assert "2023-01-01 - INFO: Test log" in fake_out.getvalue()
|
||||
|
||||
@patch("crewai.cli.deploy.main.DeployCommand._display_deployment_info")
|
||||
def test_deploy_with_uuid(self, mock_display):
|
||||
def test_deploy_with_uuid(self, mock_display) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {"uuid": "test-uuid"}
|
||||
@@ -131,7 +131,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
mock_display.assert_called_once_with({"uuid": "test-uuid"})
|
||||
|
||||
@patch("crewai.cli.deploy.main.DeployCommand._display_deployment_info")
|
||||
def test_deploy_with_project_name(self, mock_display):
|
||||
def test_deploy_with_project_name(self, mock_display) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {"uuid": "test-uuid"}
|
||||
@@ -145,7 +145,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
@patch("crewai.cli.deploy.main.fetch_and_json_env_file")
|
||||
@patch("crewai.cli.deploy.main.git.Repository.origin_url")
|
||||
@patch("builtins.input")
|
||||
def test_create_crew(self, mock_input, mock_git_origin_url, mock_fetch_env):
|
||||
def test_create_crew(self, mock_input, mock_git_origin_url, mock_fetch_env) -> None:
|
||||
mock_fetch_env.return_value = {"ENV_VAR": "value"}
|
||||
mock_git_origin_url.return_value = "https://github.com/test/repo.git"
|
||||
mock_input.return_value = ""
|
||||
@@ -157,10 +157,10 @@ class TestDeployCommand(unittest.TestCase):
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command.create_crew()
|
||||
self.assertIn("Deployment created successfully!", fake_out.getvalue())
|
||||
self.assertIn("new-uuid", fake_out.getvalue())
|
||||
assert "Deployment created successfully!" in fake_out.getvalue()
|
||||
assert "new-uuid" in fake_out.getvalue()
|
||||
|
||||
def test_list_crews(self):
|
||||
def test_list_crews(self) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = [
|
||||
@@ -171,10 +171,10 @@ class TestDeployCommand(unittest.TestCase):
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command.list_crews()
|
||||
self.assertIn("Crew1 (uuid1) active", fake_out.getvalue())
|
||||
self.assertIn("Crew2 (uuid2) inactive", fake_out.getvalue())
|
||||
assert "Crew1 (uuid1) active" in fake_out.getvalue()
|
||||
assert "Crew2 (uuid2) inactive" in fake_out.getvalue()
|
||||
|
||||
def test_get_crew_status(self):
|
||||
def test_get_crew_status(self) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = {"name": "InternalCrew", "status": "active"}
|
||||
@@ -182,10 +182,10 @@ class TestDeployCommand(unittest.TestCase):
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command.get_crew_status()
|
||||
self.assertIn("InternalCrew", fake_out.getvalue())
|
||||
self.assertIn("active", fake_out.getvalue())
|
||||
assert "InternalCrew" in fake_out.getvalue()
|
||||
assert "active" in fake_out.getvalue()
|
||||
|
||||
def test_get_crew_logs(self):
|
||||
def test_get_crew_logs(self) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 200
|
||||
mock_response.json.return_value = [
|
||||
@@ -196,22 +196,20 @@ class TestDeployCommand(unittest.TestCase):
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command.get_crew_logs(None)
|
||||
self.assertIn("2023-01-01 - INFO: Log1", fake_out.getvalue())
|
||||
self.assertIn("2023-01-02 - ERROR: Log2", fake_out.getvalue())
|
||||
assert "2023-01-01 - INFO: Log1" in fake_out.getvalue()
|
||||
assert "2023-01-02 - ERROR: Log2" in fake_out.getvalue()
|
||||
|
||||
def test_remove_crew(self):
|
||||
def test_remove_crew(self) -> None:
|
||||
mock_response = MagicMock()
|
||||
mock_response.status_code = 204
|
||||
self.mock_client.delete_crew_by_name.return_value = mock_response
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
self.deploy_command.remove_crew(None)
|
||||
self.assertIn(
|
||||
"Crew 'test_project' removed successfully", fake_out.getvalue()
|
||||
)
|
||||
assert "Crew 'test_project' removed successfully" in fake_out.getvalue()
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 11), "Requires Python 3.11+")
|
||||
def test_parse_toml_python_311_plus(self):
|
||||
def test_parse_toml_python_311_plus(self) -> None:
|
||||
toml_content = """
|
||||
[tool.poetry]
|
||||
name = "test_project"
|
||||
@@ -222,7 +220,7 @@ class TestDeployCommand(unittest.TestCase):
|
||||
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||
"""
|
||||
parsed = parse_toml(toml_content)
|
||||
self.assertEqual(parsed["tool"]["poetry"]["name"], "test_project")
|
||||
assert parsed["tool"]["poetry"]["name"] == "test_project"
|
||||
|
||||
@patch(
|
||||
"builtins.open",
|
||||
@@ -235,12 +233,11 @@ class TestDeployCommand(unittest.TestCase):
|
||||
dependencies = ["crewai"]
|
||||
""",
|
||||
)
|
||||
def test_get_project_name_python_310(self, mock_open):
|
||||
def test_get_project_name_python_310(self, mock_open) -> None:
|
||||
from crewai.cli.utils import get_project_name
|
||||
|
||||
project_name = get_project_name()
|
||||
print("project_name", project_name)
|
||||
self.assertEqual(project_name, "test_project")
|
||||
assert project_name == "test_project"
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 11), "Requires Python 3.11+")
|
||||
@patch(
|
||||
@@ -254,13 +251,13 @@ class TestDeployCommand(unittest.TestCase):
|
||||
dependencies = ["crewai"]
|
||||
""",
|
||||
)
|
||||
def test_get_project_name_python_311_plus(self, mock_open):
|
||||
def test_get_project_name_python_311_plus(self, mock_open) -> None:
|
||||
from crewai.cli.utils import get_project_name
|
||||
|
||||
project_name = get_project_name()
|
||||
self.assertEqual(project_name, "test_project")
|
||||
assert project_name == "test_project"
|
||||
|
||||
def test_get_crewai_version(self):
|
||||
def test_get_crewai_version(self) -> None:
|
||||
from crewai.cli.version import get_crewai_version
|
||||
|
||||
assert isinstance(get_crewai_version(), str)
|
||||
|
||||
Reference in New Issue
Block a user