Skip to content

Commit 794865f

Browse files
crobinsocrazyscientist
authored andcommitted
base: Add query_return_extra
This is like `query()`, but the return value is altered to be (buglist, values), where `values` is raw dictionary output from the API call, excluding the bug content. For example this may include a `limit` value if the bugzilla instance puts an implied limit on returned result numbers. bugzilla.redhat.com also has a custom extension to report `total_matches` for a query, which lets user know if the returned results are complete or not Signed-off-by: Cole Robinson <[email protected]>
1 parent 7359b33 commit 794865f

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

bugzilla/base.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,14 @@ def add_email(key, value, count):
13121312
self.pre_translation(query)
13131313
return query
13141314

1315-
def query(self, query):
1316-
"""
1317-
Pass search terms to bugzilla and and return a list of matching
1318-
Bug objects.
13191315

1320-
See `build_query` for more details about constructing the
1321-
`query` dict parameter.
1316+
def query_return_extra(self, query):
1317+
"""
1318+
Same as `query()`, but the return value is altered to be
1319+
(buglist, values), where `values` is raw dictionary output from
1320+
the API call, excluding the bug content. For example this may
1321+
include a `limit` value if the bugzilla instance puts an implied
1322+
limit on returned result numbers.
13221323
"""
13231324
try:
13241325
r = self._backend.bug_search(query)
@@ -1334,9 +1335,23 @@ def query(self, query):
13341335
"appear to support API queries derived from bugzilla "
13351336
"web URL queries." % e) from None
13361337

1337-
log.debug("Query returned %s bugs", len(r['bugs']))
1338-
return [Bug(self, dict=b,
1339-
autorefresh=self.bug_autorefresh) for b in r['bugs']]
1338+
rawbugs = r.pop("bugs")
1339+
log.debug("Query returned %s bugs", len(rawbugs))
1340+
bugs = [Bug(self, dict=b,
1341+
autorefresh=self.bug_autorefresh) for b in rawbugs]
1342+
1343+
return bugs, r
1344+
1345+
def query(self, query):
1346+
"""
1347+
Pass search terms to bugzilla and and return a list of matching
1348+
Bug objects.
1349+
1350+
See `build_query` for more details about constructing the
1351+
`query` dict parameter.
1352+
"""
1353+
bugs, dummy = self.query_return_extra(query)
1354+
return bugs
13401355

13411356
def pre_translation(self, query):
13421357
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{'bugs': [{'assigned_to_detail': {'real_name': 'Libvirt Maintainers', 'email': 'libvirt-maint', 'name': 'libvirt-maint', 'id': 311982}, 'summary': 'RFE: qemu: Support a managed autoconnect mode for host USB devices', 'status': 'NEW', 'assigned_to': 'Libvirt Maintainers', 'id': 508645}, {'assigned_to_detail': {'real_name': 'Cole Robinson', 'email': 'crobinso', 'name': 'crobinso', 'id': 199727}, 'summary': 'RFE: warn users at guest start if networks/storage pools are inactive', 'status': 'NEW', 'assigned_to': 'Cole Robinson', 'id': 668543}]}
1+
{'bugs': [{'assigned_to_detail': {'real_name': 'Libvirt Maintainers', 'email': 'libvirt-maint', 'name': 'libvirt-maint', 'id': 311982}, 'summary': 'RFE: qemu: Support a managed autoconnect mode for host USB devices', 'status': 'NEW', 'assigned_to': 'Libvirt Maintainers', 'id': 508645}, {'assigned_to_detail': {'real_name': 'Cole Robinson', 'email': 'crobinso', 'name': 'crobinso', 'id': 199727}, 'summary': 'RFE: warn users at guest start if networks/storage pools are inactive', 'status': 'NEW', 'assigned_to': 'Cole Robinson', 'id': 668543}], 'limit': 0, 'FOOFAKEVALUE': 'hello'}

tests/test_api_misc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,12 @@ def test_query_url_fail():
305305
bz.query(query)
306306
except Exception as e:
307307
assert checkstr not in str(e)
308+
309+
310+
def test_query_return_extra():
311+
bz = tests.mockbackend.make_bz(version="5.1.0",
312+
bug_search_args=None,
313+
bug_search_return="data/mockreturn/test_query1.txt")
314+
dummy, extra = bz.query_return_extra({})
315+
assert extra['limit'] == 0
316+
assert extra['FOOFAKEVALUE'] == "hello"

0 commit comments

Comments
 (0)