1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for the commit template creation."""
19
from bzrlib.plugins import commitfromnews
20
from bzrlib import msgeditor
21
from bzrlib.tests import TestCaseWithTransport
23
class TestCommitTemplate(TestCaseWithTransport):
25
def capture_template(self, commit, message):
26
self.messages.append(message)
28
message = 'let this commit succeed I command thee.'
31
def setup_capture(self):
32
commitfromnews.register()
33
msgeditor.hooks.install_named_hook('commit_message_template',
34
self.capture_template, 'commitfromnews test template')
37
def test_initial(self):
39
builder = self.make_branch_builder('test')
40
builder.start_series()
41
builder.build_snapshot('BASE-id', None,
42
[('add', ('', None, 'directory', None)),
43
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
45
message_callback=msgeditor.generate_commit_message_template)
46
builder.finish_series()
47
self.assertEqual([None], self.messages)
49
def test_added_NEWS(self):
51
builder = self.make_branch_builder('test')
52
builder.start_series()
53
content = """----------------------------
54
commitfromnews release notes
55
----------------------------
63
* Created plugin, basic functionality of looking for NEWS and including the
66
builder.build_snapshot('BASE-id', None,
67
[('add', ('', None, 'directory', None)),
68
('add', ('NEWS', 'foo-id', 'file', content)),
70
message_callback=msgeditor.generate_commit_message_template)
71
builder.finish_series()
72
self.assertEqual([content], self.messages)
74
def test_changed_NEWS(self):
76
builder = self.make_branch_builder('test')
77
builder.start_series()
78
orig_content = """----------------------------
79
commitfromnews release notes
80
----------------------------
88
* Created plugin, basic functionality of looking for NEWS and including the
91
mod_content = """----------------------------
92
commitfromnews release notes
93
----------------------------
101
* Added a new change to the system.
103
* Created plugin, basic functionality of looking for NEWS and including the
106
change_content = """* Added a new change to the system.
109
builder.build_snapshot('BASE-id', None,
110
[('add', ('', None, 'directory', None)),
111
('add', ('NEWS', 'foo-id', 'file', orig_content)),
113
builder.build_snapshot(None, None,
114
[('modify', ('foo-id', mod_content)),
116
message_callback=msgeditor.generate_commit_message_template)
117
builder.finish_series()
118
self.assertEqual([change_content], self.messages)
120
def _todo_test_passes_messages_through(self):