Exemple #1
0
    def test_get_object_state(self):

        tasks_on_object = [
            cycle_task.CycleTaskGroupObjectTask(
                end_date=date(2015, 2, 1), cycle=cycle.Cycle(is_current=True)),
            cycle_task.CycleTaskGroupObjectTask(
                end_date=date(2015, 1,
                              10), cycle=cycle.Cycle(is_current=True)),
        ]
        with freeze_time("2015-02-01 13:39:20"):
            self.assertEqual(
                "Overdue",
                workflow.WorkflowState.get_object_state(tasks_on_object))
Exemple #2
0
 def test_get_object_state(self):
     """Test get object state."""
     with patch(u"ggrc.access_control.role.get_ac_roles_for",
                return_value={}):
         tasks_on_object = [
             cycle_task.CycleTaskGroupObjectTask(
                 end_date=date(2015, 2, 1),
                 cycle=cycle.Cycle(is_current=True)),
             cycle_task.CycleTaskGroupObjectTask(
                 end_date=date(2015, 1, 10),
                 cycle=cycle.Cycle(is_current=True)),
         ]
         with freeze_time("2015-02-01 13:39:20"):
             self.assertEqual(
                 "Overdue",
                 workflow.WorkflowState.get_object_state(tasks_on_object))
  def ensure_backlog_workflow_exists(cls):
    """Ensures there is at least one backlog workflow with an active cycle.
    If such workflow does not exist it creates one."""

    def any_active_cycle(workflows):
      """Checks if any active cycle exists from given workflows"""
      for workflow in workflows:
        for cur_cycle in workflow.cycles:
          if cur_cycle.is_current:
            return True
      return False

    # Check if backlog workflow already exists
    backlog_workflows = Workflow.query.filter(
        and_(Workflow.kind == "Backlog",
             # the following means one_time wf
             Workflow.unit is None)
    ).all()

    if len(backlog_workflows) > 0 and any_active_cycle(backlog_workflows):
      return "At least one backlog workflow already exists"
    # Create a backlog workflow
    backlog_workflow = Workflow(description="Backlog workflow",
                                title="Backlog (one time)",
                                status="Active",
                                recurrences=0,
                                kind="Backlog")

    # create wf context
    wf_ctx = backlog_workflow.get_or_create_object_context(context=1)
    backlog_workflow.context = wf_ctx
    db.session.flush(backlog_workflow)
    # create a cycle
    backlog_cycle = cycle.Cycle(description="Backlog workflow",
                                title="Backlog (one time)",
                                is_current=1,
                                status="Assigned",
                                start_date=None,
                                end_date=None,
                                context=backlog_workflow
                                .get_or_create_object_context(),
                                workflow=backlog_workflow)

    # create a cycletaskgroup
    backlog_ctg = cycle_task_group\
        .CycleTaskGroup(description="Backlog workflow taskgroup",
                        title="Backlog TaskGroup",
                        cycle=backlog_cycle,
                        status=cycle_task_group.CycleTaskGroup.IN_PROGRESS,
                        start_date=None,
                        end_date=None,
                        context=backlog_workflow
                        .get_or_create_object_context())

    db.session.add_all([backlog_workflow, backlog_cycle, backlog_ctg])
    db.session.flush()

    # add fulltext entries
    get_indexer().create_record(backlog_workflow)
    return "Backlog workflow created"