From 4726951ace1282386e10f46da237b3337fb16f5c Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Wed, 29 Jan 2025 14:29:29 +0530 Subject: [PATCH] Added new checks command to cci --- cumulusci/cli/cci.py | 2 + cumulusci/cli/checks.py | 30 ++++++++++++++ cumulusci/cli/tests/test_checks.py | 63 ++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 cumulusci/cli/checks.py create mode 100644 cumulusci/cli/tests/test_checks.py diff --git a/cumulusci/cli/cci.py b/cumulusci/cli/cci.py index adc50c49df..ada12b8503 100644 --- a/cumulusci/cli/cci.py +++ b/cumulusci/cli/cci.py @@ -18,6 +18,7 @@ from cumulusci.utils.http.requests_utils import init_requests_trust from cumulusci.utils.logging import tee_stdout_stderr +from .checks import checks from .error import error from .flow import flow from .logger import get_tempfile_logger, init_logger @@ -242,3 +243,4 @@ def shell(runtime, script=None, python=None): cli.add_command(flow) cli.add_command(plan) cli.add_command(robot) +cli.add_command(checks) diff --git a/cumulusci/cli/checks.py b/cumulusci/cli/checks.py new file mode 100644 index 0000000000..11a0e9424d --- /dev/null +++ b/cumulusci/cli/checks.py @@ -0,0 +1,30 @@ +import click + +from .runtime import pass_runtime + + +@click.group("checks", help="Commands for running preflight checks for a plan") +def checks(): + pass + + +@checks.command(name="info", help="Displays preflight checks for a plan") +@click.argument("plan_name") +@pass_runtime(require_project=True) +def checks_info(runtime, plan_name): + click.echo("This plan has the following preflight checks: ") + + +@checks.command(name="run", help="Runs checks under a plan") +@click.argument("plan_name") +@click.option( + "--org", + help="Specify the target org. By default, runs against the current default org", +) +@pass_runtime(require_keychain=True, require_project=True) +def checks_run(runtime, plan_name, org): + + # Get necessary configs + org, org_config = runtime.get_org(org) + m = "Running checks for the plan " + plan_name + click.echo(m) diff --git a/cumulusci/cli/tests/test_checks.py b/cumulusci/cli/tests/test_checks.py new file mode 100644 index 0000000000..0d11991b5d --- /dev/null +++ b/cumulusci/cli/tests/test_checks.py @@ -0,0 +1,63 @@ +from unittest import mock + +from cumulusci.cli.runtime import CliRuntime + +from .. import checks +from .utils import run_click_command + + +@mock.patch("click.echo") +def test_flow_info(echo): + + runtime = CliRuntime( + config={ + "flows": { + "test": { + "steps": { + 1: { + "task": "test_task", + "options": {"option_name": "option_value"}, + } + } + } + }, + "tasks": { + "test_task": { + "class_path": "cumulusci.cli.tests.test_flow.DummyTask", + "description": "Test Task", + } + }, + }, + load_keychain=False, + ) + + run_click_command(checks.checks_info, runtime=runtime, plan_name="test") + + echo.assert_called_with("This plan has the following preflight checks: ") + + +@mock.patch("click.echo") +def test_checks_run(echo): + org_config = mock.Mock(scratch=True, config={}) + runtime = CliRuntime( + config={ + "flows": {"test": {"steps": {1: {"task": "test_task"}}}}, + "tasks": { + "test_task": { + "class_path": "cumulusci.cli.tests.test_flow.DummyTask", + "description": "Test Task", + } + }, + }, + load_keychain=False, + ) + runtime.get_org = mock.Mock(return_value=("test", org_config)) + + run_click_command( + checks.checks_run, + runtime=runtime, + plan_name="test", + org="test", + ) + + echo.assert_called_with("Running checks for the plan test")