def test_task_creation_on_container_workflow_modification(self):
        """
        When changing state of a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        empty_task_container = self.empty_task_container
        msg = "so far, no task should have been created"
        self.assertEquals(len(empty_task_container.objectValues()), 0, msg)

        # do workflow change
        api.content.transition(empty_task_container, transition='submit')
        api.content.transition(empty_task_container, transition='retract')

        created = empty_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type
        )
        self.assertTrue(IAutomatedTask.providedBy(created), msg)
Exemple #2
0
def get_container_tasks(task_container, states=[]):
    """
    Return all the tasks of a container.
    """
    open_tasks = []
    to_explore = [task_container]
    while to_explore:
        current = to_explore.pop()
        if IAutomatedTask.providedBy(current):
            if not states:
                open_tasks.append(current)
            elif api.content.get_state(current) in states:
                open_tasks.append(current)
        if hasattr(current, 'objectValues'):
            to_explore.extend(current.objectValues())
    return open_tasks
Exemple #3
0
 def get_task_instances(self, root_container, states=[]):
     """
     Catalog query to return every AutomatedTask created
     from this TaskConfig contained in 'root_container'.
     """
     tasks = []
     to_explore = [root_container]
     while to_explore:
         current = to_explore.pop()
         if IAutomatedTask.providedBy(
                 current) and current.task_config_UID == self.UID():
             if not states:
                 tasks.append(current)
             elif api.content.get_state(current) in states:
                 tasks.append(current)
         if hasattr(current, 'objectValues'):
             to_explore.extend(current.objectValues())
     tasks = sorted(tasks, key=lambda x: x.created())
     return tasks
Exemple #4
0
    def get_opinion_group(self, groupe_type='editors'):
        opinion_request = self.context

        portal_urban = api.portal.get_tool('portal_urban')
        schedule_config = portal_urban.opinions_schedule

        task = None
        for task_config in schedule_config.get_all_task_configs():
            for obj in opinion_request.objectValues():
                is_task = IAutomatedTask.providedBy(obj)
                if is_task and obj.task_config_UID == task_config.UID():
                    if obj.assigned_group.endswith(groupe_type):
                        task = obj
                        break

        if task:
            return (task.assigned_group, )

        return ('technical_editors', 'technical_editors_environment')
Exemple #5
0
    def test_task_creation_on_container_creation(self):
        """
        When creating a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        new_task_container = api.content.create(type='Folder',
                                                id='new_task_container',
                                                container=self.portal)

        created = new_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type)
        self.assertTrue(IAutomatedTask.providedBy(created), msg)
    def test_task_creation_on_container_creation(self):
        """
        When creating a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        new_task_container = api.content.create(
            type='Folder',
            id='new_task_container',
            container=self.portal
        )

        created = new_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type
        )
        self.assertTrue(IAutomatedTask.providedBy(created), msg)
Exemple #7
0
    def test_task_creation_on_container_modification(self):
        """
        When modifying a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        empty_task_container = self.empty_task_container
        msg = "so far, no task should have been created"
        self.assertEquals(len(empty_task_container.objectValues()), 0, msg)

        # simulate modification
        notify(ObjectModifiedEvent(empty_task_container))

        created = empty_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type)
        self.assertTrue(IAutomatedTask.providedBy(created), msg)
    def test_task_creation_on_container_modification(self):
        """
        When modifying a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        empty_task_container = self.empty_task_container
        msg = "so far, no task should have been created"
        self.assertEquals(len(empty_task_container.objectValues()), 0, msg)

        # simulate modification
        notify(ObjectModifiedEvent(empty_task_container))

        created = empty_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type
        )
        self.assertTrue(IAutomatedTask.providedBy(created), msg)
Exemple #9
0
    def test_task_creation_on_container_workflow_modification(self):
        """
        When changing state of a contentype scheduled with a ScheduleConfig
        Task should created automatically depending on start conditions
        and starting_states.
        """
        empty_task_container = self.empty_task_container
        msg = "so far, no task should have been created"
        self.assertEquals(len(empty_task_container.objectValues()), 0, msg)

        # do workflow change
        api.content.transition(empty_task_container, transition='submit')
        api.content.transition(empty_task_container, transition='retract')

        created = empty_task_container.objectValues()
        created = created and created[0]

        # a task should have been created
        msg = "A task should have been created"
        self.assertTrue(created, msg)

        msg = "The object created should have been a Task but is {}".format(
            created.portal_type)
        self.assertTrue(IAutomatedTask.providedBy(created), msg)