diff --git a/bugzilla/_backendrest.py b/bugzilla/_backendrest.py index 00b5563a..45bc4999 100644 --- a/bugzilla/_backendrest.py +++ b/bugzilla/_backendrest.py @@ -109,6 +109,7 @@ 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 @@ -116,7 +117,7 @@ def bug_get(self, bug_ids, aliases, paramdict): # 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) diff --git a/tests/test_backend_rest.py b/tests/test_backend_rest.py index fdfbd05b..14836975 100644 --- a/tests/test_backend_rest.py +++ b/tests/test_backend_rest.py @@ -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