2009-11-27 Adam Barth <abarth@webkit.org>
[WebKit-https.git] / WebKitTools / Scripts / modules / mock_bugzillatool.py
1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #    * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #    * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #    * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import os
30
31 from modules.mock import Mock
32 from modules.scm import CommitMessage
33
34 class MockBugzilla(Mock):
35     patch1 = {
36         "id": 197,
37         "bug_id": 42,
38         "url": "http://example.com/197",
39         "is_obsolete": False,
40         "reviewer": "Reviewer1"
41     }
42     patch2 = {
43         "id": 128,
44         "bug_id": 42,
45         "url": "http://example.com/128",
46         "is_obsolete": False,
47         "reviewer": "Reviewer2"
48     }
49
50     def fetch_bug_ids_from_commit_queue(self):
51         return [42, 75]
52
53     def fetch_patches_from_commit_queue(self):
54         return [self.patch1, self.patch2]
55
56     def fetch_reviewed_patches_from_bug(self, bug_id):
57         if bug_id == 42:
58             return [self.patch1, self.patch2]
59         return None
60
61     def fetch_attachments_from_bug(self, bug_id):
62         if bug_id == 42:
63             return [self.patch1, self.patch2]
64         return None
65
66     def fetch_patches_from_bug(self, bug_id):
67         if bug_id == 42:
68             return [self.patch1, self.patch2]
69         return None
70
71     def fetch_attachment(self, attachment_id):
72         if attachment_id == 197:
73             return self.patch1
74         if attachment_id == 128:
75             return self.patch2
76         raise Exception("Bogus attachment_id in fetch_attachment.")
77
78
79 class MockBuildBot(Mock):
80     def builder_statuses(self):
81         return [{
82             "name": "Builder1",
83             "is_green": True
84         }, {
85             "name": "Builder2",
86             "is_green": True
87         }]
88
89
90 class MockSCM(Mock):
91     def __init__(self):
92         Mock.__init__(self)
93         self.checkout_root = os.getcwd()
94
95     def create_patch(self):
96         return "Patch1"
97
98     def commit_ids_from_commitish_arguments(self, args):
99         return ["Commitish1", "Commitish2"]
100
101     def commit_message_for_local_commit(self, commit_id):
102         if commit_id == "Commitish1":
103             return CommitMessage("CommitMessage1\nhttps://bugs.example.org/show_bug.cgi?id=42\n")
104         if commit_id == "Commitish2":
105             return CommitMessage("CommitMessage2\nhttps://bugs.example.org/show_bug.cgi?id=75\n")
106         raise Exception("Bogus commit_id in commit_message_for_local_commit.")
107
108     def create_patch_from_local_commit(self, commit_id):
109         if commit_id == "Commitish1":
110             return "Patch1"
111         if commit_id == "Commitish2":
112             return "Patch2"
113         raise Exception("Bogus commit_id in commit_message_for_local_commit.")
114
115     def modified_changelogs(self):
116         # Ideally we'd return something more interesting here.
117         # The problem is that LandDiff will try to actually read the path from disk!
118         return []
119
120
121 class MockBugzillaTool():
122     def __init__(self):
123         self.bugs = MockBugzilla()
124         self.buildbot = MockBuildBot()
125         self.steps = Mock()
126         self._scm = MockSCM()
127
128     def scm(self):
129         return self._scm