Skip to content

Commit

Permalink
Merge pull request #3723 from SFDO-Tooling/feature/retrieve_tasks
Browse files Browse the repository at this point in the history
Retrieve pre-flight checks
  • Loading branch information
vsbharath authored Dec 19, 2023
2 parents 8cc6f49 + 70905af commit d0a7d71
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cumulusci/cumulusci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions cumulusci/tasks/preflight/retrieve_tasks.py
Original file line number Diff line number Diff line change
@@ -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)
62 changes: 62 additions & 0 deletions cumulusci/tasks/preflight/tests/test_retrieve_tasks.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions cumulusci/tasks/salesforce/DescribeMetadataTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit d0a7d71

Please sign in to comment.