Beispiel #1
0
def get_fake_repo():
    repo = Mock()
    repo.project = Project('example', repo)
    project = repo.project

    for i in range(0, 3):
        member = Member(project, "key_{}".format(i), "fakeRole")
        member._id = i
        member.id = i
        member.save()

    phase = Phase(project, 'phase key 1')
    phase._id = 1
    phase.save()

    for i in range(0, 5):
        task = Task(project)
        task._id = i
        task.description = 'Task  {}'.format(i)
        task.save()

    for i in range(0, 3):
        task = project.tasks[i]
        task.phase = phase
        task.assigned_to = project.members[i]
        task.save()

    project.tasks[3].assigned_to = project.members[0]
    project.tasks[4].assigned_to = project.members[1]

    for i in range(1, 3):
        project.tasks[i].parent = project.tasks[0]

    project.tasks[3].relations.add_next(project.tasks[4])

    node_1 = project.tokens.add_node(['1', '2', '3'])
    node_2 = project.tokens.add_node(['1', '2', '4'])
    node_3 = project.tokens.add_node(['3', '4', '5'])
    node_4 = project.tokens.add_node(['3', '6', '7'])

    project.tasks[0].inputs = [node_1, node_2]
    project.tasks[0].outputs = [node_3, node_4]

    return repo
Beispiel #2
0
def get_basic_frame(project):
        mock_repository = Mock()
        project.repository = mock_repository

        phase = Phase(project)
        phase._id = 2
        phase.save()

        member = Member(project, 'member_key')
        member._id = 5
        member.save()

        main_task = Task(project)
        main_task.description = 'Initial description'
        main_task.start_date = datetime.date(2016, 1, 4)
        main_task.duration = 2
        main_task.complete = 75
        main_task._id = 1
        main_task.save()

        parent = Task(project)
        parent.description = 'parent description'
        parent.start_date = datetime.date(2016, 1, 4)
        parent.duration = 1
        parent.complete = 100
        parent._id = 2
        parent.save()

        next_task = Task(project)
        next_task.description = 'next_task description'
        next_task.start_date = datetime.date(2016, 1, 4)
        next_task.duration = 1
        next_task.complete = 100
        next_task._id = 3
        next_task.save()

        return (phase, member, parent, main_task, next_task)
Beispiel #3
0
    def load_tasks(self):

        project = self.project
        tasks = {}
        resources = self.source.findall('./tasks//task')

        for resource in resources:
            if int(resource.attrib['id']) not in project.phases:
                task = Task(project)
                task._id = int(resource.attrib['id'])
                task.description = resource.attrib['name']
                task.start_date = datetime.datetime.strptime(
                                                    resource.attrib['start'],
                                                    '%Y-%m-%d').date()
                task.duration = int(resource.attrib['duration'])
                task.complete = int(resource.attrib['complete'])
                tasks[task._id] = task
        project.tasks = tasks

        input_id = self.source.findall('./tasks/taskproperties/taskproperty'
                                       '[@name="inputs"]')
        if input_id:
            input_id = input_id[0].attrib['id']
        output_id = self.source.findall('./tasks/taskproperties/taskproperty'
                                       '[@name="outputs"]')
        if output_id:
            output_id = output_id[0].attrib['id']

        for resource in resources:
            if int(resource.attrib['id']) not in project.phases:
                task = project.tasks[int(resource.attrib['id'])]
                for child in resource:
                    if child.tag == 'task':
                        subtask = project.tasks[int(child.attrib['id'])]
                        subtask.parent = task
                    if child.tag == 'depend':
                        next_task = project.tasks[int(child.attrib['id'])]
                        task.relations.add_next(next_task,
                                                int(child.attrib['difference'])
                                                )
                    if child.tag == 'customproperty':
                        if child.attrib['taskproperty-id'] == input_id:
                            task.inputs = self._get_tokens(
                                                           child.attrib['value']
                                                           )
                        if child.attrib['taskproperty-id'] == output_id:
                            task.outputs = self._get_tokens(
                                                            child.attrib['value']
                                                            )

        resources = self.source.findall('./allocations/allocation')
        for resource in resources:
            task_id = int(resource.attrib['task-id'])
            if task_id in project.tasks:
                task = project.tasks[task_id]
                member = project.members[int(
                                             resource.attrib['resource-id']
                                                            )]
                if resource.attrib['responsible'] == 'true':
                    task.assigned_to = member
                else:
                    task.colaborators.append(member)

        for phase in project.phases.values():
            resources = self.source.findall(
                                    "./tasks/task[@id='{}']//task".format(
                                                                    phase._id
                                                                    )
                                                        )
            for resource in resources:
                task = project.tasks[int(resource.attrib['id'])]
                task.phase = phase
                phase.tasks.append(task)

        for task in project.tasks.values():
            task._snap()