Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 bugzilla/_backendrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ def bug_fields(self, paramdict):
def bug_get(self, bug_ids, aliases, paramdict):
bug_list = listify(bug_ids)
alias_list = listify(aliases)
permissive = paramdict.pop("permissive", False)
data = paramdict.copy()

# FYI: The high-level API expects the backends to raise an exception
# when retrieval of a single bug fails (default behavior of the XMLRPC
# API), but the REST API simply returns an empty search result set.
# To ensure compliant behavior, the REST backend needs to use the
# explicit URL to get a single bug.
if len(bug_list or []) + len(alias_list or []) == 1:
if not permissive and len(bug_list or []) + len(alias_list or []) == 1:
for id_list in (bug_list, alias_list):
if id_list:
return self._get("/bug/%s" % id_list[0], data)
Expand Down
68 changes: 50 additions & 18 deletions 68 tests/test_backend_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,64 @@
from bugzilla._session import _BugzillaSession


def test_getbug():
session = _BugzillaSession(url="http://example.com",
class TestGetBug:
@property
def session(self):
return _BugzillaSession(url="http://example.com",
user_agent="py-bugzilla-test",
sslverify=False,
cert=None,
tokencache={},
api_key="",
is_redhat_bugzilla=False)
backend = _BackendREST(url="http://example.com",
bugzillasession=session)

def _assertion(self, *args):
self.assertion_called = True
assert args and args[0] == url
@property
def backend(self):
return _BackendREST(url="http://example.com",
bugzillasession=self.session)

setattr(backend, "_get", MethodType(_assertion, backend))
def test_getbug__not_permissive(self):
backend = self.backend

for _ids, aliases, url in (
(1, None, "/bug/1"),
([1], [], "/bug/1"),
(None, "CVE-1999-0001", "/bug/CVE-1999-0001"),
([], ["CVE-1999-0001"], "/bug/CVE-1999-0001"),
(1, "CVE-1999-0001", "/bug"),
):
backend.assertion_called = False
def _assertion(self, *args):
self.assertion_called = True
assert args and args[0] == url

backend.bug_get(_ids, aliases, {})
setattr(backend, "_get", MethodType(_assertion, backend))

assert backend.assertion_called is True
for _ids, aliases, url in (
(1, None, "/bug/1"),
([1], [], "/bug/1"),
(None, "CVE-1999-0001", "/bug/CVE-1999-0001"),
([], ["CVE-1999-0001"], "/bug/CVE-1999-0001"),
(1, "CVE-1999-0001", "/bug"),
([1, 2], None, "/bug")
):
backend.assertion_called = False

backend.bug_get(_ids, aliases, {})

assert backend.assertion_called is True

def test_getbug__permissive(self):
backend = self.backend

def _assertion(self, *args):
self.assertion_called = True
assert args and args[0] == url and args[1] == params

setattr(backend, "_get", MethodType(_assertion, backend))

for _ids, aliases, url, params in (
(1, None, "/bug", {"id": [1], "alias": None}),
([1], [], "/bug", {"id": [1], "alias": []}),
(None, "CVE-1999-0001", "/bug", {"alias": ["CVE-1999-0001"], "id": None}),
([], ["CVE-1999-0001"], "/bug", {"alias": ["CVE-1999-0001"], "id": []}),
(1, "CVE-1999-0001", "/bug", {"id": [1], "alias": ["CVE-1999-0001"]}),
([1, 2], None, "/bug", {"id": [1, 2], "alias": None})
):
backend.assertion_called = False

backend.bug_get(_ids, aliases, {"permissive": True})

assert backend.assertion_called is True
Morty Proxy This is a proxified and sanitized view of the page, visit original site.