~bzr/bzr-commitfromnews/trunk

« back to all changes in this revision

Viewing changes to tests/test_committemplate.py

  • Committer: Robert Collins
  • Date: 2010-02-27 12:17:25 UTC
  • Revision ID: robertc@robertcollins.net-20100227121725-quxul8rc0tkv552n
Created plugin, basic functionality of looking for NEWS and including the
NEWS diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Tests for the commit template creation."""
 
18
 
 
19
from bzrlib.plugins import commitfromnews
 
20
from bzrlib import msgeditor
 
21
from bzrlib.tests import TestCaseWithTransport
 
22
 
 
23
class TestCommitTemplate(TestCaseWithTransport):
 
24
 
 
25
    def capture_template(self, commit, message):
 
26
        self.messages.append(message)
 
27
        if message is None:
 
28
            message = 'let this commit succeed I command thee.'
 
29
        return message
 
30
 
 
31
    def setup_capture(self):
 
32
        commitfromnews.register()
 
33
        msgeditor.hooks.install_named_hook('commit_message_template',
 
34
            self.capture_template, 'commitfromnews test template')
 
35
        self.messages = []
 
36
 
 
37
    def test_initial(self):
 
38
        self.setup_capture()
 
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')),
 
44
             ],
 
45
            message_callback=msgeditor.generate_commit_message_template)
 
46
        builder.finish_series()
 
47
        self.assertEqual([None], self.messages)
 
48
 
 
49
    def test_added_NEWS(self):
 
50
        self.setup_capture()
 
51
        builder = self.make_branch_builder('test')
 
52
        builder.start_series()
 
53
        content = """----------------------------
 
54
commitfromnews release notes
 
55
----------------------------
 
56
 
 
57
NEXT (In development)
 
58
---------------------
 
59
 
 
60
IMPROVEMENTS
 
61
~~~~~~~~~~~~
 
62
 
 
63
* Created plugin, basic functionality of looking for NEWS and including the
 
64
  NEWS diff.
 
65
"""
 
66
        builder.build_snapshot('BASE-id', None,
 
67
            [('add', ('', None, 'directory', None)),
 
68
             ('add', ('NEWS', 'foo-id', 'file', content)),
 
69
             ],
 
70
            message_callback=msgeditor.generate_commit_message_template)
 
71
        builder.finish_series()
 
72
        self.assertEqual([content], self.messages)
 
73
 
 
74
    def test_changed_NEWS(self):
 
75
        self.setup_capture()
 
76
        builder = self.make_branch_builder('test')
 
77
        builder.start_series()
 
78
        orig_content = """----------------------------
 
79
commitfromnews release notes
 
80
----------------------------
 
81
 
 
82
NEXT (In development)
 
83
---------------------
 
84
 
 
85
IMPROVEMENTS
 
86
~~~~~~~~~~~~
 
87
 
 
88
* Created plugin, basic functionality of looking for NEWS and including the
 
89
  NEWS diff.
 
90
"""
 
91
        mod_content = """----------------------------
 
92
commitfromnews release notes
 
93
----------------------------
 
94
 
 
95
NEXT (In development)
 
96
---------------------
 
97
 
 
98
IMPROVEMENTS
 
99
~~~~~~~~~~~~
 
100
 
 
101
* Added a new change to the system.
 
102
 
 
103
* Created plugin, basic functionality of looking for NEWS and including the
 
104
  NEWS diff.
 
105
"""
 
106
        change_content = """* Added a new change to the system.
 
107
 
 
108
"""
 
109
        builder.build_snapshot('BASE-id', None,
 
110
            [('add', ('', None, 'directory', None)),
 
111
             ('add', ('NEWS', 'foo-id', 'file', orig_content)),
 
112
             ])
 
113
        builder.build_snapshot(None, None,
 
114
            [('modify', ('foo-id', mod_content)),
 
115
             ],
 
116
            message_callback=msgeditor.generate_commit_message_template)
 
117
        builder.finish_series()
 
118
        self.assertEqual([change_content], self.messages)
 
119
 
 
120
    def _todo_test_passes_messages_through(self):
 
121
        pass