Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_start_completed_task(self):
t = Task(self.tw, description='test task')
t.save()
t.done()
self.assertRaises(Task.CompletedTask, t.start)
def task_start_stop(self, uuid):
task = self.get_task(uuid)
if task:
try:
task.stop() if task.active else task.start()
return True, task
except (Task.CompletedTask, Task.DeletedTask, Task.ActiveTask, Task.InactiveTask) as e:
return False, e
return False, None
def done(self):
if not self.saved:
raise Task.NotSaved(
'Task needs to be saved before it can be completed',
)
# Refresh, and raise exception if task is already completed/deleted
self.refresh(only_fields=['status'])
if self.completed:
raise Task.CompletedTask('Cannot complete a completed task')
elif self.deleted:
raise Task.DeletedTask('Deleted task cannot be completed')
self.backend.complete_task(self)
# Refresh the status again, so that we have updated info stored
self.refresh(only_fields=['status', 'start', 'end'])
def start(self):
if not self.saved:
raise Task.NotSaved(
'Task needs to be saved before it can be started',
)
# Refresh, and raise exception if task is already completed/deleted
self.refresh(only_fields=['status'])
if self.completed:
raise Task.CompletedTask('Cannot start a completed task')
elif self.deleted:
raise Task.DeletedTask('Deleted task cannot be started')
elif self.active:
raise Task.ActiveTask('Task is already active')
self.backend.start_task(self)
# Refresh the status again, so that we have updated info stored
self.refresh(only_fields=['status', 'start'])