コード例 #1
0
    def test_if_storypoints_can_be_retrieved_from_a_jira_issue(self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        mocked_jira_issue = MockedJiraIssue(story_points=100)
        mocked_jira_issue2 = MockedJiraIssue()
        mocked_jira_epic = MockedJiraIssue()
        mocked_jira_epic.key = "PROJ001-001"
        self.jira_client.search_issues.return_value = [
            mocked_jira_issue2, mocked_jira_issue
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_storypoints_from_epic(mocked_jira_epic)

        # Then
        self.jira_client.fields.assert_called_once()

        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = " + "PROJ001-001",
            fields=["customfield_10282", "status"],
            maxResults=0)

        self.assertEqual({"total": 100, "Reported": 100}, result)
コード例 #2
0
    def test_if_storypoints_custom_field_is_unknown_we_get_it_first_via_the_fields_getter(
            self):
        # Given

        self.jira_client.fields.return_value = [
            {
                "id": "customfield_11280",
                "name": "Release Note",
                "custom": True,
                "orderable": True,
                "navigable": True,
                "searchable": True,
                "clauseNames": ["cf[11280]", "Release Note"],
                "schema": {
                    "type": "option",
                    "custom":
                    "com.atlassian.jira.plugin.system.customfieldtypes:select",
                    "customId": 11280
                },
            },
            {
                "id": "customfield_10333",
                "name": "Story Points",
                "custom": True,
                "orderable": True,
                "navigable": True,
                "searchable": True,
                "clauseNames": ["cf[10333]", "Story Points"],
                "schema": {
                    "type": "number",
                    "custom":
                    "com.atlassian.jira.plugin.system.customfieldtypes:float",
                    "customId": 10333
                },
            },
        ]
        mocked_jira_issue = MockedJiraIssue()
        mocked_jira_issue.fields.customfield_10333 = 100
        mocked_jira_issue2 = MockedJiraIssue()
        mocked_jira_issue2.fields.customfield_10333 = 0
        self.jira_client.search_issues.return_value = [
            mocked_jira_issue2, mocked_jira_issue
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.jira_client.fields.assert_called_once()

        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = " + "PROJ001-001",
            fields=["customfield_10333", "status"],
            maxResults=0)

        self.assertEqual({"total": 100, "Reported": 100}, result)
コード例 #3
0
    def test_setting_a_label_for_all_sub_items(self):
        # Given
        sub_story = MockedJiraIssue()
        self.jira_client.search_issues.return_value = [
            sub_story,
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.add_labels_to_all_sub_items_of_epic("PROJ001-001",
                                                ["label_to_set"])

        # Then
        sub_story.add_field_value.assert_called_with("labels", "label_to_set")
コード例 #4
0
    def test_setting_a_label_for_all_sub_items_retrieves_only_the_label_fields(
            self):
        # Given
        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        sub_story = MockedJiraIssue()
        self.jira_client.search_issues.return_value = [
            sub_story,
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.add_labels_to_all_sub_items_of_epic("PROJ001-001",
                                                ["label_to_set"])

        # Then
        self.jira_client.search_issues.assert_called_with(
            f"'Epic Link' = PROJ001-001", fields=["labels"], maxResults=0)
コード例 #5
0
    def test_ranking_by_list_calls_the_jira_client_in_the_proper_order(self):
        # Given
        jira_client = Mock(spec=jira.JIRA)
        ranked_list = MOCKED_JIRA_ISSUE_PS_Y_
        on_top_of = mocked_issue_4

        jat = JiraAgileToolBox(jira_client)

        # When
        jat.rank_issues_by_list(ranked_list, on_top_of)

        # Then
        jira_client.rank.assert_has_calls([
            call(mocked_issue_3.key, mocked_issue_4.key),
            call(mocked_issue_2.key, mocked_issue_3.key),
            call(mocked_issue_1.key, mocked_issue_2.key),
        ])
コード例 #6
0
    def test_get_story_points_from_epic_calculates_the_total_of_zero_story_point_when_none_are_assigned(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=None),
            MockedJiraIssue(),
            MockedJiraIssue(),
        ] * 1000
        jat = JiraAgileToolBox(self.jira_client)

        # When
        sps = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.assertEqual(0, sps["total"])
コード例 #7
0
    def test_get_story_points_from_epic_calculates_the_total_story_pointS_for_3_issues(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        sps = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.assertEqual(3, sps["total"])
コード例 #8
0
    def test_copy_fix_version_from_epic_to_all_items_in_epic(self):
        # Given
        sub_issue1 = MockedJiraIssue(story_points=0)
        version1 = Mock(spec=jira.resources.Version)
        version1.name = "JAT 0.0.9"
        epic = MockedJiraIssue()
        epic.fields.fixVersions = [version1]
        epic.key = "PROJ001-001"
        self.jira_client.search_issues.return_value = [sub_issue1]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.copy_fix_version_from_epic_to_all_items_in_epic(epic)

        # Then
        sub_issue1.add_field_value.assert_called_with("fixVersions",
                                                      {"name": version1.name})
コード例 #9
0
    def test_get_story_points_from_epic_returns_a_dict_containing_the_total_story_points(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.assertIn("total", result.keys())
コード例 #10
0
    def test_get_issues_from_epic_searches_for_the_right_epic_key(self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_all_issues_in_epic("PROJ001-001")

        # Then
        self.assertEqual(self.jira_client.search_issues.return_value, result)
        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = PROJ001-001", maxResults=0)
コード例 #11
0
    def test_setting_a_label_for_all_sub_items_will_remove_already_present_labels(
            self):
        # Given
        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        sub_story = MockedJiraIssue()
        self.jira_client.search_issues.return_value = [
            sub_story,
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.add_labels_to_all_sub_items_of_epic("PROJ001-001",
                                                ["label_to_set"],
                                                keep_already_present=False)

        # Then
        sub_story.update.assert_called_with(
            fields={"labels": ["label_to_set"]})
コード例 #12
0
    def test_copy_fix_version_from_epic_to_all_items_in_epic_searches_for_the_epic(
            self):
        # Given
        sub_issue1 = MockedJiraIssue(story_points=0)
        version1 = Mock(spec=jira.resources.Version)
        version1.name = "JAT 0.0.9"
        epic = MockedJiraIssue()
        epic.fields.fixVersions = [version1]
        epic.key = "PROJ001-001"
        self.jira_client.search_issues.return_value = [sub_issue1]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.copy_fix_version_from_epic_to_all_items_in_epic(epic)

        # Then
        self.jira_client.search_issues.assert_called_with(
            f"'Epic Link' = {epic.key}", fields=["fixVersions"], maxResults=0)
コード例 #13
0
    def test_get_issues_from_epic_takes_a_string_field_or_a_list_of_fields(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.get_all_issues_in_epic("PROJ001-001", fields="a_specific_field")

        # Then
        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = PROJ001-001",
            fields=["a_specific_field"],
            maxResults=0)
コード例 #14
0
    def test_get_issues_from_epic_can_filter_on_the_fields_to_retrieve_to_reduce_data_retrieval(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.get_all_issues_in_epic("PROJ001-001", fields=["a_specific_field"])

        # Then
        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = PROJ001-001",
            fields=["a_specific_field"],
            maxResults=0)
コード例 #15
0
    def test_setting_a_label_for_all_sub_items_passes_on_the_jql_query(self):
        # Given
        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        sub_story = MockedJiraIssue()
        self.jira_client.search_issues.return_value = [
            sub_story,
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        epic = "PROJ001-001"
        jql_query = "project in (PROJ001,PROJ002)"
        jat.add_labels_to_all_sub_items_of_epic(epic, ["label_to_set"],
                                                jql_query=jql_query)

        # Then
        self.jira_client.search_issues.assert_called_with(
            f"'Epic Link' = {epic} AND {jql_query}",
            fields=["labels"],
            maxResults=0)
コード例 #16
0
    def test_get_story_points_from_epic_looks_in_jira_for_all_children_of_the_epic(
            self):
        # Given
        jira_client = Mock()
        jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(jira_client)

        # When
        jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        jira_client.search_issues.assert_called_with(
            "'Epic Link' = " + "PROJ001-001",
            fields=["customfield_10282", "status"],
            maxResults=0)
コード例 #17
0
    def test_get_story_points_from_epic_returns_a_dict_containing_the_found_statuses_as_keyword(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(0, "Reported"),
            MockedJiraIssue(1, "Investigated"),
            MockedJiraIssue(2, "Closed"),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.assertIn("Reported", result.keys())
        self.assertIn("Investigated", result.keys())
        self.assertIn("Closed", result.keys())
        self.assertNotIn("In Progress", result.keys())
コード例 #18
0
    def test_get_issues_from_epic_allows_to_filter_an_extra_jql_query(self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        jat.get_all_issues_in_epic("PROJ001-001",
                                   fields="a_specific_field",
                                   jql_query="project in (PROJ001,PROJ002)")

        # Then
        self.jira_client.search_issues.assert_called_with(
            "'Epic Link' = PROJ001-001 AND project in (PROJ001,PROJ002)",
            fields=["a_specific_field"],
            maxResults=0)
コード例 #19
0
    def test_ranking_at_the_top_of_the_backlog_searches_for_the_highest_ranked_issue(
            self):
        jira_client = Mock()

        ranked_list = MOCKED_JIRA_ISSUE_PS_Y_ + [mocked_issue_4]

        jira_client.search_issues = Mock(return_value=ranked_list)

        project = "PsY"

        jat = JiraAgileToolBox(jira_client)

        # When
        jat.rank_issues_at_top_of_project(MOCKED_JIRA_ISSUE_PS_Y_, project)

        # Then
        jira_client.rank.assert_has_calls([
            call(mocked_issue_3.key, mocked_issue_4.key),
            call(mocked_issue_2.key, mocked_issue_3.key),
            call(mocked_issue_1.key, mocked_issue_2.key),
        ])
コード例 #20
0
    def test_ranking_by_list_calls_the_jira_client_in_the_proper_order(self):
        # Given
        jira_client = Mock()
        ranked_list = [
            MockedJiraIssue("PY-001"),
            MockedJiraIssue("PY-002"),
            MockedJiraIssue("PY-003")
        ]
        on_top_of = MockedJiraIssue("PY-100")

        jat = JiraAgileToolBox(jira_client)

        # When
        jat.rank_issues_by_list(ranked_list, on_top_of)

        # Then
        jira_client.rank.assert_has_calls([
            call("PY-003", "PY-100"),
            call("PY-002", "PY-003"),
            call("PY-001", "PY-002")
        ])
コード例 #21
0
    def test_get_story_points_from_epic_looks_in_jira_for_all_children_of_the_epic_passes_on_a_jql_query(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(story_points=0),
            MockedJiraIssue(story_points=1),
            MockedJiraIssue(story_points=2),
        ]
        jat = JiraAgileToolBox(self.jira_client)
        epic = "PROJ001-001"
        jql_query = "project in (PROJ001,PROJ002)"

        # When
        jat.get_storypoints_from_epic(epic, jql_query=jql_query)

        # Then
        self.jira_client.search_issues.assert_called_with(
            f"'Epic Link' = {epic} AND {jql_query}",
            fields=["customfield_10282", "status"],
            maxResults=0)
コード例 #22
0
    def test_setting_a_label_for_all_sub_items_raises_an_exception_on_a_label_with_a_space(
            self):
        # Given
        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        sub_story = MockedJiraIssue(labels=["some_other_label"])
        self.jira_client.search_issues.return_value = [
            sub_story,
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        self.assertRaisesRegex(ValueError, "no spaces are allowed in labels",
                               jat.add_labels_to_all_sub_items_of_epic,
                               "PROJ001-001", ["label_to set"])
        sub_story.update.assert_not_called()
コード例 #23
0
    def test_get_story_points_from_epic_returns_a_dict_containing_the_found_statuses_with_their_totals(
            self):
        # Given

        self.jira_client.fields.return_value = DEFAULT_FIELDS_RETURN_VALUE
        self.jira_client.search_issues.return_value = [
            MockedJiraIssue(0, "Reported"),
            MockedJiraIssue(1, "Investigated"),
            MockedJiraIssue(1, "Closed"),
            MockedJiraIssue(1, "Closed"),
        ]
        jat = JiraAgileToolBox(self.jira_client)

        # When
        result = jat.get_storypoints_from_epic("PROJ001-001")

        # Then
        self.assertEqual(
            {
                "total": 3,
                "Reported": 0,
                "Investigated": 1,
                "Closed": 2
            }, result)