[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Thu Apr 8 00:51:59 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit a8b02fdb845b9045c8f372151dc1c53af0399eed
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Dec 30 06:46:22 2009 +0000

    2009-12-29  Eric Seidel  <eric at webkit.org>
    
            Reviewed by Adam Barth.
    
            Split out BugzillaQueries class from Bugzilla
            https://bugs.webkit.org/show_bug.cgi?id=33042
    
            * Scripts/modules/bugzilla.py:
             - Split out BugzillaQueries from Bugzilla.
             - Try to isolate self.bugzilla usage into helper functions whenever possible.
             - Add a bunch of FIXMEs.
             - Rename fetch_bug_ids_from_needs_commit_list to fetch_bug_ids_from_pending_commit_list
            * Scripts/modules/bugzilla_unittest.py:
             - Create a new BugzillaQueriesTest testcase and move logic there.
            * Scripts/modules/buildsteps_unittest.py:
             - Use Bug 75 instead of 1 since bug 1 doesn't actually exist.
            * Scripts/modules/commands/queries.py:
             - Update to use bugzilla.queries
            * Scripts/modules/commands/queues.py:
             - Ditto.
            * Scripts/modules/commands/upload.py:
             - Ditto.
            * Scripts/modules/mock_bugzillatool.py:
             - Add a MockBugzillaQueries.
             - Make patches and bugs global privates.
             - Let _id_to_object_dictionary take a variable argument list instead of an array.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52645 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 5bfceaf..2499890 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,30 @@
+2009-12-29  Eric Seidel  <eric at webkit.org>
+
+        Reviewed by Adam Barth.
+
+        Split out BugzillaQueries class from Bugzilla
+        https://bugs.webkit.org/show_bug.cgi?id=33042
+
+        * Scripts/modules/bugzilla.py:
+         - Split out BugzillaQueries from Bugzilla.
+         - Try to isolate self.bugzilla usage into helper functions whenever possible.
+         - Add a bunch of FIXMEs.
+         - Rename fetch_bug_ids_from_needs_commit_list to fetch_bug_ids_from_pending_commit_list
+        * Scripts/modules/bugzilla_unittest.py:
+         - Create a new BugzillaQueriesTest testcase and move logic there.
+        * Scripts/modules/buildsteps_unittest.py:
+         - Use Bug 75 instead of 1 since bug 1 doesn't actually exist.
+        * Scripts/modules/commands/queries.py:
+         - Update to use bugzilla.queries
+        * Scripts/modules/commands/queues.py:
+         - Ditto.
+        * Scripts/modules/commands/upload.py:
+         - Ditto.
+        * Scripts/modules/mock_bugzillatool.py:
+         - Add a MockBugzillaQueries.
+         - Make patches and bugs global privates.
+         - Let _id_to_object_dictionary take a variable argument list instead of an array.
+
 2009-12-29  Daniel Bates  <dbates at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebKitTools/Scripts/modules/bugzilla.py b/WebKitTools/Scripts/modules/bugzilla.py
index b8fe447..4ff3cb9 100644
--- a/WebKitTools/Scripts/modules/bugzilla.py
+++ b/WebKitTools/Scripts/modules/bugzilla.py
@@ -81,10 +81,71 @@ class Bug(object):
         return [patch for patch in self.patches() if patch.get("review") == "?"]
 
 
+# A container for all of the logic for making a parsing buzilla queries.
+class BugzillaQueries(object):
+    def __init__(self, bugzilla):
+        self.bugzila = bugzilla
+
+    def _load_query(self, query):
+        full_url = "%s%s" % (self.bugzilla.bug_server_url, query)
+        return self.bugzilla.browser.open(full_url)
+
+    def _fetch_bug_ids_advanced_query(self, query):
+        soup = BeautifulSoup(self._load_query(query))
+        # The contents of the <a> inside the cells in the first column happen to be the bug id.
+        return [int(bug_link_cell.find("a").string) for bug_link_cell in soup('td', "first-child")]
+
+    def _parse_attachment_ids_request_query(self, page):
+        digits = re.compile("\d+")
+        attachment_href = re.compile("attachment.cgi\?id=\d+&action=review")
+        attachment_links = SoupStrainer("a", href=attachment_href)
+        return [int(digits.search(tag["href"]).group(0)) for tag in BeautifulSoup(page, parseOnlyThese=attachment_links)]
+
+    def _fetch_attachment_ids_request_query(self, query):
+        return self._parse_attachment_ids_request_query(self._load_query(query))
+
+    # List of all r+'d bugs.
+    def fetch_bug_ids_from_pending_commit_list(self):
+        needs_commit_query_url = "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=review%2B"
+        return self._fetch_bug_ids_advanced_query(needs_commit_query_url)
+
+    def fetch_patches_from_pending_commit_list(self):
+        # FIXME: This should not have to go through self.bugzilla
+        return sum([self.bugzilla.fetch_reviewed_patches_from_bug(bug_id) for bug_id in self.fetch_bug_ids_from_pending_commit_list()], [])
+
+    def fetch_bug_ids_from_commit_queue(self):
+        commit_queue_url = "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=commit-queue%2B"
+        return self._fetch_bug_ids_advanced_query(commit_queue_url)
+
+    def fetch_patches_from_commit_queue(self, reject_invalid_patches=False):
+        # FIXME: Once reject_invalid_patches is moved out of this function this becomes a simple list comprehension using fetch_bug_ids_from_commit_queue.
+        patches_to_land = []
+        for bug_id in self.fetch_bug_ids_from_commit_queue():
+            # FIXME: This should not have to go through self.bugzilla
+            patches = self.bugzilla.fetch_commit_queue_patches_from_bug(bug_id, reject_invalid_patches)
+            patches_to_land += patches
+        return patches_to_land
+
+    def _fetch_bug_ids_from_review_queue(self):
+        review_queue_url = "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=review?"
+        return self._fetch_bug_ids_advanced_query(review_queue_url)
+
+    def fetch_patches_from_review_queue(self, limit=None):
+        # FIXME: We should probably have a self.fetch_bug to minimize the number of self.bugzilla calls.
+        return sum([self.bugzilla.fetch_bug(bug_id).unreviewed_patches() for bug_id in self._fetch_bug_ids_from_review_queue()[:limit]], []) # [:None] returns the whole array.
+
+    # FIXME: Why do we have both fetch_patches_from_review_queue and fetch_attachment_ids_from_review_queue??
+    # NOTE: This is also the only client of _fetch_attachment_ids_request_query
+    def fetch_attachment_ids_from_review_queue(self):
+        review_queue_url = "request.cgi?action=queue&type=review&group=type"
+        return self._fetch_attachment_ids_request_query(review_queue_url)
+
+
 class Bugzilla(object):
     def __init__(self, dryrun=False, committers=CommitterList()):
         self.dryrun = dryrun
         self.authenticated = False
+        self.queries = BugzillaQueries(self)
 
         # FIXME: We should use some sort of Browser mock object when in dryrun mode (to prevent any mistakes).
         self.browser = Browser()
@@ -251,51 +312,6 @@ class Bugzilla(object):
                 commit_queue_patches.append(attachment)
         return commit_queue_patches
 
-    def _fetch_bug_ids_advanced_query(self, query):
-        page = self.browser.open(query)
-        soup = BeautifulSoup(page)
-        # The contents of the <a> inside the cells in the first column happen to be the bug id.
-        return [int(bug_link_cell.find("a").string) for bug_link_cell in soup('td', "first-child")]
-
-    def _parse_attachment_ids_request_query(self, page):
-        digits = re.compile("\d+")
-        attachment_href = re.compile("attachment.cgi\?id=\d+&action=review")
-        attachment_links = SoupStrainer("a", href=attachment_href)
-        return [int(digits.search(tag["href"]).group(0)) for tag in BeautifulSoup(page, parseOnlyThese=attachment_links)]
-
-    def _fetch_attachment_ids_request_query(self, query):
-        return self._parse_attachment_ids_request_query(self.browser.open(query))
-
-    def fetch_bug_ids_from_commit_queue(self):
-        commit_queue_url = self.bug_server_url + "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=commit-queue%2B"
-        return self._fetch_bug_ids_advanced_query(commit_queue_url)
-
-    # List of all r+'d bugs.
-    def fetch_bug_ids_from_needs_commit_list(self):
-        needs_commit_query_url = self.bug_server_url + "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=review%2B"
-        return self._fetch_bug_ids_advanced_query(needs_commit_query_url)
-
-    def fetch_bug_ids_from_review_queue(self):
-        review_queue_url = self.bug_server_url + "buglist.cgi?query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&field0-0-0=flagtypes.name&type0-0-0=equals&value0-0-0=review?"
-        return self._fetch_bug_ids_advanced_query(review_queue_url)
-
-    def fetch_attachment_ids_from_review_queue(self):
-        review_queue_url = self.bug_server_url + "request.cgi?action=queue&type=review&group=type"
-        return self._fetch_attachment_ids_request_query(review_queue_url)
-
-    def fetch_patches_from_commit_queue(self, reject_invalid_patches=False):
-        patches_to_land = []
-        for bug_id in self.fetch_bug_ids_from_commit_queue():
-            patches = self.fetch_commit_queue_patches_from_bug(bug_id, reject_invalid_patches)
-            patches_to_land += patches
-        return patches_to_land
-
-    def fetch_patches_from_pending_commit_list(self):
-        return sum([self.fetch_reviewed_patches_from_bug(bug_id) for bug_id in self.fetch_bug_ids_from_needs_commit_list()], [])
-
-    def fetch_patches_from_review_queue(self, limit=None):
-        return sum([self.fetch_bug(bug_id).unreviewed_patches() for bug_id in self.fetch_bug_ids_from_review_queue()[:limit]], []) # [:None] returns the whole array.
-
     def authenticate(self):
         if self.authenticated:
             return
diff --git a/WebKitTools/Scripts/modules/bugzilla_unittest.py b/WebKitTools/Scripts/modules/bugzilla_unittest.py
index 427a7b8..720ffbc 100644
--- a/WebKitTools/Scripts/modules/bugzilla_unittest.py
+++ b/WebKitTools/Scripts/modules/bugzilla_unittest.py
@@ -29,7 +29,7 @@
 import unittest
 
 from modules.committers import CommitterList, Reviewer, Committer
-from modules.bugzilla import Bugzilla, parse_bug_id
+from modules.bugzilla import Bugzilla, BugzillaQueries, parse_bug_id
 from modules.outputcapture import OutputCapture
 
 from modules.BeautifulSoup import BeautifulSoup
@@ -223,6 +223,24 @@ ZEZpbmlzaExvYWRXaXRoUmVhc29uOnJlYXNvbl07Cit9CisKIEBlbmQKIAogI2VuZGlmCg==
         bugzilla = Bugzilla()
         self.assertEquals(27314, bugzilla._parse_bug_id_from_attachment_page(self._sample_attachment_detail_page))
 
+    def test_add_cc_to_bug(self):
+        bugzilla = Bugzilla()
+        bugzilla.browser = MockBrowser()
+        bugzilla.authenticate = lambda: None
+        expected_stderr = "Adding ['adam at example.com'] to the CC list for bug 42\n"
+        OutputCapture().assert_outputs(self, bugzilla.add_cc_to_bug, [42, ["adam at example.com"]], expected_stderr=expected_stderr)
+
+    def test_flag_permission_rejection_message(self):
+        bugzilla = Bugzilla()
+        expected_messsage="""foo at foo.com does not have review permissions according to http://trac.webkit.org/browser/trunk/WebKitTools/Scripts/modules/committers.py.
+
+- If you do not have review rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags.
+
+- If you have review rights please correct the error in WebKitTools/Scripts/modules/committers.py by adding yourself to the file (no review needed).  Due to bug 30084 the commit-queue will require a restart after your change.  Please contact eseidel at chromium.org to request a commit-queue restart.  After restart the commit-queue will correctly respect your review rights."""
+        self.assertEqual(bugzilla._flag_permission_rejection_message("foo at foo.com", "review"), expected_messsage)
+
+
+class BugzillaQueriesTest(unittest.TestCase):
     _sample_request_page = """
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                       "http://www.w3.org/TR/html4/loose.dtd">
@@ -271,25 +289,8 @@ ZEZpbmlzaExvYWRXaXRoUmVhc29uOnJlYXNvbl07Cit9CisKIEBlbmQKIAogI2VuZGlmCg==
 """
 
     def test_request_page_parsing(self):
-        bugzilla = Bugzilla()
-        self.assertEquals([40511, 40722, 40723], bugzilla._parse_attachment_ids_request_query(self._sample_request_page))
-
-    def test_add_cc_to_bug(self):
-        bugzilla = Bugzilla()
-        bugzilla.browser = MockBrowser()
-        bugzilla.authenticate = lambda: None
-        expected_stderr = "Adding ['adam at example.com'] to the CC list for bug 42\n"
-        OutputCapture().assert_outputs(self, bugzilla.add_cc_to_bug, [42, ["adam at example.com"]], expected_stderr=expected_stderr)
-
-    def test_flag_permission_rejection_message(self):
-        bugzilla = Bugzilla()
-        expected_messsage="""foo at foo.com does not have review permissions according to http://trac.webkit.org/browser/trunk/WebKitTools/Scripts/modules/committers.py.
-
-- If you do not have review rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags.
-
-- If you have review rights please correct the error in WebKitTools/Scripts/modules/committers.py by adding yourself to the file (no review needed).  Due to bug 30084 the commit-queue will require a restart after your change.  Please contact eseidel at chromium.org to request a commit-queue restart.  After restart the commit-queue will correctly respect your review rights."""
-        self.assertEqual(bugzilla._flag_permission_rejection_message("foo at foo.com", "review"), expected_messsage)
-
+        queries = BugzillaQueries(None)
+        self.assertEquals([40511, 40722, 40723], queries._parse_attachment_ids_request_query(self._sample_request_page))
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/WebKitTools/Scripts/modules/buildsteps_unittest.py b/WebKitTools/Scripts/modules/buildsteps_unittest.py
index 2f69d6d..c603491 100644
--- a/WebKitTools/Scripts/modules/buildsteps_unittest.py
+++ b/WebKitTools/Scripts/modules/buildsteps_unittest.py
@@ -38,8 +38,8 @@ class UpdateChangeLogsWithReviewerStepTest(unittest.TestCase):
     def test_guess_reviewer_from_bug(self):
         capture = OutputCapture()
         step = UpdateChangeLogsWithReviewerStep(MockBugzillaTool(), [])
-        expected_stderr = "0 reviewed patches on bug 1, cannot infer reviewer.\n"
-        capture.assert_outputs(self, step._guess_reviewer_from_bug, [1], expected_stderr=expected_stderr)
+        expected_stderr = "0 reviewed patches on bug 75, cannot infer reviewer.\n"
+        capture.assert_outputs(self, step._guess_reviewer_from_bug, [75], expected_stderr=expected_stderr)
 
 
 class StepsTest(unittest.TestCase):
diff --git a/WebKitTools/Scripts/modules/commands/queries.py b/WebKitTools/Scripts/modules/commands/queries.py
index eaddb0d..e1a0e62 100644
--- a/WebKitTools/Scripts/modules/commands/queries.py
+++ b/WebKitTools/Scripts/modules/commands/queries.py
@@ -43,7 +43,7 @@ class BugsToCommit(Command):
         Command.__init__(self, "List bugs in the commit-queue")
 
     def execute(self, options, args, tool):
-        bug_ids = tool.bugs.fetch_bug_ids_from_commit_queue()
+        bug_ids = tool.bugs.queries.fetch_bug_ids_from_commit_queue()
         for bug_id in bug_ids:
             print "%s" % bug_id
 
@@ -54,7 +54,7 @@ class PatchesToCommit(Command):
         Command.__init__(self, "List patches in the commit-queue")
 
     def execute(self, options, args, tool):
-        patches = tool.bugs.fetch_patches_from_commit_queue()
+        patches = tool.bugs.queries.fetch_patches_from_commit_queue()
         log("Patches in commit queue:")
         for patch in patches:
             print "%s" % patch["url"]
@@ -82,7 +82,7 @@ class PatchesToCommitQueue(Command):
         return not committer_record
 
     def execute(self, options, args, tool):
-        patches = tool.bugs.fetch_patches_from_pending_commit_list()
+        patches = tool.bugs.queries.fetch_patches_from_pending_commit_list()
         patches_needing_cq = filter(self._needs_commit_queue, patches)
         if options.bugs:
             bugs_needing_cq = map(lambda patch: patch['bug_id'], patches_needing_cq)
@@ -100,7 +100,7 @@ class PatchesToReview(Command):
         Command.__init__(self, "List patches that are pending review")
 
     def execute(self, options, args, tool):
-        patch_ids = tool.bugs.fetch_attachment_ids_from_review_queue()
+        patch_ids = tool.bugs.queries.fetch_attachment_ids_from_review_queue()
         log("Patches pending review:")
         for patch_id in patch_ids:
             print patch_id
diff --git a/WebKitTools/Scripts/modules/commands/queues.py b/WebKitTools/Scripts/modules/commands/queues.py
index 8e39f3a..7d59a99 100644
--- a/WebKitTools/Scripts/modules/commands/queues.py
+++ b/WebKitTools/Scripts/modules/commands/queues.py
@@ -133,7 +133,7 @@ class CommitQueue(AbstractQueue, StepSequenceErrorHandler):
         AbstractQueue.begin_work_queue(self)
 
     def next_work_item(self):
-        patches = self.tool.bugs.fetch_patches_from_commit_queue(reject_invalid_patches=True)
+        patches = self.tool.bugs.queries.fetch_patches_from_commit_queue(reject_invalid_patches=True)
         if not patches:
             self._update_status("Empty queue")
             return None
@@ -187,7 +187,7 @@ class AbstractReviewQueue(AbstractQueue, PersistentPatchCollectionDelegate, Step
         return self.name
 
     def fetch_potential_patch_ids(self):
-        return self.tool.bugs.fetch_attachment_ids_from_review_queue()
+        return self.tool.bugs.queries.fetch_attachment_ids_from_review_queue()
 
     def status_server(self):
         return self.tool.status_bot
diff --git a/WebKitTools/Scripts/modules/commands/upload.py b/WebKitTools/Scripts/modules/commands/upload.py
index fc65c5b..85facbf 100644
--- a/WebKitTools/Scripts/modules/commands/upload.py
+++ b/WebKitTools/Scripts/modules/commands/upload.py
@@ -83,7 +83,7 @@ class AssignToCommitter(AbstractDeclarativeCommmand):
         self.tool.bugs.reassign_bug(bug_id, committer.bugzilla_email(), reassign_message)
 
     def execute(self, options, args, tool):
-        for bug_id in tool.bugs.fetch_bug_ids_from_needs_commit_list():
+        for bug_id in tool.bugs.queries.fetch_bug_ids_from_pending_commit_list():
             self._assign_bug_to_last_patch_attacher(bug_id)
 
 
diff --git a/WebKitTools/Scripts/modules/mock_bugzillatool.py b/WebKitTools/Scripts/modules/mock_bugzillatool.py
index 6f79685..75df370 100644
--- a/WebKitTools/Scripts/modules/mock_bugzillatool.py
+++ b/WebKitTools/Scripts/modules/mock_bugzillatool.py
@@ -32,32 +32,53 @@ from modules.mock import Mock
 from modules.scm import CommitMessage
 from modules.bugzilla import Bug
 
-def _id_to_object_dictionary(objects):
+def _id_to_object_dictionary(*objects):
     dictionary = {}
     for thing in objects:
         dictionary[thing["id"]] = thing
     return dictionary
 
-class MockBugzilla(Mock):
-    patch1 = {
-        "id" : 197,
-        "bug_id" : 42,
-        "url" : "http://example.com/197",
-        "is_obsolete" : False,
-        "reviewer" : "Reviewer1",
-        "attacher_email" : "Contributer1",
-    }
-    patch2 = {
-        "id" : 128,
-        "bug_id" : 42,
-        "url" : "http://example.com/128",
-        "is_obsolete" : False,
-        "reviewer" : "Reviewer2",
-        "attacher_email" : "eric at webkit.org",
-    }
-    bug_server_url = "http://example.com"
-    unassigned_email = "unassigned at example.com"
-
+# FIXME: The ids shoudl be 1, 2, 3 instead of crazy numbers.
+_patch1 = {
+    "id" : 197,
+    "bug_id" : 42,
+    "url" : "http://example.com/197",
+    "is_obsolete" : False,
+    "is_patch" : True,
+    "reviewer" : "Reviewer1",
+    "attacher_email" : "Contributer1",
+}
+_patch2 = {
+    "id" : 128,
+    "bug_id" : 42,
+    "url" : "http://example.com/128",
+    "is_obsolete" : False,
+    "is_patch" : True,
+    "reviewer" : "Reviewer2",
+    "attacher_email" : "eric at webkit.org",
+}
+
+# This must be defined before we define the bugs, thus we don't use MockBugzilla.unassigned_email directly.
+_unassigned_email = "unassigned at example.com"
+
+# FIXME: The ids should be 1, 2, 3 instead of crazy numbers.
+_bug1 = {
+    "id" : 42,
+    "assigned_to_email" : _unassigned_email,
+    "attachments" : [_patch1, _patch2],
+}
+_bug2 = {
+    "id" : 75,
+    "assigned_to_email" : "foo at foo.com",
+    "attachments" : [],
+}
+_bug3 = {
+    "id" : 76,
+    "assigned_to_email" : _unassigned_email,
+    "attachments" : [],
+}
+
+class MockBugzillaQueries(Mock):
     def fetch_bug_ids_from_commit_queue(self):
         return [42, 75]
 
@@ -65,52 +86,35 @@ class MockBugzilla(Mock):
         return [197, 128]
 
     def fetch_patches_from_commit_queue(self, reject_invalid_patches=False):
-        return [self.patch1, self.patch2]
+        return [_patch1, _patch2]
 
-    def fetch_bug_ids_from_needs_commit_list(self):
+    def fetch_bug_ids_from_pending_commit_list(self):
         return [42, 75, 76]
+    
+    def fetch_patches_from_pending_commit_list(self):
+        return [_patch1, _patch2]
 
-    bug1 = {
-        "id" : 42,
-        "assigned_to_email" : unassigned_email,
-        "attachments" : [patch1, patch2],
-    }
-    bug2 = {
-        "id" : 75,
-        "assigned_to_email" : "foo at foo.com",
-        "attachments" : [],
-    }
-    bug3 = {
-        "id" : 76,
-        "assigned_to_email" : unassigned_email,
-        "attachments" : [],
-    }
-
-    bug_cache = _id_to_object_dictionary([bug1, bug2, bug3])
+
+class MockBugzilla(Mock):
+    bug_server_url = "http://example.com"
+    unassigned_email = _unassigned_email
+    bug_cache = _id_to_object_dictionary(_bug1, _bug2, _bug3)
+    attachment_cache = _id_to_object_dictionary(_patch1, _patch2)
+    queries = MockBugzillaQueries()
 
     def fetch_bug(self, bug_id):
         return Bug(self.bug_cache.get(bug_id))
 
-    def fetch_patches_from_pending_commit_list(self):
-        return [self.patch1, self.patch2]
-
     def fetch_reviewed_patches_from_bug(self, bug_id):
-        if bug_id == 42:
-            return [self.patch1, self.patch2]
-        return []
-
-    def fetch_patches_from_bug(self, bug_id):
-        if bug_id == 42:
-            return [self.patch1, self.patch2]
-        return None
+        return self.fetch_patches_from_bug(bug_id) # Return them all for now.
 
     def fetch_attachment(self, attachment_id):
-        if attachment_id == 197:
-            return self.patch1
-        if attachment_id == 128:
-            return self.patch2
-        raise Exception("Bogus attachment_id in fetch_attachment.")
+        return self.attachment_cache[attachment_id] # This could be changed to .get() if we wish to allow failed lookups.
 
+    # NOTE: Functions below this are direct copies from bugzilla.py
+    def fetch_patches_from_bug(self, bug_id):
+        return self.fetch_bug(bug_id).patches()
+    
     def bug_url_for_bug_id(self, bug_id):
         return "%s/%s" % (self.bug_server_url, bug_id)
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list