/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Copyright (C) 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Tests for the commit template creation."""

from __future__ import absolute_import

from ... import commitfromnews
from .... import (
    config,
    msgeditor,
    )
from ....tests import TestCaseWithTransport

INITIAL_NEWS_CONTENT = """----------------------------
commitfromnews release notes
----------------------------

NEXT (In development)
---------------------

IMPROVEMENTS
~~~~~~~~~~~~

* Created plugin, basic functionality of looking for NEWS and including the
  NEWS diff.
"""


class TestCommitTemplate(TestCaseWithTransport):

    def capture_template(self, commit, message):
        self.commits.append(commit)
        self.messages.append(message)
        if message is None:
            message = 'let this commit succeed I command thee.'
        return message

    def enable_commitfromnews(self):
        stack= config.GlobalStack()
        stack.set("commit.template_from_files", ["NEWS"])

    def setup_capture(self):
        commitfromnews.register()
        msgeditor.hooks.install_named_hook('commit_message_template',
            self.capture_template, 'commitfromnews test template')
        self.messages = []
        self.commits = []

    def test_initial(self):
        self.setup_capture()
        self.enable_commitfromnews()
        builder = self.make_branch_builder('test')
        builder.start_series()
        builder.build_snapshot(None,
            [('add', ('', None, 'directory', None)),
             ('add', ('foo', b'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
             ],
            message_callback=msgeditor.generate_commit_message_template,
            revision_id=b'BASE-id')
        builder.finish_series()
        self.assertEqual([None], self.messages)

    def test_added_NEWS(self):
        self.setup_capture()
        self.enable_commitfromnews()
        builder = self.make_branch_builder('test')
        builder.start_series()
        content = INITIAL_NEWS_CONTENT
        builder.build_snapshot(None,
            [('add', ('', None, 'directory', None)),
             ('add', ('NEWS', b'foo-id', 'file', content)),
             ],
            message_callback=msgeditor.generate_commit_message_template,
            revision_id=b'BASE-id')
        builder.finish_series()
        self.assertEqual([content], self.messages)

    def test_changed_NEWS(self):
        self.setup_capture()
        self.enable_commitfromnews()
        builder = self.make_branch_builder('test')
        builder.start_series()
        orig_content = INITIAL_NEWS_CONTENT
        mod_content = b"""----------------------------
commitfromnews release notes
----------------------------

NEXT (In development)
---------------------

IMPROVEMENTS
~~~~~~~~~~~~

* Added a new change to the system.

* Created plugin, basic functionality of looking for NEWS and including the
  NEWS diff.
"""
        change_content = """* Added a new change to the system.

"""
        builder.build_snapshot(None,
            [('add', ('', None, 'directory', None)),
             ('add', ('NEWS', b'foo-id', 'file', orig_content)),
             ], revision_id=b'BASE-id')
        builder.build_snapshot(None,
            [('modify', ('NEWS', mod_content)),
             ],
            message_callback=msgeditor.generate_commit_message_template)
        builder.finish_series()
        self.assertEqual([change_content], self.messages)

    def test_fix_bug(self):
        self.setup_capture()
        self.enable_commitfromnews()
        builder = self.make_branch_builder('test')
        builder.start_series()
        orig_content = INITIAL_NEWS_CONTENT
        mod_content = b"""----------------------------
commitfromnews release notes
----------------------------

NEXT (In development)
---------------------

IMPROVEMENTS
~~~~~~~~~~~~

* Created plugin, basic functionality of looking for NEWS and including the
  NEWS diff.

* Fixed a horrible bug. (lp:523423)

"""
        change_content = """
* Fixed a horrible bug. (lp:523423)

"""
        builder.build_snapshot(None,
            [('add', ('', None, 'directory', None)),
             ('add', ('NEWS', b'foo-id', 'file', orig_content)),
             ], revision_id=b'BASE-id')
        builder.build_snapshot(None,
            [('modify', ('NEWS', mod_content)),
             ],
            message_callback=msgeditor.generate_commit_message_template)
        builder.finish_series()
        self.assertEqual([change_content], self.messages)
        self.assertEqual(1, len(self.commits))
        self.assertEquals('https://launchpad.net/bugs/523423 fixed',
                          self.commits[0].revprops['bugs'])

    def _todo_test_passes_messages_through(self):
        pass