@@ -117,25 +117,6 @@ def test_handle_user_confirm_cancel():
117
117
with pytest .raises (typer .Abort ):
118
118
modify_cmd .handle_user_confirm ("cancel" , MagicMock (), MagicMock ())
119
119
120
- def test_execute_invalid_name ():
121
- # Test setup
122
- mock_platform = MagicMock ()
123
- main .platform = mock_platform
124
- mock_platform .get_dev_env_by_name .return_value = None
125
- test_dev_env_name = "not existing env"
126
-
127
- # Run unit under test
128
- runner_result = runner .invoke (main .typer_cli , ["modify" , test_dev_env_name ], color = True )
129
-
130
- # Check expectations
131
- assert 0 == runner_result .exit_code
132
-
133
- mock_platform .get_dev_env_by_name .assert_called_once_with (test_dev_env_name )
134
-
135
- console = Console (file = io .StringIO ())
136
- console .print ("[red]The Development Environment doesn't exist." )
137
- assert console .file .getvalue () == runner_result .stderr
138
-
139
120
@patch ("dem.cli.command.modify_cmd.handle_user_confirm" )
140
121
@patch ("dem.cli.command.modify_cmd.get_confirm_from_user" )
141
122
@patch ("dem.cli.command.modify_cmd.get_modifications_from_user" )
@@ -276,6 +257,25 @@ def test_modify_single_tool_no_type(mock_stderr_print: MagicMock) -> None:
276
257
277
258
mock_stderr_print .assert_called_once_with ("[red]Error: The tool type and the tool image must be set together.[/]" )
278
259
260
+ def test_execute_invalid_name ():
261
+ # Test setup
262
+ mock_platform = MagicMock ()
263
+ main .platform = mock_platform
264
+ mock_platform .get_dev_env_by_name .return_value = None
265
+ test_dev_env_name = "not existing env"
266
+
267
+ # Run unit under test
268
+ runner_result = runner .invoke (main .typer_cli , ["modify" , test_dev_env_name ], color = True )
269
+
270
+ # Check expectations
271
+ assert 0 == runner_result .exit_code
272
+
273
+ mock_platform .get_dev_env_by_name .assert_called_once_with (test_dev_env_name )
274
+
275
+ console = Console (file = io .StringIO ())
276
+ console .print ("[red]The Development Environment doesn't exist." )
277
+ assert console .file .getvalue () == runner_result .stderr
278
+
279
279
@patch ("dem.cli.command.modify_cmd.modify_single_tool" )
280
280
@patch ("dem.cli.command.modify_cmd.typer.confirm" )
281
281
@patch ("dem.cli.command.modify_cmd.stdout.print" )
@@ -319,4 +319,31 @@ def test_execute_open_modify_panel(mock_open_modify_panel: MagicMock) -> None:
319
319
320
320
# Check expectations
321
321
mock_platform .get_dev_env_by_name .assert_called_once_with (test_dev_env_name )
322
- mock_open_modify_panel .assert_called_once_with (mock_platform , mock_dev_env )
322
+ mock_open_modify_panel .assert_called_once_with (mock_platform , mock_dev_env )
323
+
324
+ @patch ("dem.cli.command.modify_cmd.stderr.print" )
325
+ @patch ("dem.cli.command.modify_cmd.typer.confirm" )
326
+ @patch ("dem.cli.command.modify_cmd.stdout.print" )
327
+ def test_execute_PlatformError (mock_stdout_print : MagicMock , mock_confirm : MagicMock ,
328
+ mock_stderr_print : MagicMock ) -> None :
329
+ # Test setup
330
+ mock_platform = MagicMock ()
331
+ test_dev_env_name = "test_dev_env_name"
332
+ test_tool_type = "test_tool_type"
333
+ test_tool_image = "test_tool_image"
334
+ mock_dev_env = MagicMock ()
335
+ mock_dev_env .is_installed = True
336
+
337
+ mock_platform .get_dev_env_by_name .return_value = mock_dev_env
338
+ test_exception_text = "test_exception_text"
339
+ mock_platform .uninstall_dev_env .side_effect = modify_cmd .PlatformError (test_exception_text )
340
+
341
+ # Run unit under test
342
+ modify_cmd .execute (mock_platform , test_dev_env_name , test_tool_type , test_tool_image )
343
+
344
+ # Check expectations
345
+ mock_platform .get_dev_env_by_name .assert_called_once_with (test_dev_env_name )
346
+ mock_stdout_print .assert_called_once_with ("[yellow]The Development Environment is installed, so it can't be modified.[/]" )
347
+ mock_confirm .assert_called_once_with ("Do you want to uninstall it first?" , abort = True )
348
+ mock_platform .uninstall_dev_env .assert_called_once_with (mock_dev_env )
349
+ mock_stderr_print .assert_called_once_with (f"[red]Platform error: { test_exception_text } [/]" )
0 commit comments