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 26import unittest 27 28from webkitpy.tool.bot.commitannouncer import CommitAnnouncer 29from webkitpy.tool.mocktool import MockTool 30 31 32class 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@chromium.org committed "Commit test subject line"', 38 bot._format_commit_detail("""\ 391234commit1234 40authorABC@chromium.org 41Commit test subject line 42Multiple 43lines 44of 45description. 46 47BUG=654321 48 49Review URL: https://codereview.chromium.org/123456 50 51git-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@chromium.org committed "Commit test subject line"', 57 bot._format_commit_detail("""\ 581234commit1234 59authorABC@chromium.org 60Commit test subject line 61Multiple 62lines 63of 64description. 65 66BUG=654321 67 68git-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@chromium.org committed "Commit test subject line"', 73 bot._format_commit_detail("""\ 741234commit1234 75authorABC@chromium.org 76Commit test subject line 77Multiple 78lines 79of 80description. 81 82BUG=654321 83 84Review URL: https://codereview.chromium.org/123456 85""")) 86 87 self.assertEqual( 88 'https://chromium.googlesource.com/chromium/blink/+/1234comm authorABC@chromium.org committed "Commit test subject line"', 89 bot._format_commit_detail("""\ 901234commit1234 91authorABC@chromium.org 92Commit test subject line 93Multiple 94lines 95of 96description. 97""")) 98 99 self.assertEqual( 100 'r456789 http://crrev.com/123456 authorABC@chromium.org committed "Commit test subject line"', 101 bot._format_commit_detail("""\ 1021234commit1234 103authorABC@chromium.org 104Commit test subject line 105Multiple 106lines 107of 108description. 109Review URL: http://fake.review.url 110git-svn-id: svn://svn.chromium.org/blink/trunk@000000 Fake-SVN-number 111 112BUG=654321 113 114Review URL: https://codereview.chromium.org/123456 115 116git-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@chromium.org committed "Commit test subject line" ' 121 '\x037TBR=reviewerDEF@chromium.org\x03', 122 bot._format_commit_detail("""\ 1231234commit1234 124authorABC@chromium.org 125Commit test subject line 126Multiple 127lines 128of 129description. 130 131BUG=654321 132TBR=reviewerDEF@chromium.org 133 134Review URL: https://codereview.chromium.org/123456 135 136git-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@chromium.org committed "Commit test subject line" ' 141 '\x037NOTRY=true\x03', 142 bot._format_commit_detail("""\ 1431234commit1234 144authorABC@chromium.org 145Commit test subject line 146Multiple 147lines 148of 149description. 150 151BUG=654321 152NOTRY=true 153 154Review URL: https://codereview.chromium.org/123456 155 156git-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@chromium.org committed "Commit test subject line" ' 161 '\x037NOTRY=true TBR=reviewerDEF@chromium.org\x03', 162 bot._format_commit_detail("""\ 1631234commit1234 164authorABC@chromium.org 165Commit test subject line 166Multiple 167lines 168of 169description. 170 171NOTRY=true 172BUG=654321 173TBR=reviewerDEF@chromium.org 174 175Review URL: https://codereview.chromium.org/123456 176 177git-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@chromium.org committed "Commit test subject line" ' 182 '\x037tbr=reviewerDEF@chromium.org, reviewerGHI@chromium.org, reviewerJKL@chromium.org notry=TRUE\x03', 183 bot._format_commit_detail("""\ 1841234commit1234 185authorABC@chromium.org 186Commit test subject line 187Multiple 188lines 189of 190description. 191 192BUG=654321 193tbr=reviewerDEF@chromium.org, reviewerGHI@chromium.org, reviewerJKL@chromium.org 194notry=TRUE 195 196Review URL: https://codereview.chromium.org/123456 197 198git-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