Skip to content

Commit

Permalink
tests: fill out API side of cli command coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Robinson <crobinso@redhat.com>
  • Loading branch information
crobinso committed Jan 10, 2020
1 parent d154649 commit 48797ca
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bugzilla/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,6 @@ def query(self, query):
# Try to give a hint in the error message if url_to_query
# isn't supported by this bugzilla instance
if ("query_format" not in str(e) or
"RHBugzilla" in str(e.__class__) or
self._check_version(5, 0)):
raise
raise BugzillaError("%s\nYour bugzilla instance does not "
Expand Down Expand Up @@ -1719,14 +1718,15 @@ def _validate_createbug(self, *args, **kwargs):
# Previous API required users specifying keyword args that mapped
# to the XMLRPC arg names. Maintain that bad compat, but also allow
# receiving a single dictionary like query() does
if kwargs and args:
if kwargs and args: # pragma: no cover
raise BugzillaError("createbug: cannot specify positional "
"args=%s with kwargs=%s, must be one or the "
"other." % (args, kwargs))
if args:
if len(args) > 1 or not isinstance(args[0], dict):
raise BugzillaError("createbug: positional arguments only "
"accept a single dictionary.")
raise BugzillaError( # pragma: no cover
"createbug: positional arguments only "
"accept a single dictionary.")
data = args[0]
else:
data = kwargs
Expand Down
2 changes: 2 additions & 0 deletions tests/data/clioutput/test_query2-rhbz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#508645 NEW - Libvirt Maintainers - RFE: qemu: Support a managed autoconnect mode for host USB devices
#668543 NEW - Cole Robinson - RFE: warn users at guest start if networks/storage pools are inactive
1 change: 1 addition & 0 deletions tests/data/mockargs/test_modify2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{'blocks': {'set': [123456, 445566]},
'comment': {'comment': 'some example comment', 'is_private': True},
'component': 'NEWCOMP',
'dupe_of': 555666,
'flags': [{'name': '-needinfo,+somethingels', 'status': 'e'}],
Expand Down
6 changes: 5 additions & 1 deletion tests/data/mockargs/test_new1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{'component': 'FOOCOMP',
{'blocks': ['12345', '6789'],
'cc': ['foo@example.com', 'bar@example.com'],
'comment_is_private': True,
'component': 'FOOCOMP',
'depends_on': ['dependme'],
'description': 'This is the first comment!\nWith newline & stuff.',
'groups': ['FOOGROUP', 'BARGROUP'],
'keywords': ['ADDKEY'],
Expand Down
18 changes: 16 additions & 2 deletions tests/data/mockargs/test_query1-rhbz.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{'component': ['foo', 'bar'],
{'cc': ['foo@example.com'],
'component': ['foo', 'bar'],
'field0-0-0': 'keywords',
'field1-0-0': 'cf_fixed_in',
'field2-0-0': 'cf_qa_whiteboard',
'id': ['1234', '2480'],
'include_fields': ['assigned_to', 'id', 'status', 'summary'],
'product': ['foo']}
'longdesc': 'some comment string',
'longdesc_type': 'allwordssubstr',
'product': ['foo'],
'qa_contact': 'qa@example.com',
'query_format': 'advanced',
'type0-0-0': 'substring',
'type1-0-0': 'substring',
'type2-0-0': 'substring',
'value0-0-0': 'fribkeyword',
'value1-0-0': 'amifixed',
'value2-0-0': 'some-example-whiteboard'}
5 changes: 5 additions & 0 deletions tests/data/mockargs/test_query2-rhbz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{'email1': ['foo@example.com'],
'emailcc1': True,
'emailtype1': 'BAR',
'include_fields': ['assigned_to', 'id', 'status', 'summary'],
'query_format': 'advanced'}
1 change: 1 addition & 0 deletions tests/data/mockargs/test_update_flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'flags': {'name': 'needinfo', 'status': '?'}, 'ids': [12345, 6789]}
8 changes: 7 additions & 1 deletion tests/test_api_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ def test_rhbz_pre_translation():
assert output_query == input_query


def testSubComponentFail():
def testUpdateFailures():
# sub_component without component also passed
bz = tests.mockbackend.make_bz(version="4.4.0", rhbz=True)
with pytest.raises(ValueError):
bz.build_update(sub_component="some sub component")

# Trying to update value that only rhbz supports
bz = tests.mockbackend.make_bz()
with pytest.raises(ValueError):
bz.build_update(fixed_in="some fixedin value")


def testCreatebugFieldConversion():
bz4 = tests.mockbackend.make_bz(version="4.0.0")
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_modify(run_cli):
cmd += "--flag=-needinfo,+somethingelse "
cmd += "--whiteboard =foo --whiteboard =thisone "
cmd += "--dupeid 555666 "
cmd += "--comment 'some example comment' --private "
fakebz = tests.mockbackend.make_bz(
bug_update_args="data/mockargs/test_modify2.txt",
bug_update_return={})
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def test_new(run_cli):
cmd = "bugzilla new --product FOOPROD --component FOOCOMP "
cmd += "--summary 'Hey this is the title!' "
cmd += "--comment 'This is the first comment!\nWith newline & stuff.' "
cmd += "--keywords ADDKEY --groups FOOGROUP,BARGROUP"
cmd += "--keywords ADDKEY --groups FOOGROUP,BARGROUP "
cmd += "--blocked 12345,6789 --cc foo@example.com --cc bar@example.com "
cmd += "--dependson dependme --private "

fakebz = tests.mockbackend.make_bz(
bug_create_args="data/mockargs/test_new1.txt",
Expand Down
16 changes: 14 additions & 2 deletions tests/test_cli_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,27 @@ def test_query(run_cli):
out = run_cli(cmd, fakebz)
tests.utils.diff_compare(out, "data/clioutput/test_query1.txt")

# Simple query with some comma opts
# RHBZ query with a ton of opts
cmd = "bugzilla query "
cmd += "--product foo --component foo,bar --bug_id 1234,2480"
cmd += "--product foo --component foo,bar --bug_id 1234,2480 "
cmd += "--keywords fribkeyword --fixed_in amifixed "
cmd += "--qa_whiteboard some-example-whiteboard "
cmd += "--cc foo@example.com --qa_contact qa@example.com "
cmd += "--comment 'some comment string' "
fakebz = tests.mockbackend.make_bz(rhbz=True,
bug_search_args="data/mockargs/test_query1-rhbz.txt",
bug_search_return="data/mockreturn/test_query1.txt")
out = run_cli(cmd, fakebz)
tests.utils.diff_compare(out, "data/clioutput/test_query1-rhbz.txt")

# --emailtype handling
cmd = "bugzilla query --cc foo@example.com --emailtype BAR "
fakebz = tests.mockbackend.make_bz(rhbz=True,
bug_search_args="data/mockargs/test_query2-rhbz.txt",
bug_search_return="data/mockreturn/test_query1.txt")
out = run_cli(cmd, fakebz)
tests.utils.diff_compare(out, "data/clioutput/test_query2-rhbz.txt")

# Same but with --ids output
cmd = "bugzilla query --ids "
cmd += "--product foo --component foo,bar --bug_id 1234,2480"
Expand Down

0 comments on commit 48797ca

Please sign in to comment.