/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
7027.8.1 by Jelmer Vernooij
Fix commitfromnews tests on python3.
28
INITIAL_NEWS_CONTENT = b"""----------------------------
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
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:
7027.8.1 by Jelmer Vernooij
Fix commitfromnews tests on python3.
49
            message = u'let this commit succeed I command thee.'
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
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()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
68
        builder.build_snapshot(None,
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
69
            [('add', ('', None, 'directory', None)),
7027.8.1 by Jelmer Vernooij
Fix commitfromnews tests on python3.
70
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
71
             ],
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
72
            message_callback=msgeditor.generate_commit_message_template,
6855.4.1 by Jelmer Vernooij
Yet more bees.
73
            revision_id=b'BASE-id')
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
74
        builder.finish_series()
75
        self.assertEqual([None], self.messages)
76
77
    def test_added_NEWS(self):
78
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
79
        self.enable_commitfromnews()
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
80
        builder = self.make_branch_builder('test')
81
        builder.start_series()
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
82
        content = INITIAL_NEWS_CONTENT
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
83
        builder.build_snapshot(None,
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
84
            [('add', ('', None, 'directory', None)),
6855.4.1 by Jelmer Vernooij
Yet more bees.
85
             ('add', ('NEWS', b'foo-id', 'file', content)),
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
86
             ],
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
87
            message_callback=msgeditor.generate_commit_message_template,
6855.4.1 by Jelmer Vernooij
Yet more bees.
88
            revision_id=b'BASE-id')
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
89
        builder.finish_series()
7027.8.1 by Jelmer Vernooij
Fix commitfromnews tests on python3.
90
        self.assertEqual([content.decode('utf-8')], self.messages)
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
91
92
    def test_changed_NEWS(self):
93
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
94
        self.enable_commitfromnews()
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
95
        builder = self.make_branch_builder('test')
96
        builder.start_series()
0.192.1 by Jelmer Vernooij
tests: Put initial content in a variable.
97
        orig_content = INITIAL_NEWS_CONTENT
6883.22.11 by Jelmer Vernooij
merge trunk
98
        mod_content = b"""----------------------------
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
99
commitfromnews release notes
100
----------------------------
101
102
NEXT (In development)
103
---------------------
104
105
IMPROVEMENTS
106
~~~~~~~~~~~~
107
108
* Added a new change to the system.
109
110
* Created plugin, basic functionality of looking for NEWS and including the
111
  NEWS diff.
112
"""
113
        change_content = """* Added a new change to the system.
114
115
"""
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
116
        builder.build_snapshot(None,
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
117
            [('add', ('', None, 'directory', None)),
6855.4.1 by Jelmer Vernooij
Yet more bees.
118
             ('add', ('NEWS', b'foo-id', 'file', orig_content)),
119
             ], revision_id=b'BASE-id')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
120
        builder.build_snapshot(None,
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
121
            [('modify', ('NEWS', mod_content)),
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
122
             ],
123
            message_callback=msgeditor.generate_commit_message_template)
124
        builder.finish_series()
125
        self.assertEqual([change_content], self.messages)
126
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
127
    def test_fix_bug(self):
128
        self.setup_capture()
6739 by Jelmer Vernooij
Merge lp:~jelmer/brz/bundle-commitfromnews.
129
        self.enable_commitfromnews()
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
130
        builder = self.make_branch_builder('test')
131
        builder.start_series()
132
        orig_content = INITIAL_NEWS_CONTENT
6883.22.11 by Jelmer Vernooij
merge trunk
133
        mod_content = b"""----------------------------
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
134
commitfromnews release notes
135
----------------------------
136
137
NEXT (In development)
138
---------------------
139
140
IMPROVEMENTS
141
~~~~~~~~~~~~
142
143
* Created plugin, basic functionality of looking for NEWS and including the
144
  NEWS diff.
145
0.192.3 by Jelmer Vernooij
Match on lp:BUGNO rather than #BUGNO
146
* Fixed a horrible bug. (lp:523423)
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
147
148
"""
149
        change_content = """
0.192.3 by Jelmer Vernooij
Match on lp:BUGNO rather than #BUGNO
150
* Fixed a horrible bug. (lp:523423)
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
151
152
"""
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
153
        builder.build_snapshot(None,
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
154
            [('add', ('', None, 'directory', None)),
6855.4.1 by Jelmer Vernooij
Yet more bees.
155
             ('add', ('NEWS', b'foo-id', 'file', orig_content)),
156
             ], revision_id=b'BASE-id')
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
157
        builder.build_snapshot(None,
6883.22.1 by Jelmer Vernooij
Take paths in BranchBuilder.
158
            [('modify', ('NEWS', mod_content)),
0.192.2 by Jelmer Vernooij
Initial work on extract bug numbers from NEWS.
159
             ],
160
            message_callback=msgeditor.generate_commit_message_template)
161
        builder.finish_series()
162
        self.assertEqual([change_content], self.messages)
163
        self.assertEqual(1, len(self.commits))
164
        self.assertEquals('https://launchpad.net/bugs/523423 fixed',
165
                          self.commits[0].revprops['bugs'])
166
0.191.1 by Robert Collins
Created plugin, basic functionality of looking for NEWS and including the
167
    def _todo_test_passes_messages_through(self):
168
        pass