Skip to content

Commit 0955d2e

Browse files
Include alias in include_fields (closes #170) (#186)
Include `alias` in `include_fields`, when the parameter for `getbug` is an alias (closes #170) Because the `_getbugs` method tries to return bug data in the same order as IDs and aliases are provided, the `alias` needs to be explicitly added to `include_fields`.
1 parent e158780 commit 0955d2e

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

bugzilla/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,11 @@ def _alias_or_int(_v):
10811081
else:
10821082
ids.append(idstr)
10831083

1084+
if (include_fields is not None and aliases
1085+
and "alias" not in include_fields):
1086+
# Extra field to prevent sorting (see below) from causing an error
1087+
include_fields.append("alias")
1088+
10841089
extra_fields = listify(extra_fields or [])
10851090
extra_fields += self._getbug_extra_fields()
10861091

tests/test_api_bug.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ def test_api_getbugs():
9494
assert fakebz.getbugs(["123456", "CVE-1234-FAKE"]) == []
9595

9696

97+
def test_getbug_alias():
98+
"""
99+
Test that `getbug(<alias>)` includes the alias in `include_fields`
100+
"""
101+
fakebz = tests.mockbackend.make_bz(
102+
bug_get_args=None,
103+
bug_get_return="data/mockreturn/test_query_cve_getbug.txt")
104+
bug = fakebz.getbug("CVE-1234-5678", include_fields=["id"])
105+
assert bug.alias == ["CVE-1234-5678"]
106+
assert bug.id == 123456
107+
108+
def mock_bug_get(bug_ids, aliases, paramdict):
109+
assert bug_ids == []
110+
assert aliases == ["CVE-1234-5678"]
111+
assert "alias" in paramdict.get("include_fields", [])
112+
return {"bugs": [bug.get_raw_data()]}
113+
114+
backend = getattr(fakebz, "_backend")
115+
setattr(backend, "bug_get", mock_bug_get)
116+
117+
fakebz.getbug("CVE-1234-5678", include_fields=["id"])
118+
119+
97120
def test_bug_getattr():
98121
fakebz = tests.mockbackend.make_bz(
99122
bug_get_args=None,

tests/test_ro_functional.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ def testGetBugAlias404(backends):
330330
raise AssertionError("No exception raised")
331331

332332

333+
def testGetBugAliasIncludedField(backends):
334+
bz = _open_bz(REDHAT_URL, **backends)
335+
336+
bug = bz.getbug("CVE-2011-2527", include_fields=["id"])
337+
assert bug.bug_id == 720773
338+
339+
333340
def testQuerySubComponent(run_cli, backends):
334341
bz = _open_bz(REDHAT_URL, **backends)
335342

0 commit comments

Comments
 (0)