/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
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
6690.6.1 by Jelmer Vernooij
Bundle the commitfromnews plugin.
19
from __future__ import absolute_import
20
21
from ... import commitfromnews
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
22
from .... import (
23
    config,
24
    msgeditor,
25
    )
6690.6.1 by Jelmer Vernooij
Bundle the commitfromnews plugin.
26
from ....tests import TestCaseWithTransport
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
27
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
28
INITIAL_NEWS_CONTENT = """----------------------------
29
commitfromnews release notes
30
----------------------------
31
32
NEXT (In development)
33
---------------------
34
35
IMPROVEMENTS
36
~~~~~~~~~~~~
37
38
* Created plugin, basic functionality of looking for NEWS and including the
39
  NEWS diff.
40
"""
41
42
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
43
class TestCommitTemplate(TestCaseWithTransport):
44
45
    def capture_template(self, commit, message):
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
46
        self.commits.append(commit)
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
47
        self.messages.append(message)
48
        if message is None:
49
            message = 'let this commit succeed I command thee.'
50
        return message
51
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
52
    def enable_commitfromnews(self):
53
        stack= config.GlobalStack()
54
        stack.set("commit.template_from_files", ["NEWS"])
55
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
56
    def setup_capture(self):
57
        commitfromnews.register()
58
        msgeditor.hooks.install_named_hook('commit_message_template',
59
            self.capture_template, 'commitfromnews test template')
60
        self.messages = []
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
61
        self.commits = []
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
62
63
    def test_initial(self):
64
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
65
        self.enable_commitfromnews()
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
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')),
71
             ],
72
            message_callback=msgeditor.generate_commit_message_template)
73
        builder.finish_series()
74
        self.assertEqual([None], self.messages)
75
76
    def test_added_NEWS(self):
77
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
78
        self.enable_commitfromnews()
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
79
        builder = self.make_branch_builder('test')
80
        builder.start_series()
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
81
        content = INITIAL_NEWS_CONTENT
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
82
        builder.build_snapshot('BASE-id', None,
83
            [('add', ('', None, 'directory', None)),
84
             ('add', ('NEWS', 'foo-id', 'file', content)),
85
             ],
86
            message_callback=msgeditor.generate_commit_message_template)
87
        builder.finish_series()
88
        self.assertEqual([content], self.messages)
89
90
    def test_changed_NEWS(self):
91
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
92
        self.enable_commitfromnews()
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
93
        builder = self.make_branch_builder('test')
94
        builder.start_series()
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
95
        orig_content = INITIAL_NEWS_CONTENT
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
96
        mod_content = """----------------------------
97
commitfromnews release notes
98
----------------------------
99
100
NEXT (In development)
101
---------------------
102
103
IMPROVEMENTS
104
~~~~~~~~~~~~
105
106
* Added a new change to the system.
107
108
* Created plugin, basic functionality of looking for NEWS and including the
109
  NEWS diff.
110
"""
111
        change_content = """* Added a new change to the system.
112
113
"""
114
        builder.build_snapshot('BASE-id', None,
115
            [('add', ('', None, 'directory', None)),
116
             ('add', ('NEWS', 'foo-id', 'file', orig_content)),
117
             ])
118
        builder.build_snapshot(None, None,
119
            [('modify', ('foo-id', mod_content)),
120
             ],
121
            message_callback=msgeditor.generate_commit_message_template)
122
        builder.finish_series()
123
        self.assertEqual([change_content], self.messages)
124
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
125
    def test_fix_bug(self):
126
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
127
        self.enable_commitfromnews()
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
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
----------------------------
134
135
NEXT (In development)
136
---------------------
137
138
IMPROVEMENTS
139
~~~~~~~~~~~~
140
141
* Created plugin, basic functionality of looking for NEWS and including the
142
  NEWS diff.
143
0.192.3 by Jelmer Vernooij
Match on lp:BUGNO rather than #BUGNO
144
* Fixed a horrible bug. (lp:523423)
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
145
146
"""
147
        change_content = """
0.192.3 by Jelmer Vernooij
Match on lp:BUGNO rather than #BUGNO
148
* Fixed a horrible bug. (lp:523423)
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
149
150
"""
151
        builder.build_snapshot('BASE-id', None,
152
            [('add', ('', None, 'directory', None)),
153
             ('add', ('NEWS', 'foo-id', 'file', orig_content)),
154
             ])
155
        builder.build_snapshot(None, None,
156
            [('modify', ('foo-id', mod_content)),
157
             ],
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'])
164
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
165
    def _todo_test_passes_messages_through(self):
166
        pass