1545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# Copyright (C) 2010 Google Inc. All rights reserved. 2545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# 3545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# Redistribution and use in source and binary forms, with or without 4545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# modification, are permitted provided that the following conditions are 5545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# met: 6545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# 7545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# * Redistributions of source code must retain the above copyright 8545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# notice, this list of conditions and the following disclaimer. 9545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# * Redistributions in binary form must reproduce the above 10545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# copyright notice, this list of conditions and the following disclaimer 11545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# in the documentation and/or other materials provided with the 12545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# distribution. 13545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# * Neither the name of Google Inc. nor the names of its 14545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# contributors may be used to endorse or promote products derived from 15545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# this software without specific prior written permission. 16545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# 17545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch 29545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochimport os 30545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochimport unittest 31545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch 32545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochfrom webkitpy.common.checkout.changelog_unittest import ChangeLogTest 33545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochfrom webkitpy.common.system.outputcapture import OutputCapture 34e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkefrom webkitpy.tool.mocktool import MockOptions, MockTool 35545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochfrom webkitpy.tool.steps.preparechangelog import PrepareChangeLog 36545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch 37545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch 38545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass PrepareChangeLogTest(ChangeLogTest): 39545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch def test_ensure_bug_url(self): 40545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch capture = OutputCapture() 41e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke step = PrepareChangeLog(MockTool(), MockOptions()) 42545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) 43545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch changelog_path = self._write_tmp_file_with_contents(changelog_contents.encode("utf-8")) 44545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch state = { 45545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch "bug_title": "Example title", 46545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch "bug_id": 1234, 47545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch "changelogs": [changelog_path], 48545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch } 49545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch capture.assert_outputs(self, step.run, [state]) 50545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch actual_contents = self._read_file_contents(changelog_path, "utf-8") 51545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch expected_message = "Example title\n http://example.com/1234" 52545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch expected_contents = changelog_contents.replace("Need a short description and bug URL (OOPS!)", expected_message) 53545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch os.remove(changelog_path) 54545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch self.assertEquals(actual_contents, expected_contents) 55