Skip to content

Commit 50acd2e

Browse files
committed
tests: Fill out some more backend test coverage
Signed-off-by: Cole Robinson <crobinso@redhat.com>
1 parent ddfbc16 commit 50acd2e

5 files changed

Lines changed: 82 additions & 44 deletions

File tree

bugzilla/_backendrest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, url, bugzillasession):
3636
def _handle_response(self, text):
3737
try:
3838
ret = dict(json.loads(text))
39-
except Exception:
39+
except Exception: # pragma: no cover
4040
log.debug("Failed to parse REST response. Output is:\n%s", text)
4141
raise
4242

@@ -148,19 +148,19 @@ def component_create(self, paramdict):
148148
return self._post("/component", paramdict)
149149
def component_update(self, paramdict):
150150
if "ids" in paramdict:
151-
apiurl = str(listify(paramdict["ids"])[0])
151+
apiurl = str(listify(paramdict["ids"])[0]) # pragma: no cover
152152
if "names" in paramdict:
153153
apiurl = ("%(product)s/%(component)s" %
154154
listify(paramdict["names"])[0])
155155
return self._put("/component/%s" % apiurl, paramdict)
156156

157-
def externalbugs_add(self, paramdict):
157+
def externalbugs_add(self, paramdict): # pragma: no cover
158158
raise BugzillaError(
159159
"No REST API available yet for externalbugs_add")
160-
def externalbugs_remove(self, paramdict):
160+
def externalbugs_remove(self, paramdict): # pragma: no cover
161161
raise BugzillaError(
162162
"No REST API available yet for externalbugs_remove")
163-
def externalbugs_update(self, paramdict):
163+
def externalbugs_update(self, paramdict): # pragma: no cover
164164
raise BugzillaError(
165165
"No REST API available yet for externalbugs_update")
166166

@@ -187,7 +187,7 @@ def user_logout(self):
187187
def user_update(self, paramdict):
188188
urlid = None
189189
if "ids" in paramdict:
190-
urlid = listify(paramdict["ids"])[0]
190+
urlid = listify(paramdict["ids"])[0] # pragma: no cover
191191
if "names" in paramdict:
192192
urlid = listify(paramdict["names"])[0]
193193
return self._put("/user/%s" % urlid, paramdict)

bugzilla/_backendxmlrpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __request_helper(self, url, request_body):
4848
except RequestException as e:
4949
if not response:
5050
raise
51-
raise ProtocolError(
51+
raise ProtocolError( # pragma: no cover
5252
url, response.status_code, str(e), response.headers)
5353
except Fault:
5454
raise
@@ -75,7 +75,7 @@ def parse_response(self, response):
7575
msg = response.text.encode('utf-8')
7676
try:
7777
parser.feed(msg)
78-
except Exception:
78+
except Exception: # pragma: no cover
7979
log.debug("Failed to parse this XMLRPC response:\n%s", msg)
8080
raise
8181

tests/test_ro_functional.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ def test_rest_xmlrpc_detection():
5858
# See /rest in the URL, so use REST
5959
bz = _open_bz("bugzilla.redhat.com/rest")
6060
assert bz.is_rest()
61+
with pytest.raises(bugzilla.BugzillaError) as e:
62+
dummy = bz._proxy # pylint: disable=protected-access
63+
assert "raw XMLRPC access is not provided" in str(e)
6164

6265
# See /xmlrpc.cgi in the URL, so use XMLRPC
6366
bz = _open_bz("bugzilla.redhat.com/xmlrpc.cgi")
6467
assert bz.is_xmlrpc()
68+
assert bz._proxy # pylint: disable=protected-access
6569

6670

6771
def test_apikey_error_scraping():
@@ -80,6 +84,12 @@ def test_apikey_error_scraping():
8084
assert fakekey not in str(e.value)
8185

8286

87+
def test_xmlrpc_bad_url():
88+
with pytest.raises(bugzilla.BugzillaError) as e:
89+
_open_bz("https://example.com/#xmlrpc")
90+
assert "URL may not be an XMLRPC URL" in str(e)
91+
92+
8393
###################
8494
# mozilla testing #
8595
###################
@@ -288,8 +298,6 @@ def testGetBugAlias(backends):
288298
def testQuerySubComponent(run_cli, backends):
289299
bz = _open_bz(REDHAT_URL, **backends)
290300

291-
tests.utils.skip_if_rest(bz, "Not working on REST, not sure why yet")
292-
293301
# Test special error wrappers in bugzilla/_cli.py
294302
out = run_cli("bugzilla query --product 'Red Hat Enterprise Linux 7' "
295303
"--component lvm2 --sub-component 'Thin Provisioning'", bz)
@@ -306,6 +314,13 @@ def testBugFields(backends):
306314
assert set(bz.bugfields) == set(["product", "bug_status"])
307315

308316

317+
def testProductGetMisc(backends):
318+
bz = _open_bz(REDHAT_URL, **backends)
319+
320+
assert bz.product_get(ptype="enterable", include_fields=["id"])
321+
assert bz.product_get(ptype="selectable", include_fields=["name"])
322+
323+
309324
def testBugAutoRefresh(backends):
310325
bz = _open_bz(REDHAT_URL, **backends)
311326

@@ -381,6 +396,18 @@ def testFaults(run_cli, backends):
381396
assert "--nosslverify" in out
382397

383398

399+
def test_login_stubs(backends):
400+
bz = _open_bz(REDHAT_URL, **backends)
401+
402+
# Failed login, verifies our backends are calling the correct API
403+
with pytest.raises(bugzilla.BugzillaError) as e:
404+
bz.login("foo", "bar")
405+
assert "Login failed" in str(e)
406+
407+
# Works fine when not logged in
408+
bz.logout()
409+
410+
384411
def test_redhat_version(backends):
385412
bzversion = (5, 0)
386413
bz = _open_bz(REDHAT_URL, **backends)

tests/test_rw_functional.py

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,15 @@ def test11UserUpdate(backends):
747747
user.refresh()
748748
assert user.groupnames == origgroups
749749

750+
# Try user create
751+
try:
752+
name = "pythonbugzilla-%s" % datetime.datetime.today()
753+
bz.createuser(name + "@example.com", name, name)
754+
except Exception as e:
755+
if have_admin:
756+
raise
757+
assert "Sorry, you aren't a member" in str(e)
758+
750759

751760
def test11ComponentEditing(backends):
752761
bz = _open_bz(**backends)
@@ -798,10 +807,6 @@ def compare(data, newid):
798807
# bugzilla 5 error string
799808
("You are not allowed" in str(e)))
800809

801-
# bugzilla.redhat.com doesn't have REST editcomponent yet
802-
tests.utils.skip_if_rest(
803-
bz, "editcomponent not supported for redhat REST API")
804-
805810
# Edit component
806811
data = basedata.copy()
807812
data.update({
@@ -817,11 +822,15 @@ def compare(data, newid):
817822
if newid is not None:
818823
compare(data, newid)
819824
except Exception as e:
820-
if have_admin:
825+
if bz.is_rest():
826+
# redhat REST does not support component editing
827+
assert "A REST API resource was not found" in str(e)
828+
elif have_admin:
821829
raise
822-
assert (("Sorry, you aren't a member" in str(e)) or
823-
# bugzilla 5 error string
824-
("You are not allowed" in str(e)))
830+
else:
831+
assert (("Sorry, you aren't a member" in str(e)) or
832+
# bugzilla 5 error string
833+
("You are not allowed" in str(e)))
825834

826835

827836
def test13SubComponents(backends):
@@ -843,14 +852,10 @@ def test13SubComponents(backends):
843852
"Default / Unclassified (RHEL5)"]}
844853

845854

846-
def test14ExternalTrackersAddUpdateRemoveQuery(backends):
847-
bz = _open_bz(**backends)
855+
def _testExternalTrackers(bz):
848856
bugid = 461686
849857
ext_bug_id = 380489
850858

851-
tests.utils.skip_if_rest(
852-
bz, "unknown if REST API has externaltrackers support")
853-
854859
# Delete any existing external trackers to get to a known state
855860
ids = [bug['id'] for bug in bz.getbug(bugid).external_bugs]
856861
if ids != []:
@@ -895,6 +900,16 @@ def test14ExternalTrackersAddUpdateRemoveQuery(backends):
895900
assert len(ids) == 0
896901

897902

903+
def test14ExternalTrackersAddUpdateRemoveQuery(backends):
904+
bz = _open_bz(**backends)
905+
try:
906+
_testExternalTrackers(bz)
907+
except Exception as e:
908+
if not bz.is_rest():
909+
raise
910+
assert "No REST API available" in str(e)
911+
912+
898913
def test15EnsureLoggedIn(run_cli, backends):
899914
bz = _open_bz(**backends)
900915
comm = "bugzilla --ensure-logged-in query --bug_id 979546"
@@ -913,24 +928,27 @@ def test16ModifyTags(run_cli, backends):
913928
bz = _open_bz(**backends)
914929
bug = bz.getbug(bugid)
915930

916-
tests.utils.skip_if_rest(bz, "update_tags not supported for REST API")
931+
try:
932+
if bug.tags:
933+
bz.update_tags(bug.id, tags_remove=bug.tags)
934+
bug.refresh()
935+
assert bug.tags == []
917936

918-
if bug.tags:
919-
bz.update_tags(bug.id, tags_remove=bug.tags)
937+
run_cli(cmd + "--tags foo --tags +bar --tags baz", bz)
920938
bug.refresh()
921-
assert bug.tags == []
922-
923-
run_cli(cmd + "--tags foo --tags +bar --tags baz", bz)
924-
bug.refresh()
925-
assert bug.tags == ["foo", "bar", "baz"]
939+
assert bug.tags == ["foo", "bar", "baz"]
926940

927-
run_cli(cmd + "--tags=-bar", bz)
928-
bug.refresh()
929-
assert bug.tags == ["foo", "baz"]
941+
run_cli(cmd + "--tags=-bar", bz)
942+
bug.refresh()
943+
assert bug.tags == ["foo", "baz"]
930944

931-
bz.update_tags(bug.id, tags_remove=bug.tags)
932-
bug.refresh()
933-
assert bug.tags == []
945+
bz.update_tags(bug.id, tags_remove=bug.tags)
946+
bug.refresh()
947+
assert bug.tags == []
948+
except Exception as e:
949+
if not bz.is_rest():
950+
raise
951+
assert "No REST API available" in str(e)
934952

935953

936954
def test17LoginAPIKey(backends):

tests/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import shlex
1111
import sys
1212

13-
import pytest
14-
1513
import bugzilla._cli
1614

1715
import tests
@@ -52,11 +50,6 @@ def open_functional_bz(bzclass, url, kwargs):
5250
return bz
5351

5452

55-
def skip_if_rest(bz, msg):
56-
if bz.is_rest():
57-
pytest.skip(msg)
58-
59-
6053
def diff_compare(inputdata, filename, expect_out=None):
6154
"""Compare passed string output to contents of filename"""
6255
def _process(data):

0 commit comments

Comments
 (0)