-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3723 from SFDO-Tooling/feature/retrieve_tasks
Retrieve pre-flight checks
- Loading branch information
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters