Skip to content

Commit 7798f81

Browse files
crazyscientistcrobinso
authored andcommitted
Set Bug.weburl that is compatible with the REST API (fixes python-bugzilla#178)
Instead of replacing the substring 'xmlrpc.cgi' in the Bugzilla URL, the URL is now constructed by explicitly using the `netloc` of the Bugzilla URL.
1 parent c6bfae5 commit 7798f81

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

bugzilla/bug.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import copy
88
from logging import getLogger
9+
from urllib.parse import urlparse, urlunparse
910

1011

1112
log = getLogger(__name__)
@@ -39,8 +40,16 @@ def __init__(self, bugzilla, bug_id=None, dict=None, autorefresh=False):
3940
dict["id"] = bug_id
4041

4142
self._update_dict(dict)
42-
self.weburl = bugzilla.url.replace('xmlrpc.cgi',
43-
'show_bug.cgi?id=%i' % self.bug_id)
43+
self.weburl = self._generate_weburl()
44+
45+
def _generate_weburl(self):
46+
"""
47+
Generate the URL to the bug in the web UI
48+
"""
49+
parsed = urlparse(self.bugzilla.url)
50+
return urlunparse((parsed.scheme, parsed.netloc,
51+
'show_bug.cgi', '', 'id=%s' % self.bug_id,
52+
''))
4453

4554
def __str__(self):
4655
"""

tests/data/clioutput/test_query2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ATTRIBUTE[target_milestone]: rc
5757
ATTRIBUTE[target_release]: ['---']
5858
ATTRIBUTE[url]:
5959
ATTRIBUTE[version]: ['5.8']
60-
ATTRIBUTE[weburl]: https:///TESTSUITEMOCK
60+
ATTRIBUTE[weburl]: https:///show_bug.cgi?id=1165434
6161
ATTRIBUTE[whiteboard]: genericwhiteboard
6262

6363

tests/test_api_bug.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,12 @@ def _get_fake_bug(apiname):
184184
attachments = bug.get_attachments()
185185
bug.attachments = attachments
186186
assert [469147, 470041, 502352] == bug.get_attachment_ids()
187+
188+
189+
def test_bug_weburl():
190+
fakebz = tests.mockbackend.make_bz(
191+
bug_get_args=None,
192+
bug_get_return="data/mockreturn/test_getbug_rhel.txt")
193+
bug_id = 1165434
194+
bug = fakebz.getbug(bug_id)
195+
assert bug.weburl == f"https:///show_bug.cgi?id={bug_id}"

0 commit comments

Comments
 (0)