From bf29a9391441bf290636b846491cb83ad6d96118 Mon Sep 17 00:00:00 2001 From: Yusuf-TJ <73256563+Yusuf-TJ@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:53:54 +0100 Subject: [PATCH] updated `jira.search_issues` default behaviour to include all fields (#1360) The `jira.search_issues` documentation states that when nothing is passed to the field parameter, all fields are returned. https://jira.readthedocs.io/api.html?highlight=search_issues#jira.client.JIRA.search_issues The "*all" has been set as the default field parameter to achieve this. --- jira/client.py | 4 +--- tests/resources/test_issue.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/jira/client.py b/jira/client.py index 9a341f201..a658cecb5 100644 --- a/jira/client.py +++ b/jira/client.py @@ -2870,7 +2870,7 @@ def search_issues( startAt: int = 0, maxResults: int = 50, validate_query: bool = True, - fields: Optional[Union[str, List[str]]] = None, + fields: Optional[Union[str, List[str]]] = "*all", expand: Optional[str] = None, json_result: bool = False, ) -> Union[List[Dict[str, Any]], ResultList[Issue]]: @@ -2895,8 +2895,6 @@ def search_issues( """ if isinstance(fields, str): fields = fields.split(",") - else: - fields = list(fields or []) # this will translate JQL field names to REST API Name # most people do know the JQL names so this will help them use the API easier diff --git a/tests/resources/test_issue.py b/tests/resources/test_issue.py index 85131f3d9..a1199ba0d 100644 --- a/tests/resources/test_issue.py +++ b/tests/resources/test_issue.py @@ -26,6 +26,29 @@ def test_issue(self): self.assertEqual(issue.key, self.issue_1) self.assertEqual(issue.fields.summary, "issue 1 from %s" % self.project_b) + def test_issue_search_finds_issue(self): + issues = self.jira.search_issues("key=%s" % self.issue_1) + self.assertEqual(self.issue_1, issues[0].key) + + def test_issue_search_return_type(self): + issues = self.jira.search_issues("key=%s" % self.issue_1) + self.assertIsInstance(issues, list) + issues = self.jira.search_issues("key=%s" % self.issue_1, json_result=True) + self.assertIsInstance(issues, dict) + + def test_issue_search_only_includes_provided_fields(self): + issues = self.jira.search_issues( + "key=%s" % self.issue_1, fields="comment,assignee" + ) + self.assertTrue(hasattr(issues[0].fields, "comment")) + self.assertTrue(hasattr(issues[0].fields, "assignee")) + self.assertFalse(hasattr(issues[0].fields, "reporter")) + + def test_issue_search_default_behaviour_included_fields(self): + issues = self.jira.search_issues("key=%s" % self.issue_1) + self.assertTrue(hasattr(issues[0].fields, "reporter")) + self.assertTrue(hasattr(issues[0].fields, "comment")) + def test_issue_get_field(self): issue = self.jira.issue(self.issue_1) self.assertEqual(