This branch is a straight refactoring to fix bug 415774. I've moved the getRemoteStatus() method from the BugzillaLPPlugin ExternalBugTracker to BugzillaAPI, from which BugzillaLPPlugin descends. The method needs no alteration to work for both ExternalBugTrackers. I've also moved the relevant tests into the bugzilla-api doctest. Note that this branch depends on a previous, unlanded branch. Please use the diff below rather than the one provided by Launchpad. = Launchpad lint = Checking for conflicts. and issues in doctests and templates. Running jslint, xmllint, pyflakes, and pylint. Using normal rules. Linting changed files: lib/lp/bugs/doc/externalbugtracker-bugzilla-api.txt lib/lp/bugs/doc/externalbugtracker-bugzilla-lp-plugin.txt lib/lp/bugs/externalbugtracker/bugzilla.py Diff of changes --------------- === modified file 'lib/lp/bugs/doc/externalbugtracker-bugzilla-api.txt' --- lib/lp/bugs/doc/externalbugtracker-bugzilla-api.txt 2009-08-21 09:32:57 +0000 +++ lib/lp/bugs/doc/externalbugtracker-bugzilla-api.txt 2009-08-21 10:51:09 +0000 @@ -219,3 +219,38 @@ >>> bugzilla._getActualBugId(2) 2 + + +Getting remote statuses +----------------------- + +BugzillaAPI.getRemoteStatus() will return the remote status of a given +bug as a string. If the bug has a resolution, that will be returned too. + + >>> test_transport.print_method_calls = False + >>> bugzilla.initializeRemoteBugDB([1, 2]) + + >>> print bugzilla.getRemoteStatus(1) + RESOLVED FIXED + + >>> print bugzilla.getRemoteStatus(2) + NEW + +If a bug can't be found a BugNotFound error will be raised. + + >>> bugzilla.getRemoteStatus('no-such-bug') + Traceback (most recent call last): + ... + BugNotFound: no-such-bug + +If the data we've imported from Bugzilla is incomplete and doesn't +contain either the bug's status or its resolution an UnparseableBugData +error will be raised. We can add a sample bug to demonstrate this. + + >>> bugzilla._bugs[999] = {} + >>> bugzilla.getRemoteStatus(999) + Traceback (most recent call last): + ... + UnparseableBugData + + >>> del bugzilla._bugs[999] === modified file 'lib/lp/bugs/doc/externalbugtracker-bugzilla-lp-plugin.txt' --- lib/lp/bugs/doc/externalbugtracker-bugzilla-lp-plugin.txt 2009-08-21 09:32:57 +0000 +++ lib/lp/bugs/doc/externalbugtracker-bugzilla-lp-plugin.txt 2009-08-21 10:42:55 +0000 @@ -301,34 +301,10 @@ Getting remote statuses ----------------------- -BugzillaLPPlugin.getRemoteStatus() will return the remote status of a -given bug as a string. If the bug has a resolution, that will be -returned too. - - >>> print bugzilla.getRemoteStatus(1) - RESOLVED FIXED - - >>> print bugzilla.getRemoteStatus(2) - NEW - -If a bug can't be found a BugNotFound error will be raised. - - >>> bugzilla.getRemoteStatus('no-such-bug') - Traceback (most recent call last): - ... - BugNotFound: no-such-bug - -If the data we've imported from Bugzilla is incomplete and doesn't -contain either the bug's status or its resolution an UnparseableBugData -error will be raised. We can add a sample bug to demonstrate this. - - >>> bugzilla._bugs[999] = {} - >>> bugzilla.getRemoteStatus(999) - Traceback (most recent call last): - ... - UnparseableBugData - - >>> del bugzilla._bugs[999] +BugzillaLPPlugin doesn't have any special functionality for getting +remote statuses. See the "Getting remote statuses" section of +externalbugtracker-bugzilla-api.txt for details of getting remote +statuses from Bugzilla APIs. Getting the remote product === modified file 'lib/lp/bugs/externalbugtracker/bugzilla.py' --- lib/lp/bugs/externalbugtracker/bugzilla.py 2009-08-21 09:32:57 +0000 +++ lib/lp/bugs/externalbugtracker/bugzilla.py 2009-08-21 10:47:25 +0000 @@ -522,6 +522,23 @@ self._storeBugs(remote_bugs) + def getRemoteStatus(self, bug_id): + """See `IExternalBugTracker`.""" + actual_bug_id = self._getActualBugId(bug_id) + + # Attempt to get the status and resolution from the bug. If + # we don't have the data for either of them, raise an error. + try: + status = self._bugs[actual_bug_id]['status'] + resolution = self._bugs[actual_bug_id]['resolution'] + except KeyError, error: + raise UnparseableBugData + + if resolution != '': + return "%s %s" % (status, resolution) + else: + return status + class BugzillaLPPlugin(BugzillaAPI): """An `ExternalBugTracker` to handle Bugzillas using the LP Plugin.""" @@ -648,23 +665,6 @@ server_utc_time = datetime(*server_timetuple[:6]) return server_utc_time.replace(tzinfo=pytz.timezone('UTC')) - def getRemoteStatus(self, bug_id): - """See `IExternalBugTracker`.""" - actual_bug_id = self._getActualBugId(bug_id) - - # Attempt to get the status and resolution from the bug. If - # we don't have the data for either of them, raise an error. - try: - status = self._bugs[actual_bug_id]['status'] - resolution = self._bugs[actual_bug_id]['resolution'] - except KeyError, error: - raise UnparseableBugData - - if resolution != '': - return "%s %s" % (status, resolution) - else: - return status - def getRemoteProduct(self, remote_bug): """See `IExternalBugTracker`.""" actual_bug_id = self._getActualBugId(remote_bug)