예제 #1
0
 def test_not_allowed_new_assignment(self):
     invalid_statuses = [Task.Status.PROCESSING,
                         Task.Status.REVIEWING,
                         Task.Status.POST_REVIEW_PROCESSING,
                         Task.Status.COMPLETE,
                         Task.Status.ABORTED]
     for status in invalid_statuses:
         with self.assertRaises(TaskStatusError):
             get_new_task_assignment(self.workers[2], status)
예제 #2
0
 def test_not_allowed_new_assignment(self):
     invalid_statuses = [
         Task.Status.PROCESSING, Task.Status.REVIEWING,
         Task.Status.POST_REVIEW_PROCESSING, Task.Status.COMPLETE,
         Task.Status.ABORTED
     ]
     for status in invalid_statuses:
         with self.assertRaises(TaskStatusError):
             get_new_task_assignment(self.workers[2], status)
예제 #3
0
 def test_worker_assigned_to_rejected_task(self):
     assignments = TaskAssignment.objects.filter(
         worker=self.workers[4],
         status=TaskAssignment.Status.PROCESSING,
         task__status=Task.Status.POST_REVIEW_PROCESSING)
     self.assertTrue(assignments.exists())
     self.assertTrue(worker_assigned_to_rejected_task(self.workers[4]))
     with self.assertRaises(TaskAssignmentError):
         get_new_task_assignment(self.workers[4],
                                 Task.Status.AWAITING_PROCESSING)
예제 #4
0
 def test_worker_assigned_to_rejected_task(self):
     assignments = TaskAssignment.objects.filter(
         worker=self.workers[4],
         status=TaskAssignment.Status.PROCESSING,
         task__status=Task.Status.POST_REVIEW_PROCESSING)
     self.assertTrue(assignments.exists())
     self.assertTrue(worker_assigned_to_rejected_task(self.workers[4]))
     with self.assertRaises(TaskAssignmentError):
         get_new_task_assignment(self.workers[4],
                                 Task.Status.AWAITING_PROCESSING)
예제 #5
0
 def test_worker_assigned_to_rejected_task(self):
     assignments = TaskAssignment.objects.filter(
         worker=self.workers[4],
         status=TaskAssignment.Status.PROCESSING,
         task__status=Task.Status.POST_REVIEW_PROCESSING)
     self.assertTrue(assignments.exists())
     self.assertTrue(worker_assigned_to_rejected_task(self.workers[4]))
     with patch('orchestra.utils.task_lifecycle.settings.'
                + 'ORCHESTRA_ENFORCE_NO_NEW_TASKS_DURING_REVIEW',
                return_value=True):
         with self.assertRaises(TaskAssignmentError):
             get_new_task_assignment(self.workers[4],
                                     Task.Status.AWAITING_PROCESSING)
예제 #6
0
def new_task_assignment(request, task_type):
    new_tasks_status = {
        'entry_level': Task.Status.AWAITING_PROCESSING,
        'reviewer': Task.Status.PENDING_REVIEW
    }
    try:
        task_status = new_tasks_status[task_type]
    except KeyError:
        raise BadRequest('No such task type')

    worker = Worker.objects.get(user=request.user)
    try:
        task_assignment = get_new_task_assignment(worker, task_status)
    except WorkerCertificationError:
        raise BadRequest('No worker certificates')
    except NoTaskAvailable:
        raise BadRequest('No task')

    task = task_assignment.task
    return {
        'id': task.id,
        'assignment_id': task_assignment.id,
        'step': task.step.slug,
        'project': task.project.workflow_version.slug,
        'detail': task.project.short_description
    }
예제 #7
0
    def test_project_assignment_recorded_time(self):
        project = self.projects['base_test_project']
        worker = self.workers[0]

        task = self.tasks['review_task']
        assignment = TaskAssignment.objects.filter(worker=worker,
                                                   task=task).first()
        other_assignment = get_new_task_assignment(
            worker, Task.Status.AWAITING_PROCESSING)

        # create 3 time entries
        TimeEntry.objects.create(worker=self.workers[0],
                                 date=datetime.datetime.now().date(),
                                 time_worked=datetime.timedelta(hours=1),
                                 assignment=assignment)
        TimeEntry.objects.create(worker=self.workers[0],
                                 date=datetime.datetime.now().date(),
                                 time_worked=datetime.timedelta(hours=1),
                                 assignment=other_assignment)
        TimeEntry.objects.create(worker=self.workers[0],
                                 date=datetime.datetime.now().date(),
                                 time_worked=datetime.timedelta(minutes=15),
                                 assignment=assignment)

        response = self.api_client.post(
            '/orchestra/api/project/project_information/',
            {'project_ids': [project.id]},
            format='json')
        returned = load_encoded_json(response.content)
        returned_task = returned[str(project.id)]['tasks']
        returned_assignment = returned_task['step1']['assignments'][0]
        recorded_time = returned_assignment['recorded_work_time']
        self.assertEqual(recorded_time, 105 * 60)  # 1:15 + 0:30
예제 #8
0
파일: views.py 프로젝트: skamille/orchestra
def new_task_assignment(request, task_type):
    new_tasks_status = {
        'entry_level': Task.Status.AWAITING_PROCESSING,
        'reviewer': Task.Status.PENDING_REVIEW
    }
    try:
        task_status = new_tasks_status[task_type]
    except KeyError:
        raise BadRequest('No such task type')

    worker = Worker.objects.get(user=request.user)
    try:
        task_assignment = get_new_task_assignment(worker, task_status)
    except WorkerCertificationError:
        raise BadRequest('No worker certificates')
    except NoTaskAvailable:
        raise BadRequest('No task')

    task = task_assignment.task
    return {
        'id': task.id,
        'step': task.step.slug,
        'project': task.project.workflow_version.slug,
        'detail': task.project.short_description
    }
예제 #9
0
    def test_get_new_task_assignment_reviewer(self):
        # Reviewer assignment
        self.assertEquals(
            Task.objects.filter(status=Task.Status.PENDING_REVIEW).count(), 1)

        # assign a review task to worker
        assignment = get_new_task_assignment(self.workers[7],
                                             Task.Status.PENDING_REVIEW)
        self.assertTrue(assignment is not None)
        self.assertEquals(assignment.task.status, Task.Status.REVIEWING)

        self.assertEquals(assignment.in_progress_task_data,
                          {'test_key': 'test_value'})

        # No tasks in state PENDING_REVIEW
        # No more tasks left in AWAITING_PROCESSING
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[7],
                                    Task.Status.PENDING_REVIEW)

        # Assign an entry-level task to reviewer
        assignment = get_new_task_assignment(self.workers[7],
                                             Task.Status.AWAITING_PROCESSING)
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[7],
                                    Task.Status.AWAITING_PROCESSING)
예제 #10
0
    def test_get_new_task_assignment_reviewer(self):
        # Reviewer assignment
        self.assertEquals(Task.objects
                          .filter(status=Task.Status.PENDING_REVIEW)
                          .count(),
                          1)

        # assign a review task to worker
        assignment = get_new_task_assignment(self.workers[7],
                                             Task.Status.PENDING_REVIEW)
        self.assertTrue(assignment is not None)
        self.assertEquals(assignment.task.status,
                          Task.Status.REVIEWING)

        self.assertEquals(assignment.in_progress_task_data,
                          {'test_key': 'test_value'})

        # No tasks in state PENDING_REVIEW
        # No more tasks left in AWAITING_PROCESSING
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[7],
                                    Task.Status.PENDING_REVIEW)

        # Assign an entry-level task to reviewer
        assignment = get_new_task_assignment(self.workers[7],
                                             Task.Status.AWAITING_PROCESSING)
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[7],
                                    Task.Status.AWAITING_PROCESSING)
예제 #11
0
파일: views.py 프로젝트: nbanta/orchestra
def new_task_assignment(request, task_type):
    new_tasks_status = {"entry_level": Task.Status.AWAITING_PROCESSING, "reviewer": Task.Status.PENDING_REVIEW}
    try:
        task_status = new_tasks_status[task_type]
    except KeyError:
        raise BadRequest("No such task type")

    worker = Worker.objects.get(user=request.user)
    try:
        task_assignment = get_new_task_assignment(worker, task_status)
    except WorkerCertificationError:
        raise BadRequest("No worker certificates")
    except NoTaskAvailable:
        raise BadRequest("No task")

    task = task_assignment.task
    return {
        "id": task.id,
        "step": task.step_slug,
        "project": task.project.workflow_slug,
        "detail": task.project.short_description,
    }
예제 #12
0
    def test_get_new_task_assignment_entry_level(self):
        # Entry-level assignment
        self.assertEquals(Task.objects
                          .filter(status=Task.Status.AWAITING_PROCESSING)
                          .count(),
                          1)

        with self.assertRaises(WorkerCertificationError):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.PENDING_REVIEW)

        # assign a new task to a worker
        assignment = get_new_task_assignment(self.workers[5],
                                             Task.Status.AWAITING_PROCESSING)
        self.assertTrue(assignment is not None)

        self.assertEquals(assignment.task.status,
                          Task.Status.PROCESSING)

        # No more tasks left in AWAITING_PROCESSING
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.AWAITING_PROCESSING)

        # Worker should not be served machine tasks
        workflow_slug = 'test_workflow_2'
        workflow = get_workflow_by_slug(workflow_slug)
        simple_machine = workflow.get_step('simple_machine')
        simple_machine.creation_depends_on = []

        project = Project.objects.create(workflow_slug=workflow_slug,
                                         short_description='',
                                         priority=0,
                                         task_class=0)
        Task.objects.create(project=project,
                            status=Task.Status.AWAITING_PROCESSING,
                            step_slug='simple_machine')

        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.AWAITING_PROCESSING)
예제 #13
0
    def test_get_new_task_assignment_entry_level(self):
        # Entry-level assignment
        self.assertEqual(Task.objects
                         .filter(status=Task.Status.AWAITING_PROCESSING)
                         .count(),
                         1)

        with self.assertRaises(WorkerCertificationError):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.PENDING_REVIEW)

        # assign a new task to a worker
        assignment = get_new_task_assignment(self.workers[5],
                                             Task.Status.AWAITING_PROCESSING)
        self.assertTrue(assignment is not None)

        self.assertEqual(assignment.task.status,
                         Task.Status.PROCESSING)

        # No more tasks left in AWAITING_PROCESSING
        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.AWAITING_PROCESSING)

        # Worker should not be served machine tasks
        workflow_version = self.workflow_versions['test_workflow_2']
        simple_machine = self.workflow_steps[
            workflow_version.slug]['simple_machine']
        project = Project.objects.create(workflow_version=workflow_version,
                                         short_description='',
                                         priority=0,
                                         task_class=0)
        Task.objects.create(project=project,
                            status=Task.Status.AWAITING_PROCESSING,
                            step=simple_machine)

        with self.assertRaises(NoTaskAvailable):
            get_new_task_assignment(self.workers[5],
                                    Task.Status.AWAITING_PROCESSING)