[webkit-patch] Use commit.webkit.org instead of remote SVN to compute identifier
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / commands / upload_unittest.py
1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # Copyright (C) 2018-2021 Apple Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #    * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #    * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #    * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 from webkitpy.thirdparty.mock import Mock
31 from webkitpy.tool.commands.commandtest import CommandsTest
32 from webkitpy.tool.commands.upload import *
33 from webkitpy.tool.mocktool import MockOptions, MockTool
34
35 from webkitcorepy import mocks
36
37
38 class UploadCommandsTest(CommandsTest):
39     def test_commit_message_for_current_diff(self):
40         tool = MockTool()
41         expected_stdout = "This is a fake commit message that is at least 50 characters.\n"
42         self.assert_execute_outputs(CommitMessageForCurrentDiff(), [], expected_stdout=expected_stdout, tool=tool)
43
44     def test_clean_pending_commit(self):
45         self.assert_execute_outputs(CleanPendingCommit(), [])
46
47     def test_assign_to_committer(self):
48         tool = MockTool()
49         expected_logs = """Warning, attachment 10001 on bug 50000 has invalid committer (non-committer@example.com)
50 MOCK reassign_bug: bug_id=50000, assignee=ap@webkit.org
51 -- Begin comment --
52 Attachment 10001 was posted by a committer and has review+, assigning to Alexey Proskuryakov for commit.
53 -- End comment --
54 Bug 50003 is already assigned to foo@foo.com (None).
55 Bug 50002 has no non-obsolete patches, ignoring.
56 """
57         self.assert_execute_outputs(AssignToCommitter(), [], expected_logs=expected_logs, tool=tool)
58
59     def test_obsolete_attachments(self):
60         expected_logs = "Obsoleting 2 old patches on bug 50000\n"
61         self.assert_execute_outputs(ObsoleteAttachments(), [50000], expected_logs=expected_logs)
62
63     def test_post(self):
64         options = MockOptions()
65         options.cc = None
66         options.check_style = True
67         options.check_style_filter = None
68         options.comment = None
69         options.description = "MOCK description"
70         options.non_interactive = False
71         options.request_commit = False
72         options.review = True
73         options.suggest_reviewers = False
74         expected_logs = """MOCK: user.open_url: file://...
75 Was that diff correct?
76 Obsoleting 2 old patches on bug 50000
77 MOCK reassign_bug: bug_id=50000, assignee=None
78 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
79 MOCK: user.open_url: http://example.com/50000
80 """
81         self.assert_execute_outputs(Post(), [50000], options=options, expected_logs=expected_logs)
82
83     def test_attach_to_bug(self):
84         options = MockOptions()
85         options.comment = "extra comment"
86         options.description = "file description"
87         expected_logs = """MOCK add_attachment_to_bug: bug_id=50000, description=file description filename=None mimetype=None
88 -- Begin comment --
89 extra comment
90 -- End comment --
91 """
92         self.assert_execute_outputs(AttachToBug(), [50000, "path/to/file.txt", "file description"], options=options, expected_logs=expected_logs)
93
94     def test_attach_to_bug_no_description_or_comment(self):
95         options = MockOptions()
96         options.comment = None
97         options.description = None
98         expected_logs = "MOCK add_attachment_to_bug: bug_id=50000, description=file.txt filename=None mimetype=None\n"
99         self.assert_execute_outputs(AttachToBug(), [50000, "path/to/file.txt"], options=options, expected_logs=expected_logs)
100
101     def test_land_safely(self):
102         expected_logs = """Obsoleting 2 old patches on bug 50000
103 MOCK reassign_bug: bug_id=50000, assignee=None
104 MOCK add_patch_to_bug: bug_id=50000, description=Patch for landing, mark_for_review=False, mark_for_commit_queue=False, mark_for_landing=True
105 """
106         self.assert_execute_outputs(LandSafely(), [50000], expected_logs=expected_logs)
107
108     def test_prepare_diff_with_arg(self):
109         options = MockOptions()
110         options.sort_xcode_project = False
111         self.assert_execute_outputs(Prepare(), [50000], options=options)
112
113     def test_prepare(self):
114         options = MockOptions()
115         options.sort_xcode_project = False
116         options.non_interactive = True
117         expected_logs = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: MOCK cc\n"
118         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
119
120     def test_prepare_with_cc(self):
121         options = MockOptions()
122         options.cc = "a@example.com,b@example.com"
123         options.sort_xcode_project = False
124         options.non_interactive = True
125         expected_logs = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: a@example.com,b@example.com\n"
126         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
127
128     def test_prepare_with_radar(self):
129         options = MockOptions()
130         options.cc_radar = True
131         options.sort_xcode_project = False
132         options.non_interactive = True
133         expected_logs = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: webkit-bug-importer@group.apple.com,MOCK cc\n"
134         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
135
136     def test_prepare_with_cc_and_radar(self):
137         options = MockOptions()
138         options.cc = "a@example.com,b@example.com"
139         options.cc_radar = True
140         options.sort_xcode_project = False
141         options.non_interactive = True
142         expected_logs = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: webkit-bug-importer@group.apple.com,a@example.com,b@example.com\n"
143         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
144
145     def test_upload(self):
146         options = MockOptions()
147         options.cc = None
148         options.check_style = True
149         options.check_style_filter = None
150         options.comment = None
151         options.description = "MOCK description"
152         options.non_interactive = False
153         options.request_commit = False
154         options.review = True
155         options.submit_to_ews = False
156         options.sort_xcode_project = False
157         options.suggest_reviewers = False
158         expected_logs = """MOCK: user.open_url: file://...
159 Was that diff correct?
160 Obsoleting 2 old patches on bug 50000
161 MOCK reassign_bug: bug_id=50000, assignee=None
162 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
163 MOCK: user.open_url: http://example.com/50000
164 """
165         self.assert_execute_outputs(Upload(), [50000], options=options, expected_logs=expected_logs)
166
167     def test_upload_with_no_review_and_ews(self):
168         options = MockOptions()
169         options.cc = None
170         options.check_style = True
171         options.check_style_filter = None
172         options.comment = None
173         options.description = 'MOCK description'
174         options.non_interactive = False
175         options.request_commit = False
176         options.review = False
177         options.ews = True
178         options.sort_xcode_project = False
179         options.suggest_reviewers = False
180         expected_logs = """MOCK: user.open_url: file://...
181 Was that diff correct?
182 Obsoleting 2 old patches on bug 50000
183 MOCK reassign_bug: bug_id=50000, assignee=None
184 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=False, mark_for_commit_queue=False, mark_for_landing=False
185 MOCK: user.open_url: http://example.com/50000
186 MOCK: submit_to_ews: 10001
187 """
188         self.assert_execute_outputs(Upload(), [50000], options=options, expected_logs=expected_logs)
189
190     def test_mark_bug_fixed(self):
191         tool = MockTool()
192         tool._scm.last_svn_commit_log = lambda: "r9876 |"
193         options = Mock()
194         options.bug_id = 50000
195         options.comment = "MOCK comment"
196         expected_logs = """Bug: <http://example.com/50000> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter.
197 Revision: 9876
198 MOCK: user.open_url: http://example.com/50000
199 Is this correct?
200 Adding comment to Bug 50000.
201 MOCK bug comment: bug_id=50000, cc=None, see_also=None
202 --- Begin comment ---
203 MOCK comment
204
205 Committed r9876 (5@main): <https://commits.webkit.org/5@main>
206 --- End comment ---
207
208 """
209         with mocks.Requests('commits.webkit.org', **{
210             'r9876/json': mocks.Response.fromJson(dict(
211                 identifier='5@main',
212                 revision=9876,
213             )),
214         }):
215             self.assert_execute_outputs(MarkBugFixed(), [], expected_logs=expected_logs, tool=tool, options=options)
216
217     def test_edit_changelog(self):
218         self.assert_execute_outputs(EditChangeLogs(), [])