Example #1
0
def create_project_with_tasks(workflow_slug,
                              description,
                              priority,
                              task_class,
                              project_data,
                              review_document_url,
                              workflow_version_slug=None):

    # Allow backwards compatibility with calls that pass in a version slug in
    # the 'workflow_slug' variable.
    # TODO(dhaas): be less backward-compatible?
    if workflow_version_slug is None:
        try:
            workflow_version = WorkflowVersion.objects.get(slug=workflow_slug)
        except WorkflowVersion.MultipleObjectsReturned:
            raise ValueError('No workflow slug passed, and version slug {} is '
                             'not unique.'.format(workflow_slug))
    else:
        workflow_version = WorkflowVersion.objects.get(
            slug=workflow_version_slug,
            workflow__slug=workflow_slug)

    project = Project.objects.create(workflow_version=workflow_version,
                                     short_description=description,
                                     priority=priority,
                                     project_data=project_data,
                                     task_class=task_class,
                                     review_document_url=review_document_url)

    create_project_slack_group(project)
    create_project_google_folder(project)

    create_subsequent_tasks(project)
    return project
Example #2
0
def _setup_projects(test_case, projects):
    # Create projects
    test_case.projects = {}
    for name, workflow_slug in projects.items():
        test_case.projects[name] = ProjectFactory(
            start_datetime=parse('2015-10-12T00:00:00+00:00'),
            workflow_version=test_case.workflow_versions[workflow_slug])
        create_project_slack_group(test_case.projects[name])
Example #3
0
def _setup_projects(test_case, projects):
    # Create projects
    test_case.projects = {}
    for name, workflow_slug in projects.items():
        test_case.projects[name] = ProjectFactory(
            start_datetime=parse('2015-10-12T00:00:00+00:00'),
            workflow_version=test_case.workflow_versions[workflow_slug])
        create_project_slack_group(test_case.projects[name])
Example #4
0
def create_project_with_tasks(workflow_slug, workflow_version_slug,
                              description, priority, task_class, project_data):

    workflow_version = WorkflowVersion.objects.get(
        slug=workflow_version_slug, workflow__slug=workflow_slug)

    project = Project.objects.create(workflow_version=workflow_version,
                                     short_description=description,
                                     priority=priority,
                                     project_data=project_data,
                                     task_class=task_class)

    create_project_slack_group(project)
    create_project_google_folder(project)

    create_subsequent_tasks(project)
    return project
Example #5
0
 def test_create_project_slack_group(self):
     groups = self.slack.data['groups']
     num_groups = len(groups)
     project = ProjectFactory(workflow_slug='test_workflow')
     self.assertFalse(project.id in groups)
     group_id = create_project_slack_group(project)
     self.assertEquals(len(groups), num_groups + 1)
     self.assertTrue(group_id in groups)
     project = Project.objects.get(id=project.id)
     self.assertEquals(group_id, project.slack_group_id)
Example #6
0
def create_project_with_tasks(workflow_slug,
                              description,
                              priority,
                              task_class,
                              project_data,
                              review_document_url):

    project = Project.objects.create(workflow_slug=workflow_slug,
                                     short_description=description,
                                     priority=priority,
                                     project_data=project_data,
                                     task_class=task_class,
                                     review_document_url=review_document_url)

    create_project_slack_group(project)
    create_project_google_folder(project)

    create_subsequent_tasks(project)
    return project
Example #7
0
 def test_create_project_slack_group(self):
     groups = self.slack.data['groups']
     num_groups = len(groups)
     project = ProjectFactory(
         workflow_version=self.workflow_versions['test_workflow'])
     self.assertFalse(project.id in groups)
     group_id = create_project_slack_group(project)
     self.assertEquals(len(groups), num_groups + 1)
     self.assertTrue(group_id in groups)
     project = Project.objects.get(id=project.id)
     self.assertEquals(group_id, project.slack_group_id)
Example #8
0
def create_project_with_tasks(workflow_slug,
                              workflow_version_slug,
                              description,
                              priority,
                              task_class,
                              project_data):

    workflow_version = WorkflowVersion.objects.get(
        slug=workflow_version_slug,
        workflow__slug=workflow_slug)

    project = Project.objects.create(workflow_version=workflow_version,
                                     short_description=description,
                                     priority=priority,
                                     project_data=project_data,
                                     task_class=task_class)

    create_project_slack_group(project)
    create_project_google_folder(project)

    create_subsequent_tasks(project)
    return project
Example #9
0
def setup_models(test_case):
    """ Set up models that we'll use in multiple tests """
    # Certification generation data
    certifications = [
        {
            'slug': 'certification1',
            'name': 'The first certification',
            'required_certifications': []
        },
        {
            'slug': 'certification2',
            'name': 'The second certification',
            'required_certifications': ['certification1']
        }
    ]

    # Worker generation data
    workers = {
        0: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL)
        ],
        1: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification1', WorkerCertification.Role.REVIEWER)
        ],
        2: [],
        3: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification1', WorkerCertification.Role.REVIEWER)
        ],
        4: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification2', WorkerCertification.Role.ENTRY_LEVEL)
        ],
        5: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification2', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification2', WorkerCertification.Role.REVIEWER)
        ],
        6: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification1', WorkerCertification.Role.REVIEWER),
            ('certification2', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification2', WorkerCertification.Role.REVIEWER)
        ],
        7: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification1', WorkerCertification.Role.REVIEWER)
        ],
        8: [
            ('certification1', WorkerCertification.Role.ENTRY_LEVEL),
            ('certification1', WorkerCertification.Role.REVIEWER)
        ]
    }

    # Project generation data
    projects = {
        'empty_project': 'test_workflow',
        'base_test_project': 'test_workflow',
        'test_human_and_machine': 'test_workflow_2',
        'no_task_assignments': 'test_workflow',
        'reject_entry_proj': 'test_workflow',
        'reject_rev_proj': 'test_workflow',
        'aborted_project': 'test_workflow',
        'project_to_end': 'test_workflow',
        'assignment_policy': 'assignment_policy_workflow',
    }

    # Task generation data
    test_case.test_step_slug = 'step1'
    test_data = {'test_key': 'test_value'}
    tasks = {
        'review_task': {
            'project_name': 'base_test_project',
            'status': Task.Status.PENDING_REVIEW,
            'assignments': [
                (0, test_data, TaskAssignment.Status.SUBMITTED)
            ],
        },
        'processing_task': {
            'project_name': 'no_task_assignments',
            'status': Task.Status.AWAITING_PROCESSING,
            'assignments': []
        },
        'rejected_entry': {
            'project_name': 'reject_entry_proj',
            'status': Task.Status.POST_REVIEW_PROCESSING,
            'assignments': [
                (4, test_data, TaskAssignment.Status.PROCESSING),
                (6, {}, TaskAssignment.Status.SUBMITTED)
            ]
        },
        'rejected_review': {
            'project_name': 'reject_rev_proj',
            'status': Task.Status.POST_REVIEW_PROCESSING,
            'assignments': [
                (5, {}, TaskAssignment.Status.SUBMITTED),
                (6, test_data, TaskAssignment.Status.PROCESSING),
                (7, {}, TaskAssignment.Status.SUBMITTED)
            ]
        },
        'aborted': {
            'project_name': 'aborted_project',
            'status': Task.Status.ABORTED,
            'assignments': [
                (4, test_data, TaskAssignment.Status.PROCESSING)
            ]
        },
        'to_be_ended_1': {
            'project_name': 'project_to_end',
            'status': Task.Status.POST_REVIEW_PROCESSING,
            'assignments': [
                (5, {}, TaskAssignment.Status.SUBMITTED),
                (6, test_data, TaskAssignment.Status.PROCESSING),
                (7, {}, TaskAssignment.Status.SUBMITTED)
            ]
        },
        'to_be_ended_2': {
            'project_name': 'project_to_end',
            'status': Task.Status.PROCESSING,
            'assignments': [
                (4, test_data, TaskAssignment.Status.SUBMITTED)
            ]
        },
    }

    # Create certifications and dependencies
    test_case.certifications = {}
    for details in certifications:
        new_slug = details['slug']
        test_case.certifications[new_slug] = CertificationFactory(
            slug=new_slug, name=details['name'])
        for required_slug in details['required_certifications']:
            test_case.certifications[new_slug].required_certifications.add(
                test_case.certifications[required_slug])

    # Create and certify workers
    test_case.workers = {}
    test_case.clients = {}
    for user_id, certifications in workers.items():
        # Create user, worker, client
        user = (UserFactory(username='******'.format(user_id),
                            first_name='test_first_{}'.format(user_id),
                            last_name='test_last_{}'.format(user_id),
                            password='******'.format(user_id),
                            email='test_user_{}@test.com'.format(user_id)))
        test_case.workers[user_id] = WorkerFactory(user=user)
        test_case.clients[user_id] = Client()
        test_case.clients[user_id].login(
            username='******'.format(user_id),
            password='******'.format(user_id))

        # Assign certifications
        for slug, role in certifications:
            WorkerCertificationFactory(
                certification=test_case.certifications[slug],
                worker=test_case.workers[user_id],
                role=role)

    # Create projects
    test_case.projects = {}
    for name, workflow_slug in projects.items():
        test_case.projects[name] = ProjectFactory(
            workflow_slug=workflow_slug,
            start_datetime=parse('2015-10-12T00:00:00+00:00'))
        create_project_slack_group(test_case.projects[name])

    # Create and assign taks
    test_case.tasks = {}
    for task_slug, details in tasks.items():
        task = TaskFactory(project=test_case.projects[details['project_name']],
                           step_slug=test_case.test_step_slug,
                           status=details['status'],
                           start_datetime=parse('2015-10-12T01:00:00+00:00'))
        test_case.tasks[task_slug] = task
        for i, (user_id,
                task_data,
                assignment_status) in enumerate(details['assignments']):
            TaskAssignmentFactory(
                worker=test_case.workers[user_id],
                task=task,
                status=assignment_status,
                assignment_counter=i,
                in_progress_task_data=task_data,
                start_datetime=parse(
                    '2015-10-12T0{}:00:00+00:00'.format(2 + i)))