-
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
80fe6ae
commit 7b0633c
Showing
10 changed files
with
252 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,26 @@ | ||
"""del-task CLI command implementation.""" | ||
# dem/cli/command/del_task_cmd.py | ||
|
||
from dem.core.platform import Platform | ||
from dem.cli.console import stderr | ||
|
||
def execute(platform: Platform, dev_env_name: str, task_name: str) -> None: | ||
""" Delete a task from a Development Environment. | ||
Args: | ||
platform -- the Platform | ||
dev_env_name -- the Development Environment name | ||
task_name -- the task name | ||
""" | ||
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 | ||
|
||
try: | ||
dev_env.del_task(task_name) | ||
except KeyError as e: | ||
stderr.print(f"[red] Error: {str(e)}[/]") | ||
return | ||
|
||
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
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,71 @@ | ||
"""Unit tests for the del-task CLI command.""" | ||
# tests/cli/test_del_task_cmd.py | ||
|
||
# Unit under test: | ||
import dem.cli.main as main | ||
import dem.cli.command.del_task_cmd as del_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_del_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, ["del-task", "my-dev-env", "my-task"]) | ||
|
||
# Check | ||
assert result.exit_code == 0 | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with("my-dev-env") | ||
mock_dev_env.del_task.assert_called_once_with("my-task") | ||
mock_platform.flush_dev_env_properties.assert_called_once() | ||
|
||
@patch("dem.cli.command.del_task_cmd.stderr") | ||
def test_del_task_cmd_dev_env_not_found(mock_stderr: MagicMock) -> None: | ||
# Setup | ||
mock_platform = MagicMock() | ||
main.platform = mock_platform | ||
|
||
mock_platform.get_dev_env_by_name.return_value = None | ||
|
||
# Run | ||
result = runner.invoke(main.typer_cli, ["del-task", "my-dev-env", "my-task"]) | ||
|
||
# Check | ||
assert result.exit_code == 0 | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with("my-dev-env") | ||
mock_stderr.print.assert_called_once_with("[red]Error: Development Environment 'my-dev-env' not found![/]") | ||
|
||
@patch("dem.cli.command.del_task_cmd.stderr") | ||
def test_del_task_cmd_task_not_found(mock_stderr: MagicMock) -> 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 | ||
mock_dev_env.del_task.side_effect = KeyError("Task [bold]my-task[/] not found.") | ||
|
||
# Run | ||
result = runner.invoke(main.typer_cli, ["del-task", "my-dev-env", "my-task"]) | ||
|
||
# Check | ||
assert result.exit_code == 0 | ||
|
||
mock_platform.get_dev_env_by_name.assert_called_once_with("my-dev-env") | ||
mock_dev_env.del_task.assert_called_once_with("my-task") | ||
mock_stderr.print.assert_called_once_with("[red] Error: \'Task [bold]my-task[/] 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