-
Notifications
You must be signed in to change notification settings - Fork 686
/
Copy pathtest_jira.py
131 lines (110 loc) · 5.16 KB
/
test_jira.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# coding: utf8
"""Tests for Jira Modules"""
from unittest import TestCase
from atlassian import jira
from .mockup import mockup_server
from requests import HTTPError
class TestJira(TestCase):
def setUp(self):
self.jira = jira.Jira(f"{mockup_server()}/jira", username="username", password="password", cloud=True)
def test_get_issue(self):
"""Can retrieve an Issue by ID"""
resp = self.jira.issue("FOO-123")
self.assertEqual(resp["key"], "FOO-123")
def test_get_issue_not_found(self):
"""Receive HTTP Error when Issue does not exist"""
with self.assertRaises(HTTPError):
self.jira.issue("FOO-321")
def test_get_epic_issues(self):
resp = self.jira.epic_issues("BAR-22")
self.assertIsInstance(resp["issues"], list)
def test_get_epic_issues_not_found(self):
with self.assertRaises(HTTPError):
self.jira.epic_issues("BAR-11")
def test_get_issue_comments(self):
"""Can retrieve issue comments"""
resp = self.jira.issue_get_comments("FOO-123")
self.assertEqual(len(resp["comments"]), 2)
self.assertEqual(resp["total"], 2)
def test_get_issue_comment(self):
"""Can retrieve issue comments"""
resp = self.jira.issue_get_comment("FOO-123", 10000)
self.assertEqual(resp["body"], "Some Text comment")
self.assertEqual(resp["id"], "10000")
def test_get_issue_comment_not_found(self):
"""Get comment on issue by id, but not found"""
with self.assertRaises(HTTPError):
self.jira.epic_issues("BAR-11")
def test_post_issue_with_invalid_request(self):
"""Post an issue but receive a 400 error response"""
with self.assertRaises(HTTPError):
self.jira.create_issue(fields={"issuetype": "foo", "summary": "summary", "project": "project"})
def test_post_issue_expect_failed_authentication(self):
"""Post an issue but receive a 401 error response"""
with self.assertRaises(HTTPError):
self.jira.create_issue(fields={"issuetype": "fail", "summary": "authentication", "project": "project"})
def test_get_issue_property_keys(self):
"""Can retrieve issue property keys"""
resp = self.jira.get_issue_property_keys("FOO-123")
self.assertEqual(resp["keys"][0]["key"], "Bar1")
self.assertEqual(
resp["keys"][0]["self"], "https://sample.atlassian.net/rest/api/2/issue/FOO-123/properties/Bar1"
)
def test_get_issue_property_keys_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property_keys("BAR-11")
def test_set_issue_property_create(self):
self.jira.set_issue_property("FOO-123", "Bar2New", data={"test.id": "123456", "test.mem": "250M"})
def test_set_issue_property_update(self):
self.jira.set_issue_property("FOO-123", "Bar1", data={"test.id": "123456", "test.mem": "250M"})
def test_get_issue_property(self):
resp = self.jira.get_issue_property("FOO-123", "Bar1")
self.assertEqual(resp["value"]["test.id"], "123")
self.assertEqual(resp["value"]["test.time"], "1m")
def test_get_issue_property_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")
def test_delete_issue_property(self):
self.jira.delete_issue_property("FOO-123", "Bar1")
def test_delete_issue_property_not_found(self):
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOO-123", "NotFoundBar1")
with self.assertRaises(HTTPError):
self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1")
def test_post_issue_remotelink(self):
"""Create a new remote link"""
resp = self.jira.create_or_update_issue_remote_links(
"FOO-123",
"https://confluence.atlassian-python.atlassian.net/display/Test",
"Unused link text",
)
self.assertEqual(resp["id"], 10000)
self.assertEqual(
resp["self"], "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000"
)
self.assertDictEqual(resp["application"], {})
def test_post_issue_remotelink_confluence(self):
"""Create a new Confluence remote link"""
resp = self.jira.create_or_update_issue_remote_links(
"FOO-123",
"https://confluence.atlassian-python.atlassian.net/display/Test",
"Unused link text",
global_id="appId=00000000-0000-0000-0000-000000000000&pageId=0",
application={
"type": "com.atlassian.confluence",
"name": "Confluence",
},
)
self.assertEqual(resp["id"], 10000)
self.assertEqual(
resp["self"], "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000"
)
self.assertDictEqual(
resp["application"],
{
"type": "com.atlassian.confluence",
"name": "Confluence",
},
)