Home | History | Annotate | Download | only in commands
      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 from webkitpy.thirdparty.mock import Mock
     30 from webkitpy.tool.commands.commandtest import CommandsTest
     31 from webkitpy.tool.commands.upload import *
     32 from webkitpy.tool.mocktool import MockOptions, MockTool
     33 
     34 class UploadCommandsTest(CommandsTest):
     35     def test_commit_message_for_current_diff(self):
     36         tool = MockTool()
     37         expected_stdout = "This is a fake commit message that is at least 50 characters.\n"
     38         self.assert_execute_outputs(CommitMessageForCurrentDiff(), [], expected_stdout=expected_stdout, tool=tool)
     39 
     40     def test_clean_pending_commit(self):
     41         self.assert_execute_outputs(CleanPendingCommit(), [])
     42 
     43     def test_assign_to_committer(self):
     44         tool = MockTool()
     45         expected_stderr = "Warning, attachment 128 on bug 42 has invalid committer (non-committer (at] example.com)\nBug 77 is already assigned to foo (at] foo.com (None).\nBug 76 has no non-obsolete patches, ignoring.\n"
     46         self.assert_execute_outputs(AssignToCommitter(), [], expected_stderr=expected_stderr, tool=tool)
     47         tool.bugs.reassign_bug.assert_called_with(42, "eric (at] webkit.org", "Attachment 128 was posted by a committer and has review+, assigning to Eric Seidel for commit.")
     48 
     49     def test_obsolete_attachments(self):
     50         expected_stderr = "Obsoleting 2 old patches on bug 42\n"
     51         self.assert_execute_outputs(ObsoleteAttachments(), [42], expected_stderr=expected_stderr)
     52 
     53     def test_post(self):
     54         options = MockOptions()
     55         options.cc = None
     56         options.check_style = True
     57         options.comment = None
     58         options.description = "MOCK description"
     59         options.request_commit = False
     60         options.review = True
     61         options.suggest_reviewers = False
     62         expected_stderr = """MOCK: user.open_url: file://...
     63 Was that diff correct?
     64 Obsoleting 2 old patches on bug 42
     65 MOCK add_patch_to_bug: bug_id=42, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
     66 MOCK: user.open_url: http://example.com/42
     67 """
     68         self.assert_execute_outputs(Post(), [42], options=options, expected_stderr=expected_stderr)
     69 
     70     def test_attach_to_bug(self):
     71         options = MockOptions()
     72         options.comment = "extra comment"
     73         options.description = "file description"
     74         expected_stderr = """MOCK add_attachment_to_bug: bug_id=42, description=file description filename=None
     75 -- Begin comment --
     76 extra comment
     77 -- End comment --
     78 """
     79         self.assert_execute_outputs(AttachToBug(), [42, "path/to/file.txt", "file description"], options=options, expected_stderr=expected_stderr)
     80 
     81     def test_attach_to_bug_no_description_or_comment(self):
     82         options = MockOptions()
     83         options.comment = None
     84         options.description = None
     85         expected_stderr = """MOCK add_attachment_to_bug: bug_id=42, description=file.txt filename=None
     86 """
     87         self.assert_execute_outputs(AttachToBug(), [42, "path/to/file.txt"], options=options, expected_stderr=expected_stderr)
     88 
     89     def test_land_safely(self):
     90         expected_stderr = "Obsoleting 2 old patches on bug 42\nMOCK add_patch_to_bug: bug_id=42, description=Patch for landing, mark_for_review=False, mark_for_commit_queue=False, mark_for_landing=True\n"
     91         self.assert_execute_outputs(LandSafely(), [42], expected_stderr=expected_stderr)
     92 
     93     def test_prepare_diff_with_arg(self):
     94         self.assert_execute_outputs(Prepare(), [42])
     95 
     96     def test_prepare(self):
     97         expected_stderr = "MOCK create_bug\nbug_title: Mock user response\nbug_description: Mock user response\ncomponent: MOCK component\ncc: MOCK cc\n"
     98         self.assert_execute_outputs(Prepare(), [], expected_stderr=expected_stderr)
     99 
    100     def test_upload(self):
    101         options = MockOptions()
    102         options.cc = None
    103         options.check_style = True
    104         options.comment = None
    105         options.description = "MOCK description"
    106         options.request_commit = False
    107         options.review = True
    108         options.suggest_reviewers = False
    109         expected_stderr = """MOCK: user.open_url: file://...
    110 Was that diff correct?
    111 Obsoleting 2 old patches on bug 42
    112 MOCK add_patch_to_bug: bug_id=42, description=MOCK description, mark_for_review=True, mark_for_commit_queue=False, mark_for_landing=False
    113 MOCK: user.open_url: http://example.com/42
    114 """
    115         self.assert_execute_outputs(Upload(), [42], options=options, expected_stderr=expected_stderr)
    116 
    117     def test_mark_bug_fixed(self):
    118         tool = MockTool()
    119         tool._scm.last_svn_commit_log = lambda: "r9876 |"
    120         options = Mock()
    121         options.bug_id = 42
    122         options.comment = "MOCK comment"
    123         expected_stderr = """Bug: <http://example.com/42> Bug with two r+'d and cq+'d patches, one of which has an invalid commit-queue setter.
    124 Revision: 9876
    125 MOCK: user.open_url: http://example.com/42
    126 Is this correct?
    127 Adding comment to Bug 42.
    128 MOCK bug comment: bug_id=42, cc=None
    129 --- Begin comment ---
    130 MOCK comment
    131 
    132 Committed r9876: <http://trac.webkit.org/changeset/9876>
    133 --- End comment ---
    134 
    135 """
    136         self.assert_execute_outputs(MarkBugFixed(), [], expected_stderr=expected_stderr, tool=tool, options=options)
    137 
    138     def test_edit_changelog(self):
    139         self.assert_execute_outputs(EditChangeLogs(), [])
    140