Skip to content

Commit

Permalink
Add client route for deleting remote links by global (and internal) id (
Browse files Browse the repository at this point in the history
#1395)

* Add client route for deleting remote links by global (and internal) id
___
Jannik Meinecke <jannik.meinecke@mercedes-benz.com> on behalf of MBition GmbH.
https://github.com/mercedes-benz/foss/blob/master/PROVIDER_INFORMATION.md
  • Loading branch information
rynkk authored Jun 29, 2022
1 parent 5515bf3 commit e811ac8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
31 changes: 31 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
import sys
import time
import urllib
import warnings
from collections import OrderedDict
from collections.abc import Iterable
Expand Down Expand Up @@ -3280,6 +3281,36 @@ def delete_user_avatar(self, username: str, avatar: str):
url = self._get_url("user/avatar/" + avatar)
return self._session.delete(url, params=params)

@translate_resource_args
def delete_remote_link(
self,
issue: Union[str, Issue],
*,
internal_id: Optional[str] = None,
global_id: Optional[str] = None,
) -> Response:
"""Delete remote link from issue by internalId or globalId.
Args:
issue (str): Key (or Issue) of Issue
internal_id (Optional[str]): InternalID of the remote link to delete
global_id (Optional[str]): GlobalID of the remote link to delete
Returns:
Response
"""
if not ((internal_id is None) ^ (global_id is None)):
raise ValueError("Must supply either 'internal_id' XOR 'global_id'.")

if internal_id is not None:
url = self._get_url(f"issue/{issue}/remotelink/{internal_id}")
elif global_id is not None:
# stop "&" and other special characters in global_id from messing around with the query
global_id = urllib.parse.quote(global_id, safe="")
url = self._get_url(f"issue/{issue}/remotelink?globalId={global_id}")

return self._session.delete(url)

def search_users(
self,
user: Optional[str] = None,
Expand Down
33 changes: 33 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,39 @@ def _calculate_calls_for_fetch_pages(
return call_list


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


class ClientRemoteLinkTests(JiraTestCase):
def setUp(self):
JiraTestCase.setUp(self)
self.issue_key = self.test_manager.project_b_issue1

def test_delete_remote_link_by_internal_id(self):
link = self.jira.add_remote_link(
self.issue_key,
destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
)
_id = link.id
self.jira.delete_remote_link(self.issue_key, internal_id=_id)
self.assertRaises(JIRAError, self.jira.remote_link, self.issue_key, _id)

def test_delete_remote_link_by_global_id(self):
link = self.jira.add_remote_link(
self.issue_key,
destination=DEFAULT_NEW_REMOTE_LINK_OBJECT,
globalId="python-test:story.of.sasquatch.riding",
)
_id = link.id
self.jira.delete_remote_link(
self.issue_key, global_id="python-test:story.of.sasquatch.riding"
)
self.assertRaises(JIRAError, self.jira.remote_link, self.issue_key, _id)

def test_delete_remote_link_with_invalid_args(self):
self.assertRaises(ValueError, self.jira.delete_remote_link, self.issue_key)


class WebsudoTests(JiraTestCase):
def test_kill_websudo(self):
self.jira.kill_websudo()
Expand Down

0 comments on commit e811ac8

Please sign in to comment.