Skip to content

Commit 5937718

Browse files
fixes tasks creation for midnight tasks.
1 parent 26d1dc8 commit 5937718

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

pythonanywhere/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def to_be_created(cls, *, command, minute, hour=None, disabled=False):
9797
task.command = command
9898
task.hour = hour
9999
task.minute = minute
100-
task.interval = "daily" if hour else "hourly"
100+
task.interval = "daily" if hour is not None else "hourly"
101101
task.enabled = not disabled
102102
return task
103103

@@ -138,7 +138,7 @@ def create_schedule(self):
138138
"interval": self.interval,
139139
"minute": self.minute,
140140
}
141-
if self.hour:
141+
if self.hour is not None:
142142
params["hour"] = self.hour
143143

144144
self.update_specs(self.schedule.create(params))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="pythonanywhere",
12-
version="0.10.2",
12+
version="0.10.3",
1313
description="PythonAnywhere helper tools for users",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",

tests/test_task.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ def test_creates_daily_task(self, mocker, task_specs):
9393
assert mock_create.call_args == call(
9494
{"command": "echo foo", "hour": 16, "minute": 0, "enabled": True, "interval": "daily"}
9595
)
96+
def test_creates_daily_midnight_task(self, mocker, task_specs):
97+
mock_create = mocker.patch("pythonanywhere.api.schedule.Schedule.create")
98+
mock_create.return_value = task_specs
99+
mock_update_specs = mocker.patch("pythonanywhere.task.Task.update_specs")
100+
task = Task.to_be_created(command="echo foo", hour=0, minute=0, disabled=False)
101+
102+
task.create_schedule()
103+
104+
assert mock_update_specs.call_args == call(task_specs)
105+
assert mock_create.call_count == 1
106+
assert mock_create.call_args == call(
107+
{"command": "echo foo", "hour": 0, "minute": 0, "enabled": True, "interval": "daily"}
108+
)
96109

97110

98111
@pytest.mark.tasks

0 commit comments

Comments
 (0)