diff --git a/cumulusci/cumulusci.yml b/cumulusci/cumulusci.yml index bcdd32f69e..9b13e81741 100644 --- a/cumulusci/cumulusci.yml +++ b/cumulusci/cumulusci.yml @@ -125,6 +125,9 @@ tasks: settings_type: EnhancedNotesSettings settings_field: IsEnhancedNotesEnabled value: True + retrieve_tasks: + description: Retrieves the tasks under the particular category or group + class_path: cumulusci.tasks.preflight.retrieve_tasks.RetrieveTasks custom_settings_value_wait: description: Waits for a specific field value on the specified custom settings object and field class_path: cumulusci.tasks.salesforce.custom_settings_wait.CustomSettingValueWait diff --git a/cumulusci/tasks/preflight/retrieve_tasks.py b/cumulusci/tasks/preflight/retrieve_tasks.py new file mode 100644 index 0000000000..b868c97e9a --- /dev/null +++ b/cumulusci/tasks/preflight/retrieve_tasks.py @@ -0,0 +1,30 @@ +from typing import List + +from cumulusci.cli.runtime import CliRuntime +from cumulusci.cli.utils import group_items +from cumulusci.core.exceptions import CumulusCIException +from cumulusci.core.tasks import BaseTask + + +class RetrieveTasks(BaseTask): + task_options = { + "group_name": { + "description": "Name of the category or Group", + "required": True, + }, + } + + def _run_task(self): + runtime = CliRuntime(load_keychain=True) + tasks = runtime.get_available_tasks() + task_groups = group_items(tasks) + task_groups = task_groups[self.options["group_name"]] + self.return_values: List[str] = [] + for task_name, description in task_groups: + self.return_values.append(task_name) + if self.return_values: + self.return_values.sort() + else: + raise CumulusCIException("No tasks in the specified group") + + self.logger.info(self.return_values) diff --git a/cumulusci/tasks/preflight/tests/test_retrieve_tasks.py b/cumulusci/tasks/preflight/tests/test_retrieve_tasks.py new file mode 100644 index 0000000000..50b739ab03 --- /dev/null +++ b/cumulusci/tasks/preflight/tests/test_retrieve_tasks.py @@ -0,0 +1,62 @@ +from unittest import mock + +import pytest + +from cumulusci.cli.runtime import CliRuntime +from cumulusci.core.exceptions import CumulusCIException +from cumulusci.tasks.preflight.retrieve_tasks import RetrieveTasks +from cumulusci.tasks.salesforce.tests.util import create_task + + +class TestRetrieveTasks: + @pytest.mark.parametrize( + "available_tasks, group_name, expected_output", + [ + ( + [ + { + "name": "test_task1", + "description": "Test Task", + "group": "Group", + }, + { + "name": "test_task2", + "description": "Test Task", + "group": "Group", + }, + { + "name": "test_task3", + "description": "Test Task", + "group": "Test Group", + }, + ], + "Group", + ["test_task1", "test_task2"], + ), + ( + [ + { + "name": "test_task1", + "description": "Test Task", + "group": "Group", + }, + ], + "Tests", + None, + ), + ], + ) + def test_run_task(self, available_tasks, group_name, expected_output): + task = create_task(RetrieveTasks, options={"group_name": group_name}) + + with mock.patch.object( + CliRuntime, "get_available_tasks", return_value=available_tasks + ): + if expected_output is not None: + output = task() + assert output == expected_output + else: + with pytest.raises( + CumulusCIException, match="No tasks in the specified group" + ): + task() diff --git a/cumulusci/tasks/salesforce/DescribeMetadataTypes.py b/cumulusci/tasks/salesforce/DescribeMetadataTypes.py index 49c605c37d..0b2d4f4e1e 100644 --- a/cumulusci/tasks/salesforce/DescribeMetadataTypes.py +++ b/cumulusci/tasks/salesforce/DescribeMetadataTypes.py @@ -22,5 +22,5 @@ def _get_api(self): def _run_task(self): api_object = self._get_api() - metadata_list = api_object() - self.logger.info("Metadata Types supported by org:\n" + str(metadata_list)) + self.return_values = api_object() + self.logger.info("Metadata Types supported by org:\n" + str(self.return_values))