Skip to content

Commit b428676

Browse files
committed
tests: Centralize more Bugzilla init
This will help with future REST testing Signed-off-by: Cole Robinson <[email protected]>
1 parent 8a3f1ce commit b428676

2 files changed

Lines changed: 51 additions & 52 deletions

File tree

tests/test_ro_functional.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,35 @@
1616

1717
import pytest
1818

19-
from bugzilla import Bugzilla, BugzillaError, RHBugzilla
19+
from bugzilla import Bugzilla, BugzillaError
2020
import tests
2121

2222

2323
class BaseTest(unittest.TestCase):
2424
url = None
25-
bzclass = Bugzilla
2625
bzversion = (0, 0)
2726
closestatus = "CLOSED"
2827

28+
def _open_bz(self, **kwargs):
29+
if "use_creds" not in kwargs:
30+
kwargs["use_creds"] = False
31+
return Bugzilla(self.url, **kwargs)
32+
2933
def clicomm(self, argstr, expectexc=False, bz=None):
3034
comm = "bugzilla " + argstr
3135

3236
if not bz:
33-
bz = Bugzilla(url=self.url, use_creds=False)
37+
bz = self._open_bz()
3438
if expectexc:
3539
with pytest.raises(Exception):
3640
tests.clicomm(comm, bz)
3741
else:
3842
return tests.clicomm(comm, bz)
3943

4044
def _testBZVersion(self):
41-
bz = Bugzilla(self.url, use_creds=False)
42-
assert bz.__class__ == self.bzclass
4345
if tests.CLICONFIG.REDHAT_URL:
4446
return
47+
bz = self._open_bz()
4548
assert bz.bz_ver_major == self.bzversion[0]
4649
assert bz.bz_ver_minor == self.bzversion[1]
4750

@@ -129,10 +132,12 @@ def _testQueryURL(self, querystr, count, expectstr):
129132

130133

131134
class BZMozilla(BaseTest):
135+
url = "bugzilla.mozilla.org"
136+
132137
def testVersion(self):
133138
# bugzilla.mozilla.org returns version values in YYYY-MM-DD
134139
# format, so just try to confirm that
135-
bz = Bugzilla("bugzilla.mozilla.org", use_creds=False)
140+
bz = self._open_bz()
136141
assert bz.__class__ == Bugzilla
137142
assert bz.bz_ver_major >= 2016
138143
assert bz.bz_ver_minor in range(1, 13)
@@ -148,13 +153,13 @@ def testURLQuery(self):
148153
query_url = ("https://bugs.gentoo.org/buglist.cgi?"
149154
"component=[CS]&product=Doc%20Translations"
150155
"&query_format=advanced&resolution=FIXED")
151-
bz = Bugzilla(url=self.url, use_creds=False)
156+
bz = self._open_bz()
152157
ret = bz.query(bz.url_to_query(query_url))
153158
assert len(ret) > 0
154159

155160

156161
class BZGnome(BaseTest):
157-
url = "https://bugzilla.gnome.org/xmlrpc.cgi"
162+
url = "https://bugzilla.gnome.org"
158163
bzversion = (4, 4)
159164
closestatus = "RESOLVED"
160165

@@ -173,7 +178,7 @@ def testURLQuery(self):
173178
query_url = ("https://bugzilla.gnome.org/buglist.cgi?"
174179
"bug_status=RESOLVED&order=Importance&product=accerciser"
175180
"&query_format=advanced&resolution=NOTABUG")
176-
bz = Bugzilla(url=self.url, use_creds=False)
181+
bz = self._open_bz()
177182
try:
178183
bz.query(bz.url_to_query(query_url))
179184
except BugzillaError as e:
@@ -182,8 +187,7 @@ def testURLQuery(self):
182187

183188
class RHTest(BaseTest):
184189
url = (tests.CLICONFIG.REDHAT_URL or
185-
"https://bugzilla.redhat.com/xmlrpc.cgi")
186-
bzclass = RHBugzilla
190+
"https://bugzilla.redhat.com")
187191
bzversion = (5, 0)
188192

189193
test0 = BaseTest._testBZVersion
@@ -231,11 +235,11 @@ class RHTest(BaseTest):
231235
" CVE-2011-2527")
232236

233237
def testDoubleConnect(self):
234-
bz = self.bzclass(url=self.url)
238+
bz = self._open_bz()
235239
bz.connect(self.url)
236240

237241
def testQueryFlags(self):
238-
bz = self.bzclass(url=self.url)
242+
bz = self._open_bz()
239243
if not bz.logged_in:
240244
print("not logged in, skipping testQueryFlags")
241245
return
@@ -256,14 +260,14 @@ def testComponentsDetails(self):
256260
"""
257261
Fresh call to getcomponentsdetails should properly refresh
258262
"""
259-
bz = self.bzclass(url=self.url, use_creds=False)
263+
bz = self._open_bz()
260264
assert bool(bz.getcomponentsdetails("Red Hat Developer Toolset"))
261265

262266
def testGetBugAlias(self):
263267
"""
264268
getbug() works if passed an alias
265269
"""
266-
bz = self.bzclass(url=self.url, use_creds=False)
270+
bz = self._open_bz()
267271
bug = bz.getbug("CVE-2011-2527")
268272
assert bug.bug_id == 720773
269273

@@ -274,14 +278,14 @@ def testQuerySubComponent(self):
274278
assert "#1060931 " in out
275279

276280
def testBugFields(self):
277-
bz = self.bzclass(self.url, use_creds=False)
281+
bz = self._open_bz()
278282
fields = bz.getbugfields(names=["product"])[:]
279283
assert fields == ["product"]
280284
bz.getbugfields(names=["product", "bug_status"], force_refresh=True)
281285
assert set(bz.bugfields) == set(["product", "bug_status"])
282286

283287
def testBugAutoRefresh(self):
284-
bz = self.bzclass(self.url, use_creds=False)
288+
bz = self._open_bz()
285289

286290
bz.bug_autorefresh = True
287291

@@ -301,7 +305,7 @@ def testBugAutoRefresh(self):
301305
assert "adjust your include_fields" in str(e)
302306

303307
def testExtraFields(self):
304-
bz = self.bzclass(self.url, cookiefile=None, tokenfile=None)
308+
bz = self._open_bz()
305309

306310
# Check default extra_fields will pull in comments
307311
bug = bz.getbug(720773, exclude_fields=["product"])
@@ -329,9 +333,9 @@ def testActiveComps(self):
329333

330334
def testFaults(self):
331335
# Test special error wrappers in bugzilla/_cli.py
332-
bzinstance = Bugzilla(self.url, use_creds=False)
336+
bz = self._open_bz()
333337
out = tests.clicomm("bugzilla query --field=IDONTEXIST=FOO",
334-
bzinstance, expectfail=True)
338+
bz, expectfail=True)
335339
assert "Server error:" in out
336340

337341
out = tests.clicomm("bugzilla "

tests/test_rw_functional.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import pytest
2828

2929
import bugzilla
30-
from bugzilla import Bugzilla
3130
import tests
3231

3332

@@ -39,17 +38,11 @@ def _split_int(s):
3938

4039

4140
if not bugzilla.RHBugzilla(url=RHURL).logged_in:
42-
print("R/W tests require cached login credentials for url=%s" % RHURL)
41+
print("\nR/W tests require cached login credentials for url=%s\n" % RHURL)
4342
sys.exit(1)
4443

4544

4645
class RHPartnerTest(unittest.TestCase):
47-
# Despite its name, this instance is simply for bugzilla testing,
48-
# doesn't send out emails and is blown away occasionally. The front
49-
# page has some info.
50-
url = RHURL
51-
bzclass = bugzilla.RHBugzilla
52-
5346
def _check_have_admin(self, bz, funcname):
5447
# groupnames is empty for any user if our logged in user does not
5548
# have admin privs.
@@ -59,13 +52,16 @@ def _check_have_admin(self, bz, funcname):
5952
print("\nNo admin privs, reduced testing of %s" % funcname)
6053
return ret
6154

55+
def _open_bz(self, **kwargs):
56+
return bugzilla.RHBugzilla(url=RHURL, **kwargs)
57+
6258
def test0LoggedInNoCreds(self):
63-
bz = self.bzclass(url=self.url, use_creds=False)
59+
bz = self._open_bz(use_creds=False)
6460
assert not bz.logged_in
6561

6662
def test2(self):
67-
bz = Bugzilla(url=self.url, use_creds=False)
68-
assert bz.__class__ is self.bzclass
63+
bz = bugzilla.Bugzilla(RHURL, use_creds=False)
64+
assert bz.__class__ is bugzilla.RHBugzilla
6965

7066
def _makebug(self, bz):
7167
component = "python-bugzilla"
@@ -94,7 +90,7 @@ def test03NewBugBasic(self):
9490
"""
9591
Create a bug with minimal amount of fields, then close it
9692
"""
97-
bz = self.bzclass(url=self.url)
93+
bz = self._open_bz()
9894
bug = self._makebug(bz)
9995

10096
# Verify hasattr works
@@ -112,7 +108,7 @@ def test04NewBugAllFields(self):
112108
"""
113109
Create a bug using all 'new' fields, check some values, close it
114110
"""
115-
bz = self.bzclass(url=self.url)
111+
bz = self._open_bz()
116112

117113
summary = ("python-bugzilla test manyfields bug %s" %
118114
datetime.datetime.today())
@@ -176,7 +172,7 @@ def test05ModifyStatus(self):
176172
"""
177173
Modify status and comment fields for an existing bug
178174
"""
179-
bz = self.bzclass(url=self.url)
175+
bz = self._open_bz()
180176
bugid = "663674"
181177
cmd = "bugzilla modify %s " % bugid
182178

@@ -263,7 +259,7 @@ def test06ModifyEmails(self):
263259
"""
264260
Modify cc, assignee, qa_contact for existing bug
265261
"""
266-
bz = self.bzclass(url=self.url)
262+
bz = self._open_bz()
267263
bugid = "663674"
268264
cmd = "bugzilla modify %s " % bugid
269265

@@ -311,7 +307,7 @@ def test07ModifyMultiFlags(self):
311307
"""
312308
Modify flags and fixed_in for 2 bugs
313309
"""
314-
bz = self.bzclass(url=self.url)
310+
bz = self._open_bz()
315311
bugid1 = "461686"
316312
bugid2 = "461687"
317313
cmd = "bugzilla modify %s %s " % (bugid1, bugid2)
@@ -399,7 +395,7 @@ def cleardict_new(b):
399395
def test07ModifyMisc(self):
400396
bugid = "461686"
401397
cmd = "bugzilla modify %s " % bugid
402-
bz = self.bzclass(url=self.url)
398+
bz = self._open_bz()
403399
bug = bz.getbug(bugid)
404400

405401
# modify --dependson
@@ -501,7 +497,7 @@ def _test8Attachments(self):
501497
"""
502498
Get and set attachments for a bug
503499
"""
504-
bz = self.bzclass(url=self.url)
500+
bz = self._open_bz()
505501
cmd = "bugzilla attach "
506502
testfile = "../tests/data/bz-attach-get1.txt"
507503

@@ -552,7 +548,7 @@ def _test8Attachments(self):
552548
assert setbug.attachments[-1]["flags"] == []
553549

554550
# Set attachment obsolete
555-
bz._proxy.Bug.update_attachment({ # pylint: disable=protected-access
551+
bz._backend.bug_attachment_update({ # pylint: disable=protected-access
556552
"ids": [setbug.attachments[-1]["id"]],
557553
"is_obsolete": 1})
558554
setbug.refresh()
@@ -599,7 +595,7 @@ def _test8Attachments(self):
599595

600596

601597
def test09Whiteboards(self):
602-
bz = self.bzclass(url=self.url)
598+
bz = self._open_bz()
603599
bug_id = "663674"
604600
cmd = "bugzilla modify %s " % bug_id
605601
bug = bz.getbug(bug_id)
@@ -668,7 +664,7 @@ def fakegetpass(prompt):
668664
getpass.getpass = fakegetpass
669665

670666
try:
671-
cmd = "bugzilla --no-cache-credentials --bugzilla %s" % self.url
667+
cmd = "bugzilla --no-cache-credentials --bugzilla %s" % RHURL
672668
# Implied login with --username and --password
673669
ret = tests.clicomm("%s --user [email protected] "
674670
"--password foobar query -b 123456" % cmd,
@@ -700,7 +696,7 @@ def fakegetpass(prompt):
700696

701697
def test11UserUpdate(self):
702698
# This won't work if run by the same user we are using
703-
bz = self.bzclass(url=self.url)
699+
bz = self._open_bz()
704700
705701
group = "fedora_contrib"
706702

@@ -758,7 +754,7 @@ def test11UserUpdate(self):
758754

759755

760756
def test11ComponentEditing(self):
761-
bz = self.bzclass(url=self.url)
757+
bz = self._open_bz()
762758
component = ("python-bugzilla-testcomponent-%s" %
763759
str(random.randint(1, 1024 * 1024 * 1024)))
764760
basedata = {
@@ -831,8 +827,7 @@ def compare(data, newid):
831827
("You are not allowed" in str(e)))
832828

833829
def test12SetCookie(self):
834-
bz = self.bzclass(self.url,
835-
cookiefile=-1, tokenfile=None, configpaths=[])
830+
bz = self._open_bz(cookiefile=-1, tokenfile=None, configpaths=[])
836831

837832
try:
838833
bz.cookiefile = None
@@ -847,7 +842,7 @@ def test12SetCookie(self):
847842
assert not bz.logged_in
848843

849844
def test13SubComponents(self):
850-
bz = self.bzclass(url=self.url)
845+
bz = self._open_bz()
851846
# Long closed RHEL5 lvm2 bug. This component has sub_components
852847
bug = bz.getbug("185526")
853848
bug.autorefresh = True
@@ -865,18 +860,18 @@ def test13SubComponents(self):
865860
"Default / Unclassified (RHEL5)"]}
866861

867862
def test13ExternalTrackerQuery(self):
868-
bz = self.bzclass(url=self.url)
863+
bz = self._open_bz()
869864
with pytest.raises(RuntimeError):
870865
bz.build_external_tracker_boolean_query()
871866

872867
def _deleteAllExistingExternalTrackers(self, bugid):
873-
bz = self.bzclass(url=self.url)
868+
bz = self._open_bz()
874869
ids = [bug['id'] for bug in bz.getbug(bugid).external_bugs]
875870
if ids != []:
876871
bz.remove_external_tracker(ids=ids)
877872

878873
def test14ExternalTrackersAddUpdateRemoveQuery(self):
879-
bz = self.bzclass(url=self.url)
874+
bz = self._open_bz()
880875
bugid = 461686
881876
ext_bug_id = 380489
882877

@@ -922,14 +917,14 @@ def test14ExternalTrackersAddUpdateRemoveQuery(self):
922917
assert len(ids) == 0
923918

924919
def test15EnsureLoggedIn(self):
925-
bz = self.bzclass(url=self.url)
920+
bz = self._open_bz()
926921
comm = "bugzilla --ensure-logged-in query --bug_id 979546"
927922
tests.clicomm(comm, bz)
928923

929924
def test16ModifyTags(self):
930925
bugid = "461686"
931926
cmd = "bugzilla modify %s " % bugid
932-
bz = self.bzclass(url=self.url)
927+
bz = self._open_bz()
933928
bug = bz.getbug(bugid)
934929

935930
if bug.tags:
@@ -951,7 +946,7 @@ def test16ModifyTags(self):
951946

952947
def test17LoginAPIKey(self):
953948
api_key = "somefakeapikey1234"
954-
bz = self.bzclass(url=self.url, use_creds=False, api_key=api_key)
949+
bz = self._open_bz(use_creds=False, api_key=api_key)
955950
if bz.bz_ver_major < 5:
956951
self.skipTest("can only test apikey on bugzilla 5+")
957952

0 commit comments

Comments
 (0)