Fixed some bugs in Bugzilla and added some tests to try and catch more

problems in the future.
This commit is contained in:
James Vega 2003-11-17 19:57:07 +00:00
parent 5cfe9ffd3e
commit f57f57c5be
2 changed files with 11 additions and 3 deletions

View File

@ -43,6 +43,7 @@ from itertools import imap, ifilter
from htmlentitydefs import entitydefs as entities from htmlentitydefs import entitydefs as entities
import conf import conf
import debug
import utils import utils
import plugins import plugins
import ircutils import ircutils
@ -114,7 +115,8 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
be listed with the bugzilla query. be listed with the bugzilla query.
""" """
(name, url, description) = privmsgs.getArgs(args, required=3) (name, url, description) = privmsgs.getArgs(args, required=3)
cursor = self.db.cursor() if url[-1] == '/':
url = url[:-1]
self.db[name] = [url, description] self.db[name] = [url, description]
self.shorthand = utils.abbrev(self.db.keys()) self.shorthand = utils.abbrev(self.db.keys())
irc.reply(msg, conf.replySuccess) irc.reply(msg, conf.replySuccess)
@ -191,10 +193,13 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
try: try:
name = self.shorthand[name] name = self.shorthand[name]
(url, description) = self.db[name] (url, description) = self.db[name]
#debug.printf(url)
#debug.printf(description)
except KeyError: except KeyError:
irc.error(msg, replyNoBugzilla % name) irc.error(msg, replyNoBugzilla % name)
return return
queryurl = '%s/xml.cgi?id=%s' % (url, number) queryurl = '%s/xml.cgi?id=%s' % (url, number)
#debug.printf(queryurl)
try: try:
summary = self._get_short_bug_summary(queryurl,description,number) summary = self._get_short_bug_summary(queryurl,description,number)
except BugzillaError, e: except BugzillaError, e:
@ -229,8 +234,8 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
return ', '.join(imap(str, L)) return ', '.join(imap(str, L))
def _get_short_bug_summary(self, url, desc, number): def _get_short_bug_summary(self, url, desc, number):
bugxml = self._getbugxml(url, desc)
try: try:
bugxml = self._getbugxml(url, desc)
zilladom = minidom.parseString(bugxml) zilladom = minidom.parseString(bugxml)
except Exception, e: except Exception, e:
s = 'Could not parse XML returned by %s bugzilla: %s' % (desc, e) s = 'Could not parse XML returned by %s bugzilla: %s' % (desc, e)
@ -267,7 +272,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Configurable):
def _getbugxml(self, url, desc): def _getbugxml(self, url, desc):
try: try:
fh = urllib2.urlopen(url) fh = urllib2.urlopen(url)
except urllib2.UrlError, e: except urllib2.HTTPError, e:
raise IOError, 'Connection to %s bugzilla failed' % desc raise IOError, 'Connection to %s bugzilla failed' % desc
bugxml = fh.read() bugxml = fh.read()
fh.close() fh.close()

View File

@ -36,6 +36,9 @@ class BugzillaTest(PluginTestCase, PluginDocumentation):
def testBugzilla(self): def testBugzilla(self):
self.assertNotError('bug gcc 5') self.assertNotError('bug gcc 5')
self.assertNotError('http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') self.assertNotError('http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
self.assertNotError('add xiph http://bugs.xiph.org/ Xiph')
self.assertNotError('bug xiph 413')
self.assertNotError('remove xiph')
def testConfigBugzillaSnarfer(self): def testConfigBugzillaSnarfer(self):
self.assertNotError('bugzilla config bug-snarfer off') self.assertNotError('bugzilla config bug-snarfer off')