/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5387.2.7 by John Arbash Meinel
Merge bzr.dev 5444 to resolve some small text conflicts.
1
# Copyright (C) 2007-2010 Canonical Ltd
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
16
17
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
18
from .. import bugtracker, urlutils
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from . import TestCase, TestCaseWithMemoryTransport
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
20
21
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
22
class ErrorsTest(TestCaseWithMemoryTransport):
23
24
    def test_unknown_bug_tracker_abbreviation(self):
25
        """Test the formatting of UnknownBugTrackerAbbreviation."""
26
        branch = self.make_branch('some_branch')
27
        error = bugtracker.UnknownBugTrackerAbbreviation('xxx', branch)
28
        self.assertEqual(
29
            "Cannot find registered bug tracker called xxx on %s" % branch,
30
            str(error))
31
32
    def test_malformed_bug_identifier(self):
33
        """Test the formatting of MalformedBugIdentifier."""
34
        error = bugtracker.MalformedBugIdentifier(
35
            'bogus', 'reason for bogosity')
36
        self.assertEqual(
37
            'Did not understand bug identifier bogus: reason for bogosity. '
38
            'See "brz help bugs" for more information on this feature.',
39
            str(error))
40
41
    def test_incorrect_url(self):
6940.3.2 by Jelmer Vernooij
Review comments.
42
        err = bugtracker.InvalidBugTrackerURL('foo', 'http://bug.example.com/')
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
43
        self.assertEqual(
44
            ("The URL for bug tracker \"foo\" doesn't contain {id}: "
6940.3.2 by Jelmer Vernooij
Review comments.
45
             "http://bug.example.com/"),
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
46
            str(err))
47
48
2376.4.7 by jml at canonical
- Add docstrings to tests.
49
class TestGetBugURL(TestCaseWithMemoryTransport):
50
    """Tests for bugtracker.get_bug_url"""
51
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
52
    class TransientTracker(object):
53
        """An transient tracker used for testing."""
54
55
        @classmethod
56
        def get(klass, abbreviation, branch):
57
            klass.log.append(('get', abbreviation, branch))
58
            if abbreviation != 'transient':
59
                return None
60
            return klass()
61
62
        def get_bug_url(self, bug_id):
63
            self.log.append(('get_bug_url', bug_id))
6940.3.2 by Jelmer Vernooij
Review comments.
64
            return "http://bugs.example.com/%s" % bug_id
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
65
66
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
67
        super(TestGetBugURL, self).setUp()
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
68
        self.tracker_type = TestGetBugURL.TransientTracker
69
        self.tracker_type.log = []
70
        bugtracker.tracker_registry.register('transient', self.tracker_type)
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
71
        self.addCleanup(bugtracker.tracker_registry.remove, 'transient')
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
72
73
    def test_get_bug_url_for_transient_tracker(self):
2376.4.7 by jml at canonical
- Add docstrings to tests.
74
        branch = self.make_branch('some_branch')
6940.3.2 by Jelmer Vernooij
Review comments.
75
        self.assertEqual('http://bugs.example.com/1234',
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
76
                         bugtracker.get_bug_url('transient', branch, '1234'))
2376.4.7 by jml at canonical
- Add docstrings to tests.
77
        self.assertEqual(
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
78
            [('get', 'transient', branch), ('get_bug_url', '1234')],
79
            self.tracker_type.log)
80
81
    def test_unrecognized_abbreviation_raises_error(self):
82
        """If the abbreviation is unrecognized, then raise an error."""
2376.4.7 by jml at canonical
- Add docstrings to tests.
83
        branch = self.make_branch('some_branch')
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
84
        self.assertRaises(bugtracker.UnknownBugTrackerAbbreviation,
2376.4.7 by jml at canonical
- Add docstrings to tests.
85
                          bugtracker.get_bug_url, 'xxx', branch, '1234')
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
86
        self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log)
2376.4.7 by jml at canonical
- Add docstrings to tests.
87
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
88
2376.4.29 by Jonathan Lange
Tests for builtin trackers.
89
class TestBuiltinTrackers(TestCaseWithMemoryTransport):
90
    """Test that the builtin trackers are registered and return sane URLs."""
91
92
    def test_launchpad_registered(self):
93
        """The Launchpad bug tracker should be registered by default and
94
        generate Launchpad bug page URLs.
95
        """
96
        branch = self.make_branch('some_branch')
97
        tracker = bugtracker.tracker_registry.get_tracker('lp', branch)
98
        self.assertEqual('https://launchpad.net/bugs/1234',
99
                         tracker.get_bug_url('1234'))
100
101
    def test_debian_registered(self):
102
        """The Debian bug tracker should be registered by default and generate
103
        bugs.debian.org bug page URLs.
104
        """
105
        branch = self.make_branch('some_branch')
106
        tracker = bugtracker.tracker_registry.get_tracker('deb', branch)
107
        self.assertEqual('http://bugs.debian.org/1234',
108
                         tracker.get_bug_url('1234'))
109
3270.5.1 by James Westby
Add gnome to the list of known bugtrackers.
110
    def test_gnome_registered(self):
111
        branch = self.make_branch('some_branch')
112
        tracker = bugtracker.tracker_registry.get_tracker('gnome', branch)
113
        self.assertEqual('http://bugzilla.gnome.org/show_bug.cgi?id=1234',
114
                         tracker.get_bug_url('1234'))
115
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
116
    def test_trac_registered(self):
117
        """The Trac bug tracker should be registered by default and generate
118
        Trac bug page URLs when the appropriate configuration is present.
119
        """
120
        branch = self.make_branch('some_branch')
121
        config = branch.get_config()
6940.3.2 by Jelmer Vernooij
Review comments.
122
        config.set_user_option('trac_foo_url', 'http://bugs.example.com/trac')
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
123
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
6940.3.2 by Jelmer Vernooij
Review comments.
124
        self.assertEqual('http://bugs.example.com/trac/ticket/1234',
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
125
                         tracker.get_bug_url('1234'))
126
127
    def test_bugzilla_registered(self):
128
        """The Bugzilla bug tracker should be registered by default and
129
        generate Bugzilla bug page URLs when the appropriate configuration is
130
        present.
131
        """
132
        branch = self.make_branch('some_branch')
133
        config = branch.get_config()
6940.3.2 by Jelmer Vernooij
Review comments.
134
        config.set_user_option('bugzilla_foo_url', 'http://bugs.example.com')
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
135
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
6940.3.2 by Jelmer Vernooij
Review comments.
136
        self.assertEqual('http://bugs.example.com/show_bug.cgi?id=1234',
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
137
                         tracker.get_bug_url('1234'))
138
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
139
    def test_github(self):
140
        branch = self.make_branch('some_branch')
141
        tracker = bugtracker.tracker_registry.get_tracker('github', branch)
142
        self.assertEqual('https://github.com/breezy-team/breezy/issues/1234',
143
                         tracker.get_bug_url('breezy-team/breezy/1234'))
144
3035.3.1 by Lukáš Lalinský
Generic bug tracker configuration.
145
    def test_generic_registered(self):
146
        branch = self.make_branch('some_branch')
147
        config = branch.get_config()
6940.3.2 by Jelmer Vernooij
Review comments.
148
        config.set_user_option('bugtracker_foo_url', 'http://bugs.example.com/{id}/view.html')
3035.3.1 by Lukáš Lalinský
Generic bug tracker configuration.
149
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
6940.3.2 by Jelmer Vernooij
Review comments.
150
        self.assertEqual('http://bugs.example.com/1234/view.html',
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
151
                         tracker.get_bug_url('1234'))
152
153
    def test_generic_registered_non_integer(self):
154
        branch = self.make_branch('some_branch')
155
        config = branch.get_config()
6940.3.2 by Jelmer Vernooij
Review comments.
156
        config.set_user_option('bugtracker_foo_url', 'http://bugs.example.com/{id}/view.html')
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
157
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
6940.3.2 by Jelmer Vernooij
Review comments.
158
        self.assertEqual('http://bugs.example.com/ABC-1234/view.html',
5409.3.1 by Alexandre Garnier
Allow using string bug ID with generic bug trackers.
159
                         tracker.get_bug_url('ABC-1234'))
3035.3.1 by Lukáš Lalinský
Generic bug tracker configuration.
160
3035.3.2 by Lukáš Lalinský
Add tests for InvalidBugTrackerURL.
161
    def test_generic_incorrect_url(self):
162
        branch = self.make_branch('some_branch')
163
        config = branch.get_config()
6940.3.2 by Jelmer Vernooij
Review comments.
164
        config.set_user_option('bugtracker_foo_url', 'http://bugs.example.com/view.html')
3035.3.2 by Lukáš Lalinský
Add tests for InvalidBugTrackerURL.
165
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
166
        self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
167
                '1234')
3035.3.1 by Lukáš Lalinský
Generic bug tracker configuration.
168
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
169
170
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
171
3329.1.1 by Ian Clatworthy
Add gnome to list of known bugtrackers (James Westby, Andrew Cowie)
172
    def test_appends_id_to_base_url(self):
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
173
        """The URL of a bug is the base URL joined to the identifier."""
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
174
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
175
                'http://bugs.example.com/foo')
176
        self.assertEqual('http://bugs.example.com/foo1234', tracker.get_bug_url('1234'))
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
177
2376.4.23 by Jonathan Lange
Change 'tag' to 'abbreviated_tracker_name'
178
    def test_returns_tracker_if_abbreviation_matches(self):
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
179
        """The get() method should return an instance of the tracker if the
180
        given abbreviation matches the tracker's abbreviated name.
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
181
        """
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
182
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
183
                'http://bugs.example.com/')
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
184
        branch = self.make_branch('some_branch')
2376.4.25 by Jonathan Lange
Make singleton bug tracker thing work via instances.
185
        self.assertIs(tracker, tracker.get('xxx', branch))
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
186
2376.4.23 by Jonathan Lange
Change 'tag' to 'abbreviated_tracker_name'
187
    def test_returns_none_if_abbreviation_doesnt_match(self):
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
188
        """The get() method should return None if the given abbreviated name
189
        doesn't match the tracker's abbreviation.
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
190
        """
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
191
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
192
                'http://bugs.example.com/')
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
193
        branch = self.make_branch('some_branch')
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
194
        self.assertIs(None, tracker.get('yyy', branch))
195
196
    def test_doesnt_consult_branch(self):
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
197
        """A UniqueIntegerBugTracker shouldn't consult the branch for tracker
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
198
        information.
199
        """
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
200
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
201
                'http://bugs.example.com/')
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
202
        self.assertIs(tracker, tracker.get('xxx', None))
203
        self.assertIs(None, tracker.get('yyy', None))
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
204
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
205
    def test_check_bug_id_only_accepts_integers(self):
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
206
        """A UniqueIntegerBugTracker accepts integers as bug IDs."""
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
207
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
208
                'http://bugs.example.com/')
2376.4.28 by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation
209
        tracker.check_bug_id('1234')
210
211
    def test_check_bug_id_doesnt_accept_non_integers(self):
212
        """A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
3270.5.3 by James Westby
No longer add an extra class to accomoadate gnome.
213
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
214
                'http://bugs.example.com/')
2376.4.26 by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation.
215
        self.assertRaises(
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
216
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
2376.4.20 by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker
217
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
218
219
class TestProjectIntegerBugTracker(TestCaseWithMemoryTransport):
220
221
    def test_appends_id_to_base_url(self):
222
        """The URL of a bug is the base URL joined to the identifier."""
223
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
224
                'http://bugs.example.com/{project}/{id}')
225
        self.assertEqual('http://bugs.example.com/foo/1234', tracker.get_bug_url('foo/1234'))
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
226
227
    def test_returns_tracker_if_abbreviation_matches(self):
228
        """The get() method should return an instance of the tracker if the
229
        given abbreviation matches the tracker's abbreviated name.
230
        """
231
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
232
                'http://bugs.example.com/{project}/{id}')
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
233
        branch = self.make_branch('some_branch')
234
        self.assertIs(tracker, tracker.get('xxx', branch))
235
236
    def test_returns_none_if_abbreviation_doesnt_match(self):
237
        """The get() method should return None if the given abbreviated name
238
        doesn't match the tracker's abbreviation.
239
        """
240
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
241
                'http://bugs.example.com/{project}/{id}')
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
242
        branch = self.make_branch('some_branch')
243
        self.assertIs(None, tracker.get('yyy', branch))
244
245
    def test_doesnt_consult_branch(self):
6940.3.2 by Jelmer Vernooij
Review comments.
246
        """Shouldn't consult the branch for tracker information.
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
247
        """
248
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
249
                'http://bugs.example.com/{project}/{id}')
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
250
        self.assertIs(tracker, tracker.get('xxx', None))
251
        self.assertIs(None, tracker.get('yyy', None))
252
253
    def test_check_bug_id_only_accepts_project_integers(self):
6940.3.2 by Jelmer Vernooij
Review comments.
254
        """Accepts integers as bug IDs."""
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
255
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
256
                'http://bugs.example.com/{project}/{id}')
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
257
        tracker.check_bug_id('project/1234')
258
259
    def test_check_bug_id_doesnt_accept_non_project_integers(self):
6940.3.2 by Jelmer Vernooij
Review comments.
260
        """Rejects non-integers as bug IDs."""
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
261
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
6940.3.2 by Jelmer Vernooij
Review comments.
262
                'http://bugs.example.com/{project}/{id}')
6940.3.1 by Jelmer Vernooij
Add a 'github' bugtracker.
263
        self.assertRaises(
264
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
265
        self.assertRaises(
266
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, '1234')
267
268
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
269
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
270
    """Tests for URLParametrizedBugTracker."""
2376.4.22 by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in
271
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
272
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
273
        super(TestURLParametrizedBugTracker, self).setUp()
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
274
        self.url = 'http://twistedmatrix.com/trac'
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
275
        self.tracker = bugtracker.URLParametrizedBugTracker('some', 'ticket/')
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
276
277
    def test_get_with_unsupported_tag(self):
2376.4.7 by jml at canonical
- Add docstrings to tests.
278
        """If asked for an unrecognized or unconfigured tag, return None."""
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
279
        branch = self.make_branch('some_branch')
2376.4.42 by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to
280
        self.assertEqual(None, self.tracker.get('lp', branch))
281
        self.assertEqual(None, self.tracker.get('twisted', branch))
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
282
283
    def test_get_with_supported_tag(self):
2376.4.42 by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to
284
        """If asked for a valid tag, return a tracker instance that can map bug
285
        IDs to <base_url>/<bug_area> + <bug_id>."""
286
        bugtracker.tracker_registry.register('some', self.tracker)
4985.2.1 by Vincent Ladeuil
Deploy addAttrCleanup on the whole test suite.
287
        self.addCleanup(bugtracker.tracker_registry.remove, 'some')
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
288
2376.4.4 by jml at canonical
Beginnings of generic bug-tracker plugin system.
289
        branch = self.make_branch('some_branch')
290
        config = branch.get_config()
2376.4.40 by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication.
291
        config.set_user_option('some_twisted_url', self.url)
2376.4.42 by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to
292
        tracker = self.tracker.get('twisted', branch)
293
        self.assertEqual(
294
            urlutils.join(self.url, 'ticket/') + '1234',
295
            tracker.get_bug_url('1234'))
2376.4.7 by jml at canonical
- Add docstrings to tests.
296
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
297
    def test_get_bug_url_for_integer_id(self):
298
        self.tracker.check_bug_id('1234')
299
300
    def test_get_bug_url_for_non_integer_id(self):
301
        self.tracker.check_bug_id('ABC-1234')
302
303
304
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
305
    """Tests for URLParametrizedIntegerBugTracker."""
306
307
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
308
        super(TestURLParametrizedIntegerBugTracker, self).setUp()
5409.3.2 by Alexandre Garnier
Add tests for URLParametrizedBugTracker rather than reusing existing tests
309
        self.url = 'http://twistedmatrix.com/trac'
310
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
311
                                                                   'ticket/')
312
2376.4.30 by Jonathan Lange
Support for Bugzilla bug trackers.
313
    def test_get_bug_url_for_bad_bug(self):
314
        """When given a bug identifier that is invalid for Trac, get_bug_url
315
        should raise an error.
316
        """
317
        self.assertRaises(
6729.4.1 by Jelmer Vernooij
Move bugtracker errors to breezy.bugtracker.
318
            bugtracker.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
4119.4.2 by Jonathan Lange
Some refactoring, some unit tests.
319
320
321
class TestPropertyEncoding(TestCase):
322
    """Tests for how the bug URLs are encoded as revision properties."""
323
324
    def test_encoding_one(self):
325
        self.assertEqual(
326
            'http://example.com/bugs/1 fixed',
327
            bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
328
329
    def test_encoding_zero(self):
330
        self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
331
332
    def test_encoding_two(self):
333
        self.assertEqual(
334
            'http://example.com/bugs/1 fixed\n'
335
            'http://example.com/bugs/2 fixed',
336
            bugtracker.encode_fixes_bug_urls(
337
                ['http://example.com/bugs/1', 'http://example.com/bugs/2']))