Skip to content

Commit de36ffc

Browse files
committed
tests: Cover last remaining rhbz bits
1 parent afc2ad7 commit de36ffc

5 files changed

Lines changed: 53 additions & 5 deletions

File tree

bugzilla/rhbugzilla.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ def __init__(self, *args, **kwargs):
3535
@rhbz_back_compat: If True, convert parameters to the format they were
3636
in prior RHBZ upgrade in June 2012. Mostly this replaces lists
3737
with comma separated strings, and alters groups and flags.
38-
Default is False
38+
Default is False. Please don't use this in new code, just update
39+
your scripts.
40+
@multicall: Unused nowadays, will be removed in the future
3941
"""
4042
# 'multicall' is no longer used, just ignore it
41-
kwargs.pop("multicall", None)
43+
multicall = kwargs.pop("multicall", None)
4244
self.rhbz_back_compat = bool(kwargs.pop("rhbz_back_compat", False))
4345

46+
if multicall is not None:
47+
log.warn("multicall is unused and will be removed in a "
48+
"future release.")
49+
4450
if self.rhbz_back_compat:
4551
log.warn("rhbz_back_compat will be removed in a future release.")
4652

@@ -90,7 +96,7 @@ def get_sub_component():
9096

9197
if type(val) is not dict:
9298
component = self._listify(kwargs.get("component"))
93-
if component is []:
99+
if not component:
94100
raise ValueError("component must be specified if "
95101
"specifying sub_component")
96102
val = {component[0]: val}

tests/bug.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class BugTest(unittest.TestCase):
2828
def testBasic(self):
2929
data = {
3030
"bug_id": 123456,
31+
"status": "NEW",
32+
"assigned_to": "[email protected]",
3133
"component": "foo",
3234
"product": "bar",
3335
"short_desc": "some short desc",
@@ -52,6 +54,10 @@ def _assert_bug():
5254

5355
_assert_bug()
5456

57+
self.assertEqual(str(bug),
58+
"#123456 NEW - [email protected] - some short desc")
59+
self.assertTrue(repr(bug).startswith("<Bug #123456"))
60+
5561
# This triggers some code in __getattr__
5662
dir(bug)
5763

tests/misc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from __future__ import print_function
1313

1414
import atexit
15+
import logging
1516
import os
1617
import shutil
1718
import sys
@@ -156,3 +157,16 @@ def _testPostCompare(bz, indict, outexpect):
156157

157158
rhbz.rhbz_back_compat = True
158159
_testPostCompare(rhbz, test1, out_complex)
160+
161+
def testRHBZInit(self):
162+
# Just get us coverage when the extra values are specified
163+
level = bugzilla.log.level
164+
bugzilla.log.setLevel(logging.ERROR)
165+
bugzilla.RHBugzilla(None, cookiefile=None, multicall=True,
166+
rhbz_back_compat=True)
167+
bugzilla.log.setLevel(level)
168+
169+
def testUnimplementedAPI(self):
170+
bz3 = bugzilla.Bugzilla3(None, cookiefile=None)
171+
self.assertRaises(RuntimeError, bz3.getbugfields)
172+
self.assertRaises(RuntimeError, bz3.getqueryinfo)

tests/modify.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,7 @@ def testCC(self):
185185
def testSubComponents(self):
186186
self.clicomm("--component foo --sub-component 'bar baz'",
187187
{"component": "foo", "sub_components": {"foo": "bar baz"}})
188+
189+
def testSubComponentFail(self):
190+
self.assertRaises(ValueError, self.bz.build_update,
191+
sub_component="some sub component")

tests/query.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,38 @@ class RHBZTest(BZ4Test):
244244
'sub_components': ["Command-line tools (RHEL5)"]}
245245

246246
def testTranslation(self):
247+
def translate(_in):
248+
_out = copy.deepcopy(_in)
249+
self.bz.pre_translation(_out)
250+
return _out
251+
247252
in_query = {
248253
"fixed_in": "foo.bar",
249254
"product": "some-product",
250255
"cf_devel_whiteboard": "some_devel_whiteboard",
251256
"include_fields": ["fixed_in",
252257
"components", "cf_devel_whiteboard"],
253258
}
254-
out_query = copy.deepcopy(in_query)
255-
self.bz.pre_translation(out_query)
259+
out_query = translate(in_query)
256260

257261
in_query["include_fields"] = [
258262
"cf_devel_whiteboard", "cf_fixed_in", "component"]
259263
self.assertDictEqual(in_query, out_query)
260264

265+
in_query = {"bug_id": "123,456", "component": "foo,bar"}
266+
out_query = translate(in_query)
267+
self.assertEqual(out_query["id"], ["123", "456"])
268+
self.assertEqual(out_query["component"], ["foo", "bar"])
269+
270+
in_query = {"bug_id": [123, 124], "column_list": ["id"]}
271+
out_query = translate(in_query)
272+
self.assertEqual(out_query["id"], [123, 124])
273+
self.assertEqual(out_query["include_fields"], in_query["column_list"])
274+
275+
def testInvalidBoolean(self):
276+
self.assertRaises(RuntimeError, self.bz.build_query,
277+
boolean_query="foobar")
278+
261279

262280
class TestURLToQuery(BZ34Test):
263281
def _check(self, url, query):

0 commit comments

Comments
 (0)