mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Move crewai.cli.deploy.utils to crewai.cli.utils (#1350)
* Prevent double slashes when joining URLs * Move crewai.cli.deploy.utils to crewai.cli.utils This commit moves this package so it's reusable across commands.
This commit is contained in:
@@ -4,7 +4,8 @@ from unittest.mock import MagicMock, patch
|
||||
import sys
|
||||
|
||||
from crewai.cli.deploy.main import DeployCommand
|
||||
from crewai.cli.deploy.utils import parse_toml
|
||||
from crewai.cli.utils import parse_toml
|
||||
|
||||
|
||||
class TestDeployCommand(unittest.TestCase):
|
||||
@patch("crewai.cli.deploy.main.get_auth_token")
|
||||
@@ -165,9 +166,12 @@ 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')
|
||||
self.assertEqual(parsed["tool"]["poetry"]["name"], "test_project")
|
||||
|
||||
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
||||
@patch(
|
||||
"builtins.open",
|
||||
new_callable=unittest.mock.mock_open,
|
||||
read_data="""
|
||||
[tool.poetry]
|
||||
name = "test_project"
|
||||
version = "0.1.0"
|
||||
@@ -175,14 +179,19 @@ class TestDeployCommand(unittest.TestCase):
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||
""")
|
||||
""",
|
||||
)
|
||||
def test_get_project_name_python_310(self, mock_open):
|
||||
from crewai.cli.deploy.utils import get_project_name
|
||||
from crewai.cli.utils import get_project_name
|
||||
|
||||
project_name = get_project_name()
|
||||
self.assertEqual(project_name, 'test_project')
|
||||
self.assertEqual(project_name, "test_project")
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 11), "Requires Python 3.11+")
|
||||
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
||||
@patch(
|
||||
"builtins.open",
|
||||
new_callable=unittest.mock.mock_open,
|
||||
read_data="""
|
||||
[tool.poetry]
|
||||
name = "test_project"
|
||||
version = "0.1.0"
|
||||
@@ -190,13 +199,18 @@ class TestDeployCommand(unittest.TestCase):
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
crewai = { extras = ["tools"], version = ">=0.51.0,<1.0.0" }
|
||||
""")
|
||||
""",
|
||||
)
|
||||
def test_get_project_name_python_311_plus(self, mock_open):
|
||||
from crewai.cli.deploy.utils import get_project_name
|
||||
project_name = get_project_name()
|
||||
self.assertEqual(project_name, 'test_project')
|
||||
from crewai.cli.utils import get_project_name
|
||||
|
||||
@patch('builtins.open', new_callable=unittest.mock.mock_open, read_data="""
|
||||
project_name = get_project_name()
|
||||
self.assertEqual(project_name, "test_project")
|
||||
|
||||
@patch(
|
||||
"builtins.open",
|
||||
new_callable=unittest.mock.mock_open,
|
||||
read_data="""
|
||||
[[package]]
|
||||
name = "crewai"
|
||||
version = "0.51.1"
|
||||
@@ -204,16 +218,19 @@ class TestDeployCommand(unittest.TestCase):
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.10,<4.0"
|
||||
""")
|
||||
""",
|
||||
)
|
||||
def test_get_crewai_version(self, mock_open):
|
||||
from crewai.cli.deploy.utils import get_crewai_version
|
||||
version = get_crewai_version()
|
||||
self.assertEqual(version, '0.51.1')
|
||||
from crewai.cli.utils import get_crewai_version
|
||||
|
||||
@patch('builtins.open', side_effect=FileNotFoundError)
|
||||
version = get_crewai_version()
|
||||
self.assertEqual(version, "0.51.1")
|
||||
|
||||
@patch("builtins.open", side_effect=FileNotFoundError)
|
||||
def test_get_crewai_version_file_not_found(self, mock_open):
|
||||
from crewai.cli.deploy.utils import get_crewai_version
|
||||
with patch('sys.stdout', new=StringIO()) as fake_out:
|
||||
from crewai.cli.utils import get_crewai_version
|
||||
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
version = get_crewai_version()
|
||||
self.assertEqual(version, 'no-version-found')
|
||||
self.assertEqual(version, "no-version-found")
|
||||
self.assertIn("Error: poetry.lock not found.", fake_out.getvalue())
|
||||
|
||||
Reference in New Issue
Block a user