changeset 25:cf3583d9bf07

fixed bool bug
author Atul Varma <avarma@mozilla.com>
date Wed, 14 Jul 2010 17:22:25 -0700
parents 96f841399b40
children 8d0d0339d878
files bugzilla.py test_bugzilla.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/bugzilla.py	Thu Apr 22 16:35:27 2010 -0700
+++ b/bugzilla.py	Wed Jul 14 17:22:25 2010 -0700
@@ -191,7 +191,9 @@
                                "%s object" % (name,
                                               self.__class__.__name__))
             if proptype == bool:
-                if jsonobj[name] == '0':
+                if isinstance(jsonobj[name], bool):
+                    setattr(self, name, jsonobj[name])
+                elif jsonobj[name] == '0':
                     setattr(self, name, False)
                 elif jsonobj[name] == '1':
                     setattr(self, name, True)
--- a/test_bugzilla.py	Thu Apr 22 16:35:27 2010 -0700
+++ b/test_bugzilla.py	Wed Jul 14 17:22:25 2010 -0700
@@ -85,8 +85,14 @@
 del globname
 
 class Tests(unittest.TestCase):
-    # TODO: Add unit tests here.
-    pass
+    def test_bool(self):
+        class Foo(bugzilla.BugzillaObject):
+            __bzprops__ = {'foo': bool}
+
+        self.assertEqual(Foo({'foo': True}, None).foo, True)
+        self.assertEqual(Foo({'foo': False}, None).foo, False)
+        self.assertEqual(Foo({'foo': '0'}, None).foo, False)
+        self.assertEqual(Foo({'foo': '1'}, None).foo, True)
 
 def get_tests_in_module(module):
     tests = []