File: test_comment.py

package info (click to toggle)
python-jira 3.10.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,024 kB
  • sloc: python: 8,877; sh: 13; makefile: 7; xml: 4
file content (127 lines) | stat: -rw-r--r-- 5,365 bytes parent folder | download
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
from __future__ import annotations

from tests.conftest import JiraTestCase


class CommentTests(JiraTestCase):
    def setUp(self):
        JiraTestCase.setUp(self)
        self.issue_1_key = self.test_manager.project_b_issue1
        self.issue_2_key = self.test_manager.project_b_issue2
        self.issue_3_key = self.test_manager.project_b_issue3

    def tearDown(self) -> None:
        for issue in [self.issue_1_key, self.issue_2_key, self.issue_3_key]:
            for comment in self.jira.comments(issue):
                comment.delete()

    def test_comments(self):
        for issue in [self.issue_1_key, self.jira.issue(self.issue_2_key)]:
            self.jira.issue(issue)
            comment1 = self.jira.add_comment(issue, "First comment")
            comment2 = self.jira.add_comment(issue, "Second comment")
            comments = self.jira.comments(issue)
            assert comments[0].body == "First comment"
            assert comments[1].body == "Second comment"
            comment1.delete()
            comment2.delete()
            comments = self.jira.comments(issue)
            assert len(comments) == 0

    def test_comments_start_at(self):
        comments_created = []
        for i in range(10):
            comments_created.append(
                self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
            )
        comments = self.jira.comments(self.issue_1_key, start_at=5)
        self.assertEqual(len(comments), 5)
        self.assertEqual(comments[0].body, "Comment #6")
        for comment in comments_created:
            comment.delete()
        comments = self.jira.comments(self.issue_1_key)
        assert len(comments) == 0

    def test_comments_max_results(self):
        comments_created = []
        for i in range(10):
            comments_created.append(
                self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
            )
        comments = self.jira.comments(self.issue_1_key, max_results=4)
        self.assertEqual(len(comments), 4)
        self.assertEqual(comments[0].body, "Comment #1")
        for comment in comments_created:
            comment.delete()
        comments = self.jira.comments(self.issue_1_key)
        assert len(comments) == 0

    def test_comments_order_by(self):
        comments_created = []
        for i in range(10):
            comments_created.append(
                self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
            )
        comments = self.jira.comments(self.issue_1_key, order_by="created")
        self.assertEqual(comments[0].body, "Comment #1")
        comments = self.jira.comments(self.issue_1_key, order_by="+created")
        self.assertEqual(comments[0].body, "Comment #1")
        comments = self.jira.comments(self.issue_1_key, order_by="-created")
        self.assertEqual(comments[0].body, "Comment #10")
        for comment in comments_created:
            comment.delete()
        comments = self.jira.comments(self.issue_1_key)
        assert len(comments) == 0

    def test_expanded_comments(self):
        comment1 = self.jira.add_comment(self.issue_1_key, "First comment")
        comment2 = self.jira.add_comment(self.issue_1_key, "Second comment")
        comments = self.jira.comments(self.issue_1_key, expand="renderedBody")
        self.assertTrue(hasattr(comments[0], "renderedBody"))
        ret_comment1 = self.jira.comment(
            self.issue_1_key, comment1.id, expand="renderedBody"
        )
        ret_comment2 = self.jira.comment(self.issue_1_key, comment2.id)
        comment1.delete()
        comment2.delete()
        self.assertTrue(hasattr(ret_comment1, "renderedBody"))
        self.assertFalse(hasattr(ret_comment2, "renderedBody"))
        comments = self.jira.comments(self.issue_1_key)
        assert len(comments) == 0

    def test_add_comment(self):
        comment = self.jira.add_comment(
            self.issue_3_key,
            "a test comment!",
            visibility={"type": "role", "value": "Administrators"},
        )
        self.assertEqual(comment.body, "a test comment!")
        self.assertEqual(comment.visibility.type, "role")
        self.assertEqual(comment.visibility.value, "Administrators")
        comment.delete()

    def test_add_comment_with_issue_obj(self):
        issue = self.jira.issue(self.issue_3_key)
        comment = self.jira.add_comment(
            issue,
            "a new test comment!",
            visibility={"type": "role", "value": "Administrators"},
        )
        self.assertEqual(comment.body, "a new test comment!")
        self.assertEqual(comment.visibility.type, "role")
        self.assertEqual(comment.visibility.value, "Administrators")
        comment.delete()

    def test_update_comment(self):
        comment = self.jira.add_comment(self.issue_3_key, "updating soon!")
        comment.update(body="updated!")
        assert comment.body == "updated!"
        # self.assertEqual(comment.visibility.type, 'role')
        # self.assertEqual(comment.visibility.value, 'Administrators')
        comment.delete()

    def test_update_comment_with_notify(self):
        comment = self.jira.add_comment(self.issue_3_key, "updating soon!")
        comment.update(body="updated! without notification", notify=False)
        assert comment.body == "updated! without notification"
        comment.delete()