[LFC] Update the block box/container list
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / commands / upload_unittest.py
1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # Copyright (C) 2018, 2019 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
36 class UploadCommandsTest(CommandsTest):
37     def test_commit_message_for_current_diff(self):
38         tool = MockTool()
39         expected_stdout = "This is a fake commit message that is at least 50 characters.\n"
40         self.assert_execute_outputs(CommitMessageForCurrentDiff(), [], expected_stdout=expected_stdout, tool=tool)
41
42     def test_clean_pending_commit(self):
43         self.assert_execute_outputs(CleanPendingCommit(), [])
44
45     def test_assign_to_committer(self):
46         tool = MockTool()
47         expected_logs = """Warning, attachment 10001 on bug 50000 has invalid committer (non-committer@example.com)
48 MOCK reassign_bug: bug_id=50000, assignee=ap@webkit.org
49 -- Begin comment --
50 Attachment 10001 was posted by a committer and has review+, assigning to Alexey Proskuryakov for commit.
51 -- End comment --
52 Bug 50003 is already assigned to foo@foo.com (None).
53 Bug 50002 has no non-obsolete patches, ignoring.
54 """
55         self.assert_execute_outputs(AssignToCommitter(), [], expected_logs=expected_logs, tool=tool)
56
57     def test_obsolete_attachments(self):
58         expected_logs = "Obsoleting 2 old patches on bug 50000\n"
59         self.assert_execute_outputs(ObsoleteAttachments(), [50000], expected_logs=expected_logs)
60
61     def test_post(self):
62         options = MockOptions()
63         options.cc = None
64         options.check_style = True
65         options.check_style_filter = None
66         options.comment = None
67         options.description = "MOCK description"
68         options.non_interactive = False
69         options.request_commit = False
70         options.review = True
71         options.suggest_reviewers = False
72         expected_logs = """MOCK: user.open_url: file://...
73 Was that diff correct?
74 Obsoleting 2 old patches on bug 50000
75 MOCK reassign_bug: bug_id=50000, assignee=None
76 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
77 MOCK: user.open_url: http://example.com/50000
78 """
79         self.assert_execute_outputs(Post(), [50000], options=options, expected_logs=expected_logs)
80
81     def test_attach_to_bug(self):
82         options = MockOptions()
83         options.comment = "extra comment"
84         options.description = "file description"
85         expected_logs = """MOCK add_attachment_to_bug: bug_id=50000, description=file description filename=None mimetype=None
86 -- Begin comment --
87 extra comment
88 -- End comment --
89 """
90         self.assert_execute_outputs(AttachToBug(), [50000, "path/to/file.txt", "file description"], options=options, expected_logs=expected_logs)
91
92     def test_attach_to_bug_no_description_or_comment(self):
93         options = MockOptions()
94         options.comment = None
95         options.description = None
96         expected_logs = "MOCK add_attachment_to_bug: bug_id=50000, description=file.txt filename=None mimetype=None\n"
97         self.assert_execute_outputs(AttachToBug(), [50000, "path/to/file.txt"], options=options, expected_logs=expected_logs)
98
99     def test_land_safely(self):
100         expected_logs = """Obsoleting 2 old patches on bug 50000
101 MOCK reassign_bug: bug_id=50000, assignee=None
102 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
103 """
104         self.assert_execute_outputs(LandSafely(), [50000], expected_logs=expected_logs)
105
106     def test_prepare_diff_with_arg(self):
107         options = MockOptions()
108         options.sort_xcode_project = False
109         self.assert_execute_outputs(Prepare(), [50000], options=options)
110
111     def test_prepare(self):
112         options = MockOptions()
113         options.sort_xcode_project = False
114         options.non_interactive = True
115         expected_logs = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: MOCK cc\n"
116         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
117
118     def test_prepare_with_cc(self):
119         options = MockOptions()
120         options.cc = "a@example.com,b@example.com"
121         options.sort_xcode_project = False
122         options.non_interactive = True
123         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"
124         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
125
126     def test_prepare_with_radar(self):
127         options = MockOptions()
128         options.cc_radar = True
129         options.sort_xcode_project = False
130         options.non_interactive = True
131         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"
132         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
133
134     def test_prepare_with_cc_and_radar(self):
135         options = MockOptions()
136         options.cc = "a@example.com,b@example.com"
137         options.cc_radar = True
138         options.sort_xcode_project = False
139         options.non_interactive = True
140         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"
141         self.assert_execute_outputs(Prepare(), [], expected_logs=expected_logs, options=options)
142
143     def test_upload(self):
144         options = MockOptions()
145         options.cc = None
146         options.check_style = True
147         options.check_style_filter = None
148         options.comment = None
149         options.description = "MOCK description"
150         options.non_interactive = False
151         options.request_commit = False
152         options.review = True
153         options.submit_to_ews = False
154         options.sort_xcode_project = False
155         options.suggest_reviewers = False
156         expected_logs = """MOCK: user.open_url: file://...
157 Was that diff correct?
158 Obsoleting 2 old patches on bug 50000
159 MOCK reassign_bug: bug_id=50000, assignee=None
160 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
161 MOCK: user.open_url: http://example.com/50000
162 """
163         self.assert_execute_outputs(Upload(), [50000], options=options, expected_logs=expected_logs)
164
165     def test_upload_with_no_review_and_ews(self):
166         options = MockOptions()
167         options.cc = None
168         options.check_style = True
169         options.check_style_filter = None
170         options.comment = None
171         options.description = 'MOCK description'
172         options.non_interactive = False
173         options.request_commit = False
174         options.review = False
175         options.ews = True
176         options.sort_xcode_project = False
177         options.suggest_reviewers = False
178         expected_logs = """MOCK: user.open_url: file://...
179 Was that diff correct?
180 Obsoleting 2 old patches on bug 50000
181 MOCK reassign_bug: bug_id=50000, assignee=None
182 MOCK add_patch_to_bug: bug_id=50000, description=MOCK description, mark_for_review=False, mark_for_commit_queue=False, mark_for_landing=False
183 MOCK: user.open_url: http://example.com/50000
184 MOCK: submit_to_ews: 10001
185 """
186         self.assert_execute_outputs(Upload(), [50000], options=options, expected_logs=expected_logs)
187
188     def test_mark_bug_fixed(self):
189         tool = MockTool()
190         tool._scm.last_svn_commit_log = lambda: "r9876 |"
191         options = Mock()
192         options.bug_id = 50000
193         options.comment = "MOCK comment"
194         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.
195 Revision: 9876
196 MOCK: user.open_url: http://example.com/50000
197 Is this correct?
198 Adding comment to Bug 50000.
199 MOCK bug comment: bug_id=50000, cc=None, see_also=None
200 --- Begin comment ---
201 MOCK comment
202
203 Committed r9876: <https://commits.webkit.org/r9876>
204 --- End comment ---
205
206 """
207         self.assert_execute_outputs(MarkBugFixed(), [], expected_logs=expected_logs, tool=tool, options=options)
208
209     def test_edit_changelog(self):
210         self.assert_execute_outputs(EditChangeLogs(), [])