upload_unittest.py 6.9 KB

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