Skip to content

Commit

Permalink
feat: add unit tests for cl
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbyte committed Aug 22, 2024
1 parent 0c3c4fb commit 27f2682
Showing 1 changed file with 116 additions and 2 deletions.
118 changes: 116 additions & 2 deletions tests/cli/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

import pytest
from click.testing import CliRunner

from crewai.cli.cli import reset_memories, test, train, version
from crewai.cli.cli import (
deploy_create,
deploy_list,
deploy_logs,
deploy_push,
deploy_remove,
deply_status,
reset_memories,
signup,
test,
train,
version,
)


@pytest.fixture
Expand Down Expand Up @@ -163,3 +174,106 @@ def test_test_invalid_string_iterations(evaluate_crew, runner):
"Usage: test [OPTIONS]\nTry 'test --help' for help.\n\nError: Invalid value for '-n' / '--n_iterations': 'invalid' is not a valid integer.\n"
in result.output
)


@mock.patch("crewai.cli.cli.AuthenticationCommand")
def test_signup(command, runner):
mock_auth = command.return_value
result = runner.invoke(signup)

assert result.exit_code == 0
mock_auth.signup.assert_called_once()


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_create(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deploy_create)

assert result.exit_code == 0
mock_deploy.create_crew.assert_called_once()


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_list(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deploy_list)

assert result.exit_code == 0
mock_deploy.list_crews.assert_called_once()


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_push(command, runner):
mock_deploy = command.return_value
uuid = "test-uuid"
result = runner.invoke(deploy_push, ["-u", uuid])

assert result.exit_code == 0
mock_deploy.deploy.assert_called_once_with(uuid=uuid)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_push_no_uuid(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deploy_push)

assert result.exit_code == 0
mock_deploy.deploy.assert_called_once_with(uuid=None)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_status(command, runner):
mock_deploy = command.return_value
uuid = "test-uuid"
result = runner.invoke(deply_status, ["-u", uuid])

assert result.exit_code == 0
mock_deploy.get_crew_status.assert_called_once_with(uuid=uuid)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_status_no_uuid(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deply_status)

assert result.exit_code == 0
mock_deploy.get_crew_status.assert_called_once_with(uuid=None)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_logs(command, runner):
mock_deploy = command.return_value
uuid = "test-uuid"
result = runner.invoke(deploy_logs, ["-u", uuid])

assert result.exit_code == 0
mock_deploy.get_crew_logs.assert_called_once_with(uuid=uuid)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_logs_no_uuid(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deploy_logs)

assert result.exit_code == 0
mock_deploy.get_crew_logs.assert_called_once_with(uuid=None)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_remove(command, runner):
mock_deploy = command.return_value
uuid = "test-uuid"
result = runner.invoke(deploy_remove, ["-u", uuid])

assert result.exit_code == 0
mock_deploy.remove_crew.assert_called_once_with(uuid=uuid)


@mock.patch("crewai.cli.cli.DeployCommand")
def test_deploy_remove_no_uuid(command, runner):
mock_deploy = command.return_value
result = runner.invoke(deploy_remove)

assert result.exit_code == 0
mock_deploy.remove_crew.assert_called_once_with(uuid=None)

0 comments on commit 27f2682

Please sign in to comment.