1 # Copyright (C) 2013 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 # 14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 import webkitpy.thirdparty.unittest2 as unittest 27 28 from webkitpy.tool.bot.commitannouncer import CommitAnnouncer 29 from webkitpy.tool.mocktool import MockTool 30 31 32 class CommitAnnouncerTest(unittest.TestCase): 33 def test_format_commit(self): 34 tool = MockTool() 35 bot = CommitAnnouncer(tool, "test_password") 36 self.assertEqual( 37 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line"', 38 bot._format_commit_detail("""\ 39 1234commit1234 40 authorABC (at] chromium.org 41 Commit test subject line 42 Multiple 43 lines 44 of 45 description. 46 47 BUG=654321 48 49 Review URL: https://codereview.chromium.org/123456 50 51 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 52 """)) 53 54 self.assertEqual( 55 'r456789 https://chromium.googlesource.com/chromium/blink/+/1234comm ' 56 'authorABC (at] chromium.org committed "Commit test subject line"', 57 bot._format_commit_detail("""\ 58 1234commit1234 59 authorABC (at] chromium.org 60 Commit test subject line 61 Multiple 62 lines 63 of 64 description. 65 66 BUG=654321 67 68 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 69 """)) 70 71 self.assertEqual( 72 'http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line"', 73 bot._format_commit_detail("""\ 74 1234commit1234 75 authorABC (at] chromium.org 76 Commit test subject line 77 Multiple 78 lines 79 of 80 description. 81 82 BUG=654321 83 84 Review URL: https://codereview.chromium.org/123456 85 """)) 86 87 self.assertEqual( 88 'https://chromium.googlesource.com/chromium/blink/+/1234comm authorABC (at] chromium.org committed "Commit test subject line"', 89 bot._format_commit_detail("""\ 90 1234commit1234 91 authorABC (at] chromium.org 92 Commit test subject line 93 Multiple 94 lines 95 of 96 description. 97 """)) 98 99 self.assertEqual( 100 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line"', 101 bot._format_commit_detail("""\ 102 1234commit1234 103 authorABC (at] chromium.org 104 Commit test subject line 105 Multiple 106 lines 107 of 108 description. 109 Review URL: http://fake.review.url 110 git-svn-id: svn://svn.chromium.org/blink/trunk@000000 Fake-SVN-number 111 112 BUG=654321 113 114 Review URL: https://codereview.chromium.org/123456 115 116 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 117 """)) 118 119 self.assertEqual( 120 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line" ' 121 '\x037TBR=reviewerDEF (at] chromium.org\x03', 122 bot._format_commit_detail("""\ 123 1234commit1234 124 authorABC (at] chromium.org 125 Commit test subject line 126 Multiple 127 lines 128 of 129 description. 130 131 BUG=654321 132 TBR=reviewerDEF (at] chromium.org 133 134 Review URL: https://codereview.chromium.org/123456 135 136 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 137 """)) 138 139 self.assertEqual( 140 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line" ' 141 '\x037NOTRY=true\x03', 142 bot._format_commit_detail("""\ 143 1234commit1234 144 authorABC (at] chromium.org 145 Commit test subject line 146 Multiple 147 lines 148 of 149 description. 150 151 BUG=654321 152 NOTRY=true 153 154 Review URL: https://codereview.chromium.org/123456 155 156 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 157 """)) 158 159 self.assertEqual( 160 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line" ' 161 '\x037NOTRY=true TBR=reviewerDEF (at] chromium.org\x03', 162 bot._format_commit_detail("""\ 163 1234commit1234 164 authorABC (at] chromium.org 165 Commit test subject line 166 Multiple 167 lines 168 of 169 description. 170 171 NOTRY=true 172 BUG=654321 173 TBR=reviewerDEF (at] chromium.org 174 175 Review URL: https://codereview.chromium.org/123456 176 177 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 178 """)) 179 180 self.assertEqual( 181 'r456789 http://crrev.com/123456 authorABC (at] chromium.org committed "Commit test subject line" ' 182 '\x037tbr=reviewerDEF (at] chromium.org, reviewerGHI (at] chromium.org, reviewerJKL (at] chromium.org notry=TRUE\x03', 183 bot._format_commit_detail("""\ 184 1234commit1234 185 authorABC (at] chromium.org 186 Commit test subject line 187 Multiple 188 lines 189 of 190 description. 191 192 BUG=654321 193 tbr=reviewerDEF (at] chromium.org, reviewerGHI (at] chromium.org, reviewerJKL (at] chromium.org 194 notry=TRUE 195 196 Review URL: https://codereview.chromium.org/123456 197 198 git-svn-id: svn://svn.chromium.org/blink/trunk@456789 bbb929c8-8fbe-4397-9dbb-9b2b20218538 199 """)) 200 201 def test_sanitize_string(self): 202 bot = CommitAnnouncer(MockTool(), "test_password") 203 self.assertEqual('normal ascii', bot._sanitize_string('normal ascii')) 204 self.assertEqual('uni\\u0441ode!', bot._sanitize_string(u'uni\u0441ode!')) 205