Skip to content

Commit 4cc60bd

Browse files
committed
bugzilla: Throw an error unless user explicitly sets url=None
The default of allowing an empty URL isn't friendly for new API users. Instead require users to explicitly opt in to skipping the initial URL connection, by setting url=None, since this is the far less common scenario
1 parent 77e9697 commit 4cc60bd

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

bugzilla/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,13 @@ def fix_url(url):
231231
url = url + '/xmlrpc.cgi'
232232
return url
233233

234-
def __init__(self, url=None, user=None, password=None, cookiefile=-1,
234+
def __init__(self, url=-1, user=None, password=None, cookiefile=-1,
235235
sslverify=True, tokenfile=-1):
236236
"""
237+
:param url: The bugzilla instance URL, which we will connect
238+
to immediately. Most users will want to specify this at
239+
__init__ time, but you can defer connecting by passing
240+
url=None and calling connect(URL) manually
237241
:param cookiefile: If -1, use the default path. If None, don't use
238242
or save any cookiefile.
239243
:param tokenfile: If -1, use the default path. If None, don't use
@@ -242,7 +246,10 @@ def __init__(self, url=None, user=None, password=None, cookiefile=-1,
242246
False to disable SSL verification, but it can also be a path
243247
to file or directory for custom certs.
244248
"""
245-
self._init_class_from_url(url, sslverify)
249+
if url is -1:
250+
raise TypeError("Specify a valid bugzilla url, or pass url=None")
251+
if url is not None:
252+
self._init_class_from_url(url, sslverify)
246253

247254
# Settings the user might want to tweak
248255
self.user = user or ''
@@ -277,8 +284,6 @@ def _init_class_from_url(self, url, sslverify):
277284
Detect if we should use RHBugzilla class, and if so, set it
278285
"""
279286
from bugzilla import RHBugzilla
280-
if url is None:
281-
return
282287

283288
url = self.fix_url(url)
284289
log.debug("Detecting subclass for %s", url)

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def make_bz(version, *args, **kwargs):
4747
kwargs["cookiefile"] = None
4848
if "tokenfile" not in kwargs:
4949
kwargs["tokenfile"] = None
50+
if "url" not in kwargs:
51+
kwargs["url"] = None
5052
bz = cls(*args, **kwargs)
5153
bz._set_bz_version(version) # pylint: disable=protected-access
5254
return bz

tests/bug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import sys
1414
import unittest
1515

16+
import tests
1617
from tests import StringIO
1718

18-
from bugzilla import RHBugzilla
1919
from bugzilla.bug import _Bug
2020

2121

22-
rhbz = RHBugzilla(cookiefile=None, tokenfile=None)
22+
rhbz = tests.make_bz("4.4.0", rhbz=True)
2323

2424

2525
class BugTest(unittest.TestCase):

tests/modify.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
import unittest
1313

14-
from bugzilla.rhbugzilla import RHBugzilla
15-
1614
import tests
1715

1816

19-
rhbz = RHBugzilla(cookiefile=None, tokenfile=None)
17+
rhbz = tests.make_bz("4.4.0", rhbz=True)
2018

2119

2220
class ModifyTest(unittest.TestCase):

0 commit comments

Comments
 (0)