-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d49cd5b
commit 80fe6ae
Showing
7 changed files
with
171 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from dem.core.platform import Platform | ||
from dem.cli.console import stderr | ||
|
||
def execute(platform: Platform, dev_env_name: str, task_name: str, command: str) -> None: | ||
""" Add a task to a Development Environment. | ||
Args: | ||
platform -- the Platform | ||
dev_env_name -- the Development Environment name | ||
task_name -- the task name | ||
command -- the command | ||
""" | ||
dev_env = platform.get_dev_env_by_name(dev_env_name) | ||
if dev_env is None: | ||
stderr.print(f"[red]Error: Development Environment '{dev_env_name}' not found![/]") | ||
return | ||
dev_env.add_task(task_name, command) | ||
platform.flush_dev_env_properties() |
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
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,51 @@ | ||
"""Unit tests for the add-task CLI command.""" | ||
# tests/cli/test_add_task_cmd.py | ||
|
||
# Unit under test: | ||
import dem.cli.main as main | ||
import dem.cli.command.add_task_cmd as add_task_cmd | ||
|
||
# Test framework | ||
from typer.testing import CliRunner | ||
from unittest.mock import patch, MagicMock, call | ||
|
||
## Global test variables | ||
|
||
# In order to test stdout and stderr separately, the stderr can't be mixed into | ||
# the stdout. | ||
runner = CliRunner(mix_stderr=False) | ||
|
||
def test_add_task_cmd() -> None: | ||
# Setup | ||
mock_platform = MagicMock() | ||
main.platform = mock_platform | ||
|
||
mock_dev_env = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = mock_dev_env | ||
|
||
# Run | ||
result = runner.invoke(main.typer_cli, ["add-task", "my-dev-env", "my-task", "my-command"]) | ||
|
||
# Check | ||
assert result.exit_code == 0 | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with("my-dev-env") | ||
mock_dev_env.add_task.assert_called_once_with("my-task", "my-command") | ||
mock_platform.flush_dev_env_properties.assert_called_once() | ||
|
||
@patch("dem.cli.command.add_task_cmd.stderr.print") | ||
def test_execute_dev_env_not_found(mock_stderr_print: MagicMock) -> None: | ||
# Setup | ||
mock_platform = MagicMock() | ||
mock_platform.get_dev_env_by_name.return_value = None | ||
|
||
test_dev_env_name = "my-dev-env" | ||
test_task_name = "my-task" | ||
test_command = "my-command" | ||
|
||
# Run | ||
add_task_cmd.execute(mock_platform, test_dev_env_name, test_task_name, test_command) | ||
|
||
# Check | ||
mock_platform.get_dev_env_by_name.assert_called_once_with(test_dev_env_name) | ||
mock_stderr_print.assert_called_once_with(f"[red]Error: Development Environment '{test_dev_env_name}' not found![/]") |
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