File: test_remote_link.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 (147 lines) | stat: -rw-r--r-- 6,335 bytes parent folder | download | duplicates (2)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from __future__ import annotations

from jira.exceptions import JIRAError
from tests.conftest import JiraTestCase

DEFAULT_NEW_REMOTE_LINK_OBJECT = {"url": "http://google.com", "title": "googlicious!"}


class RemoteLinkTests(JiraTestCase):
    def setUp(self):
        JiraTestCase.setUp(self)
        self.issue_1 = self.test_manager.project_b_issue1
        self.issue_2 = self.test_manager.project_b_issue2
        self.issue_3 = self.test_manager.project_b_issue3
        self.project_b_issue1_obj = self.test_manager.project_b_issue1_obj

    def test_remote_links(self):
        self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
        )
        links = self.jira.remote_links(self.issue_1)
        self.assertEqual(len(links), 1)
        self.jira.remote_link(self.issue_1, links[0].id).delete()
        links = self.jira.remote_links(self.issue_2)
        self.assertEqual(len(links), 0)

    def test_remote_links_with_issue_obj(self):
        self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
        )
        links = self.jira.remote_links(self.project_b_issue1_obj)
        self.assertEqual(len(links), 1)
        self.jira.remote_link(self.issue_1, links[0].id).delete()
        links = self.jira.remote_links(self.project_b_issue1_obj)
        self.assertEqual(len(links), 0)

    def test_remote_link(self):
        added_link = self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        link = self.jira.remote_link(self.issue_1, added_link.id)
        self.assertEqual(link.id, added_link.id)
        self.assertTrue(hasattr(link, "globalId"))
        self.assertTrue(hasattr(link, "relationship"))
        self.assertTrue(hasattr(link, "application"))
        self.assertTrue(hasattr(link, "object"))

        link.delete()

    def test_remote_link_with_issue_obj(self):
        added_link = self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        link = self.jira.remote_link(self.project_b_issue1_obj, added_link.id)
        self.assertEqual(link.id, added_link.id)
        self.assertTrue(hasattr(link, "globalId"))
        self.assertTrue(hasattr(link, "relationship"))
        self.assertTrue(hasattr(link, "application"))
        self.assertTrue(hasattr(link, "object"))

        link.delete()

    def test_add_remote_link(self):
        link = self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        # creation response doesn't include full remote link info,
        #  so we fetch it again using the new internal ID
        link = self.jira.remote_link(self.issue_1, link.id)
        self.assertEqual(link.application.name, "far too silly")
        self.assertEqual(link.application.type, "sketch")
        self.assertEqual(link.object.url, DEFAULT_NEW_REMOTE_LINK_OBJECT["url"])
        self.assertEqual(link.object.title, DEFAULT_NEW_REMOTE_LINK_OBJECT["title"])
        self.assertEqual(link.relationship, "mousebending")
        self.assertEqual(link.globalId, "python-test:story.of.horse.riding")

        link.delete()

    def test_add_remote_link_with_issue_obj(self):
        link = self.jira.add_remote_link(
            self.project_b_issue1_obj,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        # creation response doesn't include full remote link info,
        #  so we fetch it again using the new internal ID
        link = self.jira.remote_link(self.project_b_issue1_obj, link.id)
        self.assertEqual(link.application.name, "far too silly")
        self.assertEqual(link.application.type, "sketch")
        self.assertEqual(link.object.url, DEFAULT_NEW_REMOTE_LINK_OBJECT["url"])
        self.assertEqual(link.object.title, DEFAULT_NEW_REMOTE_LINK_OBJECT["title"])
        self.assertEqual(link.relationship, "mousebending")
        self.assertEqual(link.globalId, "python-test:story.of.horse.riding")

        link.delete()

    def test_update_remote_link(self):
        link = self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        # creation response doesn't include full remote link info,
        #  so we fetch it again using the new internal ID
        link = self.jira.remote_link(self.issue_1, link.id)
        new_link = {"url": "http://yahoo.com", "title": "yahoo stuff"}
        link.update(
            object=new_link,
            globalId="python-test:updated.id",
            relationship="cheesing",
        )
        self.assertEqual(link.globalId, "python-test:updated.id")
        self.assertEqual(link.relationship, "cheesing")
        self.assertEqual(link.object.url, new_link["url"])
        self.assertEqual(link.object.title, new_link["title"])
        link.delete()

    def test_delete_remote_link(self):
        link = self.jira.add_remote_link(
            self.issue_1,
            destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
            globalId="python-test:story.of.horse.riding",
            application={"name": "far too silly", "type": "sketch"},
            relationship="mousebending",
        )
        _id = link.id
        link = self.jira.remote_link(self.issue_1, link.id)
        link.delete()
        self.assertRaises(JIRAError, self.jira.remote_link, self.issue_1, _id)