Skip to content

Commit a303fa0

Browse files
committed
tests: Add unit test case for bug attr handling
1 parent 8600e6b commit a303fa0

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

bugzilla/bug.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def __repr__(self):
6666
def __getattr__(self, name):
6767
refreshed = False
6868
while True:
69-
if name in self.__dict__:
69+
if refreshed and name in self.__dict__:
70+
# If name was in __dict__ to begin with, __getattr__ would
71+
# have never been called.
7072
return self.__dict__[name]
7173

7274
# Check field aliases
@@ -94,15 +96,6 @@ def __getattr__(self, name):
9496

9597
raise AttributeError("Bug object has no attribute '%s'" % name)
9698

97-
def __hasattr__(self, name):
98-
if name in self.__dict__:
99-
return True
100-
101-
for newname, oldname in self.bugzilla.field_aliases:
102-
if name == oldname and newname in self.__dict__:
103-
return True
104-
return False
105-
10699
def __getstate__(self):
107100
sd = self.__dict__
108101
if self.bugzilla:

tests/bug.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Copyright Red Hat, Inc. 2014
3+
#
4+
# This work is licensed under the terms of the GNU GPL, version 2 or later.
5+
# See the COPYING file in the top-level directory.
6+
#
7+
8+
'''
9+
Unit tests for testing some bug.py magic
10+
'''
11+
12+
import unittest
13+
14+
from bugzilla import RHBugzilla
15+
from bugzilla.bug import _Bug
16+
17+
import tests
18+
19+
20+
rhbz = RHBugzilla(cookiefile=None)
21+
22+
23+
class BugTest(unittest.TestCase):
24+
maxDiff = None
25+
bz = rhbz
26+
27+
def testBasic(self):
28+
data = {
29+
"bug_id": 123456,
30+
"component": "foo",
31+
"product": "bar",
32+
"short_desc": "some short desc",
33+
"cf_fixed_in": "nope",
34+
"fixed_in": "1.2.3.4",
35+
"devel_whiteboard": "some status value",
36+
}
37+
38+
bug = _Bug(bugzilla=self.bz, dict=data)
39+
40+
self.assertEqual(hasattr(bug, "component"), True)
41+
self.assertEqual(getattr(bug, "components"), ["foo"])
42+
self.assertEqual(getattr(bug, "product"), "bar")
43+
self.assertEqual(hasattr(bug, "short_desc"), True)
44+
self.assertEqual(getattr(bug, "summary"), "some short desc")
45+
self.assertEqual(bool(getattr(bug, "cf_fixed_in")), True)
46+
self.assertEqual(getattr(bug, "fixed_in"), "1.2.3.4")
47+
self.assertEqual(bool(getattr(bug, "cf_devel_whiteboard")), True)
48+
self.assertEqual(getattr(bug, "devel_whiteboard"), "some status value")
49+
50+
# This triggers some code in __getattr__
51+
dir(bug)

0 commit comments

Comments
 (0)