Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
bhancockio committed Oct 29, 2024
1 parent 0e36d35 commit c22e191
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/crewai/cli/add_crew_to_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from .create_crew import copy_template
from crewai.cli.utils import copy_template


def add_crew_to_flow(crew_name: str) -> None:
Expand All @@ -25,10 +25,8 @@ def add_crew_to_flow(crew_name: str) -> None:
# Create the crew within the flow's crews directory
create_embedded_crew(crew_name, parent_folder=crews_folder)

click.secho(
click.echo(
f"Crew {crew_name} added to the current flow successfully!",
fg="green",
bold=True,
)


Expand Down
41 changes: 14 additions & 27 deletions tests/cli/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,33 +282,20 @@ def test_deploy_remove_no_uuid(command, runner):
mock_deploy.remove_crew.assert_called_once_with(uuid=None)


@mock.patch("crewai.cli.add_crew_to_flow.create_crew")
def test_add_crew_to_flow(create_crew_mock, runner):
# Simulate being in the root of a flow project
with mock.patch("pathlib.Path.cwd") as mock_cwd:
mock_cwd.return_value = Path("/path/to/flow_project")
with mock.patch("pathlib.Path.exists") as mock_exists:

def exists_side_effect(self):
if self == Path("/path/to/flow_project/pyproject.toml"):
return True
if self == Path("/path/to/flow_project/src/flow_project/crews"):
return True
return False

mock_exists.side_effect = exists_side_effect

result = runner.invoke(flow_add_crew, ["new_crew"])

create_crew_mock.assert_called_once_with(
"new_crew",
parent_folder=Path("/path/to/flow_project/src/flow_project/crews"),
)
assert result.exit_code == 0
assert (
"Crew new_crew added to the current flow successfully!"
in result.exception
)
@mock.patch("crewai.cli.add_crew_to_flow.create_embedded_crew")
def test_flow_add_crew(mock_create_embedded_crew, runner):
crew_name = "new_crew"
result = runner.invoke(flow_add_crew, [crew_name])

assert result.exit_code == 0
assert f"Adding crew {crew_name} to the flow" in result.output

# Verify that create_embedded_crew was called with the correct arguments
mock_create_embedded_crew.assert_called_once()
call_args, call_kwargs = mock_create_embedded_crew.call_args
assert call_args[0] == crew_name
assert "parent_folder" in call_kwargs
assert isinstance(call_kwargs["parent_folder"], Path)


def test_add_crew_to_flow_not_in_root(runner):
Expand Down

0 comments on commit c22e191

Please sign in to comment.