Skip to content

Commit

Permalink
The create command fixed.
Browse files Browse the repository at this point in the history
An input string can't contain any whitespaces.
  • Loading branch information
janosmurai committed Mar 7, 2024
1 parent c12e821 commit 4d08f3f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 54 deletions.
23 changes: 5 additions & 18 deletions dem/cli/command/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ def create_new_dev_env(platform: Platform, new_dev_env_descriptor: dict) -> DevE
new_dev_env = DevEnv(new_dev_env_descriptor)
platform.local_dev_envs.append(new_dev_env)

return new_dev_env

def create_dev_env(platform: Platform, dev_env_name: str) -> DevEnv:
if ' ' in dev_env_name:
stderr.print("The name of the Development Environment cannot contain whitespace characters!")
Expand All @@ -163,22 +161,11 @@ def create_dev_env(platform: Platform, dev_env_name: str) -> DevEnv:

if dev_env_original is not None:
overwrite_existing_dev_env(dev_env_original, new_dev_env_descriptor)
new_dev_env = dev_env_original
else:
new_dev_env = create_new_dev_env(platform, new_dev_env_descriptor)

return new_dev_env
create_new_dev_env(platform, new_dev_env_descriptor)

def execute(platform: Platform, dev_env_name: str) -> None:
dev_env = create_dev_env(platform, dev_env_name)

# Validate the Dev Env creation
image_statuses = dev_env.check_image_availability(platform.tool_images,
update_tool_image_store=True)

if (ToolImages.NOT_AVAILABLE in image_statuses) or (ToolImages.REGISTRY_ONLY in image_statuses):
stderr.print("The installation failed.")
else:
platform.flush_descriptors()
stdout.print(f"The [green]{dev_env_name}[/] Development Environment has been created!")
stdout.print("Run [italic]dem install[/] to install it.")
create_dev_env(platform, dev_env_name)
platform.flush_descriptors()
stdout.print(f"The [green]{dev_env_name}[/] Development Environment has been created!")
stdout.print("Run [italic]dem install[/] to install it.")
2 changes: 1 addition & 1 deletion dem/cli/command/uninstall_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def execute(platform: Platform, dev_env_name: str) -> None:
except PlatformError as e:
stderr.print(f"[red]Error: {str(e)}[/]")
else:
stdout.print(f"[green]Successfully deleted the {dev_env_name}![/]")
stdout.print(f"[green]Successfully uninstalled the {dev_env_name}![/]")
5 changes: 0 additions & 5 deletions dem/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,5 @@ def main(
Development Environment Manager (dem)
Manage your containerized Development Environments with ease.
❗ Always put the input text into double quotation marks (""), if it contains whitespaces.
"""
return
4 changes: 0 additions & 4 deletions docs/commands.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
!!! warning

Always put the input text into double quotation marks ("") if it contains whitespaces.

## **`dem list [OPTIONS]`**

List the Development Environments installed locally or available in the catalog.
Expand Down
28 changes: 3 additions & 25 deletions tests/cli/test_create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ def test_create_new_dev_env(mock_DevEnvLocal):
mock_new_dev_env_descriptor = MagicMock()

# Run unit under test
actual_new_dev_env = create_cmd.create_new_dev_env(mock_platform,
mock_new_dev_env_descriptor)
create_cmd.create_new_dev_env(mock_platform, mock_new_dev_env_descriptor)

# Check expectations
assert actual_new_dev_env == mock_new_dev_env
mock_DevEnvLocal.assert_called_once_with(mock_new_dev_env_descriptor)
mock_platform.local_dev_envs.append.assert_called_once_with(mock_new_dev_env)

Expand All @@ -95,11 +93,9 @@ def test_create_dev_env_new(mock_get_tool_image_list, mock_get_dev_env_descripto
expected_dev_env_name = "test_dev_env"

# Run unit under test
actual_dev_env = create_cmd.create_dev_env(mock_dev_env_local_setup, expected_dev_env_name)
create_cmd.create_dev_env(mock_dev_env_local_setup, expected_dev_env_name)

# Check expectations
assert actual_dev_env == mock_new_dev_env

mock_dev_env_local_setup.get_dev_env_by_name.assert_called_once_with(expected_dev_env_name)
mock_get_tool_image_list.assert_called_once_with(mock_dev_env_local_setup.tool_images)
mock_get_dev_env_descriptor_from_user.assert_called_once_with(expected_dev_env_name, mock_tool_images)
Expand Down Expand Up @@ -130,11 +126,9 @@ def test_create_dev_env_overwrite(mock_confirm, mock_get_tool_image_list,
expected_dev_env_name = "test_dev_env"

# Run unit under test
actual_dev_env = create_cmd.create_dev_env(mock_dev_env_local_setup, expected_dev_env_name)
create_cmd.create_dev_env(mock_dev_env_local_setup, expected_dev_env_name)

# Check expectations
assert actual_dev_env == mock_dev_env_original

mock_dev_env_local_setup.get_dev_env_by_name.assert_called_once_with(expected_dev_env_name)
mock_confirm.assert_called_once_with("The input name is already used by a Development Environment. Overwrite it?",
abort=True)
Expand Down Expand Up @@ -173,11 +167,6 @@ def test_execute(mock_create_dev_env, mock_stdout_print):

mock_dev_env = MagicMock()
expected_dev_env_name = "test_dev_env"
mock_dev_env.name = expected_dev_env_name
mock_create_dev_env.return_value = mock_dev_env

image_statuses = [ToolImages.LOCAL_AND_REGISTRY, ToolImages.LOCAL_ONLY] * 2
mock_dev_env.check_image_availability.return_value = image_statuses

# Run unit under test
runner_result = runner.invoke(main.typer_cli, ["create", expected_dev_env_name], color=True)
Expand All @@ -186,8 +175,6 @@ def test_execute(mock_create_dev_env, mock_stdout_print):
assert 0 == runner_result.exit_code

mock_create_dev_env.assert_called_once_with(mock_platform, expected_dev_env_name)
mock_dev_env.check_image_availability.assert_called_once_with(mock_platform.tool_images,
update_tool_image_store=True)
mock_platform.flush_descriptors.assert_called_once()
mock_stdout_print.assert_has_calls([
call(f"The [green]{expected_dev_env_name}[/] Development Environment has been created!"),
Expand All @@ -201,12 +188,6 @@ def test_execute_failure(mock_create_dev_env, mock_stderr_print):
mock_platform = MagicMock()
main.platform = mock_platform

mock_dev_env = MagicMock()
mock_create_dev_env.return_value = mock_dev_env

image_statuses = [ToolImages.NOT_AVAILABLE] * 5
mock_dev_env.check_image_availability.return_value = image_statuses

expected_dev_env_name = "test_dev_env"

# Run unit under test
Expand All @@ -216,9 +197,6 @@ def test_execute_failure(mock_create_dev_env, mock_stderr_print):
assert 0 == runner_result.exit_code

mock_create_dev_env.assert_called_once_with(mock_platform, expected_dev_env_name)
mock_dev_env.check_image_availability.assert_called_once_with(mock_platform.tool_images,
update_tool_image_store=True)
mock_stderr_print.assert_called_once_with("The installation failed.")

@patch("dem.cli.command.create_cmd.stderr.print")
def test_create_dev_env_with_whitespace(mock_stderr_print):
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_uninstall_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_uninstall_dev_env_valid_name(mock_stdout_print):

mock_platform.get_dev_env_by_name.assert_called_once_with(fake_dev_env_to_uninstall.name )
mock_platform.uninstall_dev_env.assert_called_once_with(fake_dev_env_to_uninstall)
mock_stdout_print.assert_called_once_with(f"[green]Successfully deleted the {fake_dev_env_to_uninstall.name}![/]")
mock_stdout_print.assert_called_once_with(f"[green]Successfully uninstalled the {fake_dev_env_to_uninstall.name}![/]")

@patch("dem.cli.command.uninstall_cmd.stderr.print")
def test_uninstall_dev_env_valid_name_not_installed(mock_stderr_print):
Expand Down

0 comments on commit 4d08f3f

Please sign in to comment.