def test_get_pivotal_metrics_with_story_blocker_unresolved(mocker):
    story_started = "2018-11-01T12:00:00Z"
    story_accepted = "2018-11-07T12:00:00Z"
    blocked_start = "2018-11-05T12:00:00Z"

    stories = [{
        "id": 1,
        "current_state": "accepted",
        "name": "test",
        "accepted_at": story_accepted,
    }, {
        "id": 2,
        "current_state": "started",
        "name": "test 2",
    }]
    blocker = {
        "story_id": 2,
        "resolved": False,
        "created_at": blocked_start,
    }

    mock_pivotal_client(mocker,
                        story_started=story_started,
                        stories=stories,
                        story_blockers=[blocker])

    p = Pivotal()
    metrics = p.get_metrics()

    assert len(metrics) == 1
    assert metrics[0].avg_cycle_time == (get_datetime(story_accepted) -
                                         get_datetime(story_started) -
                                         timedelta(days=2)).total_seconds()
    assert metrics[0].process_cycle_efficiency == 1
    assert metrics[0].num_incomplete == 1
def test_pvotal_get_metrics(mocker):
    story_started = "2018-11-01T12:00:00Z"
    story_accepted = "2018-11-05T12:00:00Z"
    story = {
        "id": 1,
        "current_state": "accepted",
        "name": "test",
        "accepted_at": story_accepted,
    }

    mock_pivotal_client(mocker, story_started=story_started, stories=[story])

    p = Pivotal()
    metrics = p.get_metrics()

    assert len(metrics) == 1
    assert metrics[0].avg_cycle_time == (
        # subtract 2 days as there is a weekend between start end accepted
        get_datetime(story_accepted) - get_datetime(story_started) -
        timedelta(days=2)).total_seconds()
    assert metrics[0].process_cycle_efficiency == 1
Пример #3
0
def test_get_jira_metrics_with_blocker(mocker):
    history = [
        {
            'created': '2018-11-01T12:00:00',
            'toString': 'In Progress'
        },
        {
            'created': '2018-11-02T12:00:00',
            'toString': 'Blocked'
        },
        {
            'created': '2018-11-05T12:00:00',
            'fromString': 'Blocked',
            'toString': 'In Progress'
        },
        {
            'created': '2018-11-06T12:00:00',
            'toString': 'Done'
        },
    ]

    issue = mock_issue(history)

    mock_jira_client(mocker, issue)

    j = Jira(project_id='test_project')
    metrics = j.get_metrics()

    cycle_time_timedelta = get_datetime(history[3]['created']) - get_datetime(
        history[0]['created']) - timedelta(days=2)

    assert len(metrics) == 1
    assert metrics[0].avg_cycle_time == cycle_time_timedelta.total_seconds()
    assert metrics[0].process_cycle_efficiency == (
        (cycle_time_timedelta -
         (get_datetime(history[2]['created']) -
          get_datetime(history[1]['created']) - timedelta(days=2))) /
        cycle_time_timedelta)
Пример #4
0
def test_get_jira_metrics_for_last_12_weeks(mocker):
    history = [
        {
            'created': '2018-11-01T12:00:00',
            'toString': 'In Progress'
        },
        {
            'created': '2018-11-02T12:00:00',
            'toString': 'Done'
        },
    ]

    issue = mock_issue(history)

    mock_jira_client(mocker, issue)

    j = Jira(project_id='test_project')
    metrics = j.get_metrics(year=2018, quarter=3)

    assert len(metrics) == 1
    assert metrics[0].avg_cycle_time == (
        get_datetime(history[1]['created']) -
        get_datetime(history[0]['created'])).total_seconds()
    assert metrics[0].process_cycle_efficiency == 1
    def get_iteration_range(self, year, quarter):
        q_start, _ = get_quarter_daterange(year, quarter)

        project_info = self.pivotal.get_project()

        date_diff = q_start - get_datetime(project_info['start_time'])

        s = date_diff.total_seconds()
        weeks, _ = divmod(s, 7 * 24 * 60 * 60)

        iteration_length = project_info['iteration_length']
        current_iteration = project_info['current_iteration_number']

        iteration_start = int(weeks / iteration_length)
        iteration_end = int(iteration_start + 12 / iteration_length)
        if iteration_end > current_iteration:
            iteration_end = current_iteration
        num_iterations = iteration_end - iteration_start

        return iteration_start, num_iterations
Пример #6
0
def mock_trello_client(mocker, lists=None):
    mocker.patch(
        "os.environ", {
            'TM_TRELLO_TOKEN': 'test_token',
            'TM_TRELLO_PAT': 'test_pat',
            'TM_TRELLO_ORG_ID': 'test_org',
            'TM_TRELLO_BOARD_ID': 'test_board',
        })

    class MockList:
        id = '1'
        name = 'test_list'
        cards = []
        closed = False

        def __init__(self, name, cards=None):
            self.name = name

            if cards:
                self.cards = cards
            elif not lists:
                self.cards.append(MockCard())

        def list_cards(self):
            return self.cards

    class MockCard:
        def __init__(self,
                     name='test_card',
                     description=None,
                     movements=None,
                     created_date=None):
            self.id = uuid.uuid1()
            self.name = name
            self.description = description
            self.movements = movements
            self.created_date = created_date

        def list_movements(self):
            return self.movements

    class MockTrelloClient:
        class MockBoard:
            name = 'test_board'

            def list_lists(self):
                return _lists

        def __init__(self, api_key=None, token=None, lists=None):
            pass

        def get_board(self, board_id):
            return self.MockBoard()

    if not lists:
        _lists = [
            MockList('TM Q3 sprints',
                     cards=[
                         MockCard('Done (week 1)',
                                  description='2018-11-28 - 2018-12-11')
                     ]),
            MockList('Done (week 1)',
                     cards=[
                         MockCard('test_card',
                                  movements=[{
                                      'datetime': '2018-12-01',
                                      'source': {
                                          'name': 'test_source_name'
                                      },
                                      'destination': {
                                          'name': 'test_destination_name'
                                      }
                                  }],
                                  created_date='2019-01-07T12:00:00')
                     ])
        ]
    else:
        _lists = []
        for _list in lists:
            cards = []
            for card in _list['cards']:
                movements = []
                if card.get('movements'):
                    for movement in card.get('movements'):
                        movements.append({
                            'datetime':
                            get_datetime(movement['datetime']),
                            'source': {
                                'name': movement['source']
                            },
                            'destination': {
                                'name': movement['destination']
                            }
                        })

                cards.append(
                    MockCard(card['name'],
                             description=card.get('description'),
                             movements=movements,
                             created_date=card.get('created_date')))
            _lists.append(MockList(_list['name'], cards))

    mocker.patch("app.source.trello.TrelloClient", MockTrelloClient)