def test_role_counter_required_for_new_task(self): task = TaskFactory(status=Task.Status.COMPLETE) with self.assertRaises(TaskAssignmentError): role_counter_required_for_new_task(task) project = self.projects['assignment_policy'] # Create first task in test project create_subsequent_tasks(project) self.assertEquals(project.tasks.count(), 1) # Assign initial task to worker 0 task = project.tasks.first() counter = role_counter_required_for_new_task(task) self.assertEquals(counter, 0) initial_task = assign_task(self.workers[0].id, task.id) # Submit task; next task should be created with patch('orchestra.utils.task_lifecycle._is_review_needed', return_value=True): initial_task = submit_task(initial_task.id, {}, Iteration.Status.REQUESTED_REVIEW, self.workers[0]) counter = role_counter_required_for_new_task(initial_task) self.assertEquals(counter, 1) initial_task = assign_task(self.workers[1].id, task.id) initial_task = submit_task(initial_task.id, {}, Iteration.Status.REQUESTED_REVIEW, self.workers[1]) counter = role_counter_required_for_new_task(initial_task) self.assertEquals(counter, 2)
def staff(self, task_id, request_cause=StaffBotRequest.RequestCause.USER.value): """ This function handles staffing a request for the given task_id. """ try: task = Task.objects.get(id=task_id) required_role_counter = role_counter_required_for_new_task(task) error_msg = None assert_new_task_status_valid(task.status) except TaskStatusError: error_msg = self.staffing_is_not_allowed.format(task_id) except Task.DoesNotExist: error_msg = self.task_does_not_exist_error.format(task_id) except TaskAssignmentError as error: error_msg = self.task_assignment_error.format(task_id, error) if error_msg is not None: logger.exception(error_msg) return format_slack_message(error_msg) StaffBotRequest.objects.create( task=task, required_role_counter=required_role_counter, request_cause=request_cause) return format_slack_message('Staffed task {}!'.format(task_id))
def staff(self, task_id, request_cause=StaffBotRequest.RequestCause.USER.value): """ This function handles staffing a request for the given task_id. """ command = 'staff {}'.format(task_id) try: task = Task.objects.get(id=task_id) required_role_counter = role_counter_required_for_new_task(task) error_msg = None assert_new_task_status_valid(task.status) except TaskStatusError: error_msg = self.staffing_is_not_allowed.format(task_id) except Task.DoesNotExist: error_msg = self.task_does_not_exist_error.format(task_id) except TaskAssignmentError as error: error_msg = self.task_assignment_error.format(task_id, error) if error_msg is not None: logger.exception(error_msg) return format_slack_message( command, attachments=[{ 'color': 'danger', 'title': 'Error', 'text': error_msg }]) StaffBotRequest.objects.create( task=task, required_role_counter=required_role_counter, request_cause=request_cause) slack_message = self.staffing_success.format(task_id) message_experts_slack_group(task.project.slack_group_id, slack_message) return format_slack_message( command, attachments=[{ 'color': 'good', 'title': 'Success', 'text': slack_message }])