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_delete_deleted_task(self):
t = Task(self.tw, description='test task')
t.save()
t.delete()
self.assertRaises(Task.DeletedTask, t.delete)
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'])
def task_delete(self, uuid):
task = self.get_task(uuid)
if task:
try:
task.delete()
return True, task
except Task.DeletedTask as e:
return False, e
return False, None
def delete(self):
if not self.saved:
raise Task.NotSaved(
'Task needs to be saved before it can be deleted',
)
# Refresh the status, and raise exception if the task is deleted
self.refresh(only_fields=['status'])
if self.deleted:
raise Task.DeletedTask('Task was already deleted')
self.backend.delete_task(self)
# Refresh the status again, so that we have updated info stored
self.refresh(only_fields=['status', 'start', 'end'])
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'])