Skip to content

Commit

Permalink
#5 adds warning instead of exception raising to pa schedule set. by: …
Browse files Browse the repository at this point in the history
…Piotr
  • Loading branch information
caseneuve committed Mar 13, 2021
1 parent 4c4d362 commit 7c8aa56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cli/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ def set(
`pa schedule update` or deleted with `pa schedule delete`
commands."""

get_logger(set_info=True)
logger = get_logger(set_info=True)

task = Task.to_be_created(
command=command, hour=hour, minute=minute, disabled=disabled
)
task.create_schedule()
try:
task.create_schedule()
except Exception as e:
logger.warning(snakesay(str(e)))


delete_app = typer.Typer()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ def test_validates_hours(self):
assert "Invalid value" in result.stdout
assert "66 is not in the valid range of 0 to 23" in result.stdout

def test_logs_warning_when_create_schedule_raises(self, mocker):
mock_logger = mocker.patch("cli.schedule.get_logger").return_value
mock_snakesay = mocker.patch("cli.schedule.snakesay")
mock_task_to_be_created = mocker.patch("cli.schedule.Task.to_be_created")
error_msg = (
"POST to set new task via API failed, got <Response [403]>: "
'{"detail":"You have reached your maximum number of scheduled tasks"}'
)
mock_task_to_be_created.return_value.create_schedule.side_effect = Exception(error_msg)

runner.invoke(app, ["set", "--command", "echo foo", "--minute", "13"])

assert mock_snakesay.call_args == call(error_msg)
assert mock_logger.warning.call_args == call(mock_snakesay.return_value)


@pytest.mark.clischeduledeleteall
class TestDeleteAllTasks:
Expand Down Expand Up @@ -240,6 +255,7 @@ def test_complains_when_no_id_provided(self):
result = runner.invoke(app, ["get", "--command"])
assert "Missing argument 'id'" in result.stdout


@pytest.mark.clischedulelist
class TestList:
def test_logs_table_with_correct_headers_and_values(self, mocker, task_list):
Expand Down

0 comments on commit 7c8aa56

Please sign in to comment.