Skip to content

Commit 4e1a2aa

Browse files
koystiKyösti Viinamäki
andauthored
JIRA issue properties (#1292)
* JIRA issue property methods * JIRA issue property docs * JIRA issue property docs * JIRA issue property tests * JIRA issue property: clean code --------- Co-authored-by: Kyösti Viinamäki <kyosti.viinamaki@op.fi>
1 parent 3bc66d0 commit 4e1a2aa

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed

atlassian/jira.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,38 @@ def get_issue_transitions_full(self, issue_key, transition_id=None, expand=None)
16861686
params["expand"] = expand
16871687
return self.get(url, params=params)
16881688

1689+
def get_issue_property_keys(self, issue_key):
1690+
"""
1691+
Get Property Keys on an Issue.
1692+
:param issue_key: Issue KEY
1693+
:raises: requests.exceptions.HTTPError
1694+
:return:
1695+
"""
1696+
base_url = self.resource_url("issue")
1697+
url = "{base_url}/{issue_key}/properties".format(base_url=base_url, issue_key=issue_key)
1698+
return self.get(url)
1699+
1700+
def set_issue_property(self, issue_key, property_key, data):
1701+
base_url = self.resource_url("issue")
1702+
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
1703+
base_url=base_url, issue_key=issue_key, propertyKey=property_key
1704+
)
1705+
return self.put(url, data=data)
1706+
1707+
def get_issue_property(self, issue_key, property_key):
1708+
base_url = self.resource_url("issue")
1709+
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
1710+
base_url=base_url, issue_key=issue_key, propertyKey=property_key
1711+
)
1712+
return self.get(url)
1713+
1714+
def delete_issue_property(self, issue_key, property_key):
1715+
base_url = self.resource_url("issue")
1716+
url = "{base_url}/{issue_key}/properties/{propertyKey}".format(
1717+
base_url=base_url, issue_key=issue_key, propertyKey=property_key
1718+
)
1719+
return self.delete(url)
1720+
16891721
def get_updated_worklogs(self, since, expand=None):
16901722
"""
16911723
Returns a list of IDs and update timestamps for worklogs updated after a date and time.

docs/jira.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,19 @@ Manage issues
331331
# Get change history for an issue
332332
jira.get_issue_changelog(issue_key)
333333
334+
# Get property keys from an issue
335+
jira.get_issue_property_keys(issue_key)
336+
337+
# Set issue property
338+
data = { "Foo": "Bar" }
339+
jira.set_issue_property(issue_key, property_key, data)
340+
341+
# Get issue property
342+
jira.get_issue_property(issue_key, property_key)
343+
344+
# Delete issue property
345+
jira.delete_issue_property(issue_key, property_key)
346+
334347
# Get worklog for an issue
335348
jira.issue_get_worklog(issue_key)
336349
@@ -339,6 +352,7 @@ Manage issues
339352
jira.issue_worklog(issue_key, started, time_in_sec)
340353
341354
355+
342356
Epic Issues
343357
-------------
344358

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
responses[None] = {
2+
"status_code": 204
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
responses[None] = {"key": "Bar1", "value": {"test.id": "123", "test.time": "1m"}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
responses['{"test.id": "123456", "test.mem": "250M"}'] = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
responses['{"test.id": "123456", "test.mem": "250M"}'] = {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
responses[None] = {
2+
"keys": [{"key": "Bar1", "self": "https://sample.atlassian.net/rest/api/2/issue/FOO-123/properties/Bar1"}]
3+
}

tests/test_jira.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,41 @@ def test_post_issue_expect_failed_authentication(self):
5454
"""Post an issue but receive a 401 error response"""
5555
with self.assertRaises(HTTPError):
5656
self.jira.create_issue(fields={"issuetype": "fail", "summary": "authentication", "project": "project"})
57+
58+
def test_get_issue_property_keys(self):
59+
"""Can retrieve issue property keys"""
60+
resp = self.jira.get_issue_property_keys("FOO-123")
61+
self.assertEqual(resp["keys"][0]["key"], "Bar1")
62+
self.assertEqual(
63+
resp["keys"][0]["self"], "https://sample.atlassian.net/rest/api/2/issue/FOO-123/properties/Bar1"
64+
)
65+
66+
def test_get_issue_property_keys_not_found(self):
67+
with self.assertRaises(HTTPError):
68+
self.jira.get_issue_property_keys("BAR-11")
69+
70+
def test_set_issue_property_create(self):
71+
self.jira.set_issue_property("FOO-123", "Bar2New", data={"test.id": "123456", "test.mem": "250M"})
72+
73+
def test_set_issue_property_update(self):
74+
self.jira.set_issue_property("FOO-123", "Bar1", data={"test.id": "123456", "test.mem": "250M"})
75+
76+
def test_get_issue_property(self):
77+
resp = self.jira.get_issue_property("FOO-123", "Bar1")
78+
self.assertEqual(resp["value"]["test.id"], "123")
79+
self.assertEqual(resp["value"]["test.time"], "1m")
80+
81+
def test_get_issue_property_not_found(self):
82+
with self.assertRaises(HTTPError):
83+
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
84+
with self.assertRaises(HTTPError):
85+
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")
86+
87+
def test_delete_issue_property(self):
88+
self.jira.delete_issue_property("FOO-123", "Bar1")
89+
90+
def test_delete_issue_property_not_found(self):
91+
with self.assertRaises(HTTPError):
92+
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
93+
with self.assertRaises(HTTPError):
94+
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")

0 commit comments

Comments
 (0)