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 __future__ import absolute_import
21
from ... import commitfromnews
26
from ....tests import TestCaseWithTransport
28
INITIAL_NEWS_CONTENT = """----------------------------
29
commitfromnews release notes
30
----------------------------
38
* Created plugin, basic functionality of looking for NEWS and including the
43
class TestCommitTemplate(TestCaseWithTransport):
45
def capture_template(self, commit, message):
46
self.commits.append(commit)
47
self.messages.append(message)
49
message = 'let this commit succeed I command thee.'
52
def enable_commitfromnews(self):
53
stack= config.GlobalStack()
54
stack.set("commit.template_from_files", ["NEWS"])
56
def setup_capture(self):
57
commitfromnews.register()
58
msgeditor.hooks.install_named_hook('commit_message_template',
59
self.capture_template, 'commitfromnews test template')
63
def test_initial(self):
65
self.enable_commitfromnews()
66
builder = self.make_branch_builder('test')
67
builder.start_series()
68
builder.build_snapshot('BASE-id', None,
69
[('add', ('', None, 'directory', None)),
70
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
72
message_callback=msgeditor.generate_commit_message_template)
73
builder.finish_series()
74
self.assertEqual([None], self.messages)
76
def test_added_NEWS(self):
78
self.enable_commitfromnews()
79
builder = self.make_branch_builder('test')
80
builder.start_series()
81
content = INITIAL_NEWS_CONTENT
82
builder.build_snapshot('BASE-id', None,
83
[('add', ('', None, 'directory', None)),
84
('add', ('NEWS', 'foo-id', 'file', content)),
86
message_callback=msgeditor.generate_commit_message_template)
87
builder.finish_series()
88
self.assertEqual([content], self.messages)
90
def test_changed_NEWS(self):
92
self.enable_commitfromnews()
93
builder = self.make_branch_builder('test')
94
builder.start_series()
95
orig_content = INITIAL_NEWS_CONTENT
96
mod_content = """----------------------------
97
commitfromnews release notes
98
----------------------------
100
NEXT (In development)
101
---------------------
106
* Added a new change to the system.
108
* Created plugin, basic functionality of looking for NEWS and including the
111
change_content = """* Added a new change to the system.
114
builder.build_snapshot('BASE-id', None,
115
[('add', ('', None, 'directory', None)),
116
('add', ('NEWS', 'foo-id', 'file', orig_content)),
118
builder.build_snapshot(None, None,
119
[('modify', ('foo-id', mod_content)),
121
message_callback=msgeditor.generate_commit_message_template)
122
builder.finish_series()
123
self.assertEqual([change_content], self.messages)
125
def test_fix_bug(self):
127
self.enable_commitfromnews()
128
builder = self.make_branch_builder('test')
129
builder.start_series()
130
orig_content = INITIAL_NEWS_CONTENT
131
mod_content = """----------------------------
132
commitfromnews release notes
133
----------------------------
135
NEXT (In development)
136
---------------------
141
* Created plugin, basic functionality of looking for NEWS and including the
144
* Fixed a horrible bug. (lp:523423)
148
* Fixed a horrible bug. (lp:523423)
151
builder.build_snapshot('BASE-id', None,
152
[('add', ('', None, 'directory', None)),
153
('add', ('NEWS', 'foo-id', 'file', orig_content)),
155
builder.build_snapshot(None, None,
156
[('modify', ('foo-id', mod_content)),
158
message_callback=msgeditor.generate_commit_message_template)
159
builder.finish_series()
160
self.assertEqual([change_content], self.messages)
161
self.assertEqual(1, len(self.commits))
162
self.assertEquals('https://launchpad.net/bugs/523423 fixed',
163
self.commits[0].revprops['bugs'])
165
def _todo_test_passes_messages_through(self):