Exemplo n.º 1
0
    def create_sprint(self,
                      name,
                      start=None,
                      end=None,
                      duration=20,
                      milestone=None,
                      team=None):
        """Creates a Sprint for the given milestone, if doesn't exists, first
        it creates a Milestone"""
        # If the start day is set to today, the sprint will
        # normalize it to 9:00am of the start day and all the tests
        # will fail, till 9:00am in the morning...
        if start is None:
            # we set hours to 0 so will be normalized to 9am at any
            # time of the day, when running tests.
            start = (now(tz=utc) - timedelta(days=3)).replace(hour=0)
        if milestone is None:
            milestone = self.create_milestone('Milestone for %s' % name)
        # It should automatically load the existing Sprint if already there
        if isinstance(milestone, Milestone):
            milestone = milestone.name
        sprint_controller = SprintController(self.env)
        if start is not None:
            start = shift_to_utc(start)
        if end is not None:
            end = shift_to_utc(end)
        create_sprint_command = SprintController.CreateSprintCommand(
            self.env,
            name=name,
            start=start,
            end=end,
            duration=duration,
            milestone=milestone)
        create_sprint_command.native = True
        sprint = sprint_controller.process_command(create_sprint_command)

        assert sprint is not None
        if team is not None:
            if isinstance(team, basestring):
                team = self.create_team(name=team)
            sprint.team = team
            sprint.save()
        return sprint