Skip to content

Commit

Permalink
#29 adds path delete cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Apr 9, 2021
1 parent 366d8bf commit 833ef51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cli/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cli_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 833ef51

Please sign in to comment.