Skip to content

Commit b60617a

Browse files
committed
tests: finish Bugzilla code coverage
Signed-off-by: Cole Robinson <[email protected]>
1 parent 650f40d commit b60617a

3 files changed

Lines changed: 74 additions & 7 deletions

File tree

bugzilla/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,6 @@ def _process_include_fields(self, include_fields, exclude_fields,
939939
Internal helper to process include_fields lists
940940
"""
941941
def _convert_fields(_in):
942-
if not _in:
943-
return _in
944-
945942
for newname, oldname in self._get_api_aliases():
946943
if oldname in _in:
947944
_in.remove(oldname)
@@ -1031,7 +1028,7 @@ def _getbugs(self, idlist, permissive,
10311028

10321029
if self._check_version(4, 0):
10331030
bugdict = dict([(b['id'], b) for b in r['bugs']])
1034-
else:
1031+
else: # pragma: no cover
10351032
bugdict = dict([(b['id'], b['internals']) for b in r['bugs']])
10361033

10371034
ret = []
@@ -1258,12 +1255,13 @@ def query(self, query):
12581255
r = self._backend.bug_search(query)
12591256
log.debug("bug_search returned:\n%s", str(r))
12601257
except Exception as e:
1261-
if not BugzillaError.get_bugzilla_error_code(e):
1262-
raise
1263-
12641258
# Try to give a hint in the error message if url_to_query
12651259
# isn't supported by this bugzilla instance
1260+
print("query_format" in str(e))
1261+
print(BugzillaError.get_bugzilla_error_code(e))
1262+
print(self._check_version(5, 0))
12661263
if ("query_format" not in str(e) or
1264+
not BugzillaError.get_bugzilla_error_code(e) or
12671265
self._check_version(5, 0)):
12681266
raise
12691267
raise BugzillaError("%s\nYour bugzilla instance does not "

tests/mockbackend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ def bug_attachment_get_all(self, *args):
5454
def bug_attachment_update(self, *args):
5555
return self.__helper(args)
5656

57+
def bug_comments(self, *args):
58+
return self.__helper(args)
5759
def bug_create(self, *args):
5860
return self.__helper(args)
5961
def bug_legal_values(self, *args):
6062
return self.__helper(args)
63+
def bug_history(self, *args):
64+
return self.__helper(args)
6165
def bug_get(self, *args):
6266
return self.__helper(args)
6367
def bug_fields(self, *args):

tests/test_api_misc.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,68 @@ def test_bad_scheme():
260260
bz.connect("ftp://example.com")
261261
except Exception as e:
262262
assert "Invalid URL scheme: ftp" in str(e)
263+
264+
265+
def test_update_flags():
266+
# update_flags is just a compat wrapper for update_bugs
267+
bz = tests.mockbackend.make_bz(
268+
bug_update_args="data/mockargs/test_update_flags.txt",
269+
bug_update_return={})
270+
bz.update_flags([12345, 6789], {"name": "needinfo", "status": "?"})
271+
272+
273+
def test_bugs_history_raw():
274+
# Stub test for bugs_history_raw
275+
ids = ["12345", 567]
276+
bz = tests.mockbackend.make_bz(
277+
bug_history_args={"ids": ids},
278+
bug_history_return={})
279+
bz.bugs_history_raw(ids)
280+
281+
282+
def test_get_comments():
283+
# Stub test for get_commands
284+
ids = ["12345", 567]
285+
bz = tests.mockbackend.make_bz(
286+
bug_comments_args={"ids": ids},
287+
bug_comments_return={})
288+
bz.get_comments(ids)
289+
290+
291+
def test_get_xmlrpc_proxy():
292+
# Ensure _proxy goes to a backend API
293+
bz = tests.mockbackend.make_bz()
294+
with pytest.raises(NotImplementedError):
295+
dummy = bz._proxy # pylint: disable=protected-access
296+
297+
298+
def test_query_url_fail():
299+
# test some handling of query from_url errors
300+
query = {"query_format": "advanced", "product": "FOO"}
301+
checkstr = "does not appear to support"
302+
303+
exc = bugzilla.BugzillaError("FAKEERROR query_format", code=123)
304+
bz = tests.mockbackend.make_bz(version="4.0.0",
305+
bug_search_args=None, bug_search_return=exc)
306+
try:
307+
bz.query(query)
308+
except Exception as e:
309+
assert checkstr in str(e)
310+
311+
bz = tests.mockbackend.make_bz(version="5.1.0",
312+
bug_search_args=None, bug_search_return=exc)
313+
try:
314+
bz.query(query)
315+
except Exception as e:
316+
assert checkstr not in str(e)
317+
318+
319+
def test_api_getbugs():
320+
fakebz = tests.mockbackend.make_bz(
321+
bug_get_args="data/mockargs/test_api_getbugs1.txt",
322+
bug_get_return="data/mockreturn/test_query_cve_getbug.txt")
323+
324+
fakebz.bug_autorefresh = True
325+
bug = fakebz.getbug("CVE-1234-5678", exclude_fields="foo")
326+
assert bug.alias == ["CVE-1234-5678"]
327+
assert bug.autorefresh is True

0 commit comments

Comments
 (0)