changeset 24:96f841399b40

Added resilience for case where bugs have no attachments
author Atul Varma <avarma@mozilla.com>
date Thu, 22 Apr 2010 16:35:27 -0700
parents 09817175c9aa
children cf3583d9bf07
files bugzilla.py test_bugzilla.py
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/bugzilla.py	Wed Apr 14 16:59:22 2010 -0700
+++ b/bugzilla.py	Thu Apr 22 16:35:27 2010 -0700
@@ -439,6 +439,9 @@
     """
     >>> Bug(TEST_BUG, MockBugzillaApi())
     <Bug 558680 - u'Here is a summary'>
+
+    >>> Bug(TEST_BUG_NO_ATTACHMENTS, MockBugzillaApi())
+    <Bug 558681 - u'Here is another summary'>
     """
 
     __bzprops__ = {
@@ -449,7 +452,8 @@
     def __init__(self, jsonobj, bzapi):
         BugzillaObject.__init__(self, jsonobj, bzapi)
         self.attachments = [bzapi.attachments.get(attach['id'], attach)
-                            for attach in jsonobj['attachments']]
+                            for attach in jsonobj.get('attachments',
+                                                      [])]
 
     def __repr__(self):
         return '<Bug %d - %s>' % (self.id, repr(self.summary))
--- a/test_bugzilla.py	Wed Apr 14 16:59:22 2010 -0700
+++ b/test_bugzilla.py	Thu Apr 22 16:35:27 2010 -0700
@@ -59,6 +59,11 @@
     u'id': u'558680'
     }
 
+TEST_BUG_NO_ATTACHMENTS = {
+    u'summary': u'Here is another summary',
+    u'id': u'558681'
+    }
+
 class MockBugzillaApi(bugzilla.BugzillaApi):
     def __init__(self, config=None):
         if config is None: