/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/commitfromnews/tests/test_committemplate.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-24 01:09:25 UTC
  • mfrom: (6740 trunk)
  • mto: This revision was merged to the branch mainline in revision 6743.
  • Revision ID: jelmer@jelmer.uk-20170724010925-nted35vp0ufbs3p2
Merge trunk.

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 __future__ import absolute_import
 
20
 
 
21
from ... import commitfromnews
 
22
from .... import (
 
23
    config,
 
24
    msgeditor,
 
25
    )
 
26
from ....tests import TestCaseWithTransport
 
27
 
 
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
 
 
43
class TestCommitTemplate(TestCaseWithTransport):
 
44
 
 
45
    def capture_template(self, commit, message):
 
46
        self.commits.append(commit)
 
47
        self.messages.append(message)
 
48
        if message is None:
 
49
            message = 'let this commit succeed I command thee.'
 
50
        return message
 
51
 
 
52
    def enable_commitfromnews(self):
 
53
        stack= config.GlobalStack()
 
54
        stack.set("commit.template_from_files", ["NEWS"])
 
55
 
 
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 = []
 
61
        self.commits = []
 
62
 
 
63
    def test_initial(self):
 
64
        self.setup_capture()
 
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')),
 
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()
 
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)),
 
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()
 
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
----------------------------
 
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
 
 
125
    def test_fix_bug(self):
 
126
        self.setup_capture()
 
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
----------------------------
 
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
 
 
144
* Fixed a horrible bug. (lp:523423)
 
145
 
 
146
"""
 
147
        change_content = """
 
148
* Fixed a horrible bug. (lp:523423)
 
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
 
 
165
    def _todo_test_passes_messages_through(self):
 
166
        pass