diff --git a/cli/path.py b/cli/path.py index 0be6053..24b0355 100644 --- a/cli/path.py +++ b/cli/path.py @@ -114,8 +114,15 @@ def upload( @app.command() -def delete(path: str = typer.Argument(..., help="Path to PythonAnywhere file or directory")): - pass +def delete( + path: str = typer.Argument(..., help="Path to PythonAnywhere file or directory to be deleted"), +): + path = standarize_path(path) + pa_path = PAPath(path) + + success = pa_path.delete() + + sys.exit(0 if success else 1) @app.command() diff --git a/tests/test_cli_path.py b/tests/test_cli_path.py index a4b72f0..68256f0 100644 --- a/tests/test_cli_path.py +++ b/tests/test_cli_path.py @@ -203,3 +203,21 @@ def test_exits_with_error_when_unsuccessful_upload(self, mock_path): assert mock_path.return_value.upload.called assert result.exit_code == 1 + + +class TestDelete: + def test_exits_with_success_when_successful_delete(self, mock_path): + mock_path.return_value.delete.return_value = True + + result = runner.invoke(app, ["delete", "~/hello.txt"]) + + assert mock_path.return_value.delete.called + assert result.exit_code == 0 + + def test_exits_with_error_when_unsuccessful_delete(self, mock_path): + mock_path.return_value.delete.return_value = False + + result = runner.invoke(app, ["delete", "~/hello.txt"]) + + assert mock_path.return_value.delete.called + assert result.exit_code == 1