Skip to content

Commit e89676b

Browse files
committed
tests: add full RHBugzilla coverage
Signed-off-by: Cole Robinson <crobinso@redhat.com>
1 parent 114862b commit e89676b

7 files changed

Lines changed: 58 additions & 16 deletions

File tree

bugzilla/rhbugzilla.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,19 @@ def pre_translation(query):
7878
"""
7979
old = query.copy()
8080

81+
def split_comma(_v):
82+
if isinstance(_v, list):
83+
return _v
84+
return _v.split(",")
85+
8186
if 'bug_id' in query:
82-
if not isinstance(query['bug_id'], list):
83-
query['id'] = query['bug_id'].split(',')
84-
else:
85-
query['id'] = query['bug_id']
86-
del query['bug_id']
87+
query['id'] = split_comma(query.pop('bug_id'))
8788

8889
if 'component' in query:
89-
if not isinstance(query['component'], list):
90-
query['component'] = query['component'].split(',')
91-
92-
if 'include_fields' not in query and 'column_list' not in query:
93-
return
90+
query['component'] = split_comma(query['component'])
9491

95-
if 'include_fields' not in query:
96-
query['include_fields'] = []
97-
if 'column_list' in query:
98-
query['include_fields'] = query['column_list']
99-
del query['column_list']
92+
if 'include_fields' not in query and 'column_list' in query:
93+
query['include_fields'] = query.pop('column_list')
10094

10195
if old != query:
10296
log.debug("RHBugzilla pretranslated query to: %s", query)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#508645 NEW - Libvirt Maintainers - RFE: qemu: Support a managed autoconnect mode for host USB devices
2+
#668543 NEW - Cole Robinson - RFE: warn users at guest start if networks/storage pools are inactive
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{'cf_fixed_in': 'foofixedin',
2+
'component': 'lvm2',
3+
'ids': ['1165434'],
4+
'sub_components': {'lvm2': ['some-sub-component']}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{'component': ['foo', 'bar'],
2+
'id': ['1234', '2480'],
3+
'include_fields': ['assigned_to', 'id', 'status', 'summary'],
4+
'product': ['foo']}

tests/test_api_misc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ def _testPostCompare(bz, indict, outexpect):
8484
_testPostCompare(rhbz, test1, out_simple)
8585

8686

87+
def test_rhbz_pre_translation():
88+
bz = tests.mockbackend.make_bz(rhbz=True)
89+
input_query = {
90+
"bug_id": "12345,6789",
91+
"component": "comp1,comp2",
92+
"column_list": ["field1", "field8"],
93+
}
94+
95+
bz.pre_translation(input_query)
96+
output_query = {
97+
'component': ['comp1', 'comp2'],
98+
'id': ['12345', '6789'],
99+
'include_fields': ['field1', 'field8', 'id'],
100+
}
101+
102+
assert output_query == input_query
103+
104+
87105
def testSubComponentFail():
88106
bz = tests.mockbackend.make_bz(version="4.4.0", rhbz=True)
89107
with pytest.raises(ValueError):

tests/test_cli_modify.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_modify(run_cli):
3838
out = run_cli(cmd, fakebz)
3939
assert not out
4040

41-
# Modify with tricky opts
41+
# Modify with tricky opts hitting other API calls
4242
cmd = "bugzilla modify 1165434 "
4343
cmd += "--tags +addtag --tags=-rmtag "
4444
cmd += "--qa_whiteboard +yo-qa --qa_whiteboard=-foo "
@@ -53,3 +53,14 @@ def test_modify(run_cli):
5353
bug_get_return="data/mockreturn/test_getbug_rhel.txt")
5454
out = run_cli(cmd, fakebz)
5555
assert not out
56+
57+
# Modify hitting some rhbz paths
58+
cmd = "bugzilla modify 1165434 "
59+
cmd += "--fixed_in foofixedin "
60+
cmd += "--component lvm2 "
61+
cmd += "--sub-component some-sub-component"
62+
fakebz = tests.mockbackend.make_bz(rhbz=True,
63+
bug_update_args="data/mockargs/test_modify4.txt",
64+
bug_update_return={})
65+
out = run_cli(cmd, fakebz)
66+
assert not out

tests/test_cli_query.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def test_query(run_cli):
3434
out = run_cli(cmd, fakebz)
3535
tests.utils.diff_compare(out, "data/clioutput/test_query1.txt")
3636

37+
# Simple query with some comma opts
38+
cmd = "bugzilla query "
39+
cmd += "--product foo --component foo,bar --bug_id 1234,2480"
40+
fakebz = tests.mockbackend.make_bz(rhbz=True,
41+
bug_search_args="data/mockargs/test_query1-rhbz.txt",
42+
bug_search_return="data/mockreturn/test_query1.txt")
43+
out = run_cli(cmd, fakebz)
44+
tests.utils.diff_compare(out, "data/clioutput/test_query1-rhbz.txt")
45+
3746
# Same but with --ids output
3847
cmd = "bugzilla query --ids "
3948
cmd += "--product foo --component foo,bar --bug_id 1234,2480"

0 commit comments

Comments
 (0)