15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
from bzrlib import bugtracker, errors, urlutils
19
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
18
from .. import bugtracker, urlutils
19
from . import TestCase, TestCaseWithMemoryTransport
22
class ErrorsTest(TestCaseWithMemoryTransport):
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)
29
"Cannot find registered bug tracker called xxx on %s" % branch,
32
def test_malformed_bug_identifier(self):
33
"""Test the formatting of MalformedBugIdentifier."""
34
error = bugtracker.MalformedBugIdentifier(
35
'bogus', 'reason for bogosity')
37
'Did not understand bug identifier bogus: reason for bogosity. '
38
'See "brz help bugs" for more information on this feature.',
41
def test_incorrect_url(self):
42
err = bugtracker.InvalidBugTrackerURL('foo', 'http://bug.example.com/')
44
("The URL for bug tracker \"foo\" doesn't contain {id}: "
45
"http://bug.example.com/"),
22
49
class TestGetBugURL(TestCaseWithMemoryTransport):
54
81
def test_unrecognized_abbreviation_raises_error(self):
55
82
"""If the abbreviation is unrecognized, then raise an error."""
56
83
branch = self.make_branch('some_branch')
57
self.assertRaises(errors.UnknownBugTrackerAbbreviation,
84
self.assertRaises(bugtracker.UnknownBugTrackerAbbreviation,
58
85
bugtracker.get_bug_url, 'xxx', branch, '1234')
59
86
self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log)
93
120
branch = self.make_branch('some_branch')
94
121
config = branch.get_config()
95
config.set_user_option('trac_foo_url', 'http://bugs.com/trac')
122
config.set_user_option('trac_foo_url', 'http://bugs.example.com/trac')
96
123
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
97
self.assertEqual('http://bugs.com/trac/ticket/1234',
124
self.assertEqual('http://bugs.example.com/trac/ticket/1234',
98
125
tracker.get_bug_url('1234'))
100
127
def test_bugzilla_registered(self):
105
132
branch = self.make_branch('some_branch')
106
133
config = branch.get_config()
107
config.set_user_option('bugzilla_foo_url', 'http://bugs.com')
134
config.set_user_option('bugzilla_foo_url', 'http://bugs.example.com')
108
135
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
109
self.assertEqual('http://bugs.com/show_bug.cgi?id=1234',
136
self.assertEqual('http://bugs.example.com/show_bug.cgi?id=1234',
110
137
tracker.get_bug_url('1234'))
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'))
112
145
def test_generic_registered(self):
113
146
branch = self.make_branch('some_branch')
114
147
config = branch.get_config()
115
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
148
config.set_user_option('bugtracker_foo_url',
149
'http://bugs.example.com/{id}/view.html')
116
150
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
117
self.assertEqual('http://bugs.com/1234/view.html',
151
self.assertEqual('http://bugs.example.com/1234/view.html',
118
152
tracker.get_bug_url('1234'))
120
154
def test_generic_registered_non_integer(self):
121
155
branch = self.make_branch('some_branch')
122
156
config = branch.get_config()
123
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
157
config.set_user_option('bugtracker_foo_url',
158
'http://bugs.example.com/{id}/view.html')
124
159
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
125
self.assertEqual('http://bugs.com/ABC-1234/view.html',
160
self.assertEqual('http://bugs.example.com/ABC-1234/view.html',
126
161
tracker.get_bug_url('ABC-1234'))
128
163
def test_generic_incorrect_url(self):
129
164
branch = self.make_branch('some_branch')
130
165
config = branch.get_config()
131
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
166
config.set_user_option('bugtracker_foo_url',
167
'http://bugs.example.com/view.html')
132
168
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
133
self.assertRaises(errors.InvalidBugTrackerURL, tracker.get_bug_url, '1234')
169
self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
136
173
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
138
175
def test_appends_id_to_base_url(self):
139
176
"""The URL of a bug is the base URL joined to the identifier."""
140
177
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
141
'http://bugs.com/foo')
142
self.assertEqual('http://bugs.com/foo1234', tracker.get_bug_url('1234'))
178
'http://bugs.example.com/foo')
179
self.assertEqual('http://bugs.example.com/foo1234',
180
tracker.get_bug_url('1234'))
144
182
def test_returns_tracker_if_abbreviation_matches(self):
145
183
"""The get() method should return an instance of the tracker if the
146
184
given abbreviation matches the tracker's abbreviated name.
148
186
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
187
'http://bugs.example.com/')
150
188
branch = self.make_branch('some_branch')
151
189
self.assertIs(tracker, tracker.get('xxx', branch))
166
204
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
205
'http://bugs.example.com/')
168
206
self.assertIs(tracker, tracker.get('xxx', None))
169
207
self.assertIs(None, tracker.get('yyy', None))
171
209
def test_check_bug_id_only_accepts_integers(self):
172
210
"""A UniqueIntegerBugTracker accepts integers as bug IDs."""
173
211
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
212
'http://bugs.example.com/')
175
213
tracker.check_bug_id('1234')
177
215
def test_check_bug_id_doesnt_accept_non_integers(self):
178
216
"""A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
179
217
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
182
errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
218
'http://bugs.example.com/')
220
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
223
class TestProjectIntegerBugTracker(TestCaseWithMemoryTransport):
225
def test_appends_id_to_base_url(self):
226
"""The URL of a bug is the base URL joined to the identifier."""
227
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
228
'http://bugs.example.com/{project}/{id}')
229
self.assertEqual('http://bugs.example.com/foo/1234',
230
tracker.get_bug_url('foo/1234'))
232
def test_returns_tracker_if_abbreviation_matches(self):
233
"""The get() method should return an instance of the tracker if the
234
given abbreviation matches the tracker's abbreviated name.
236
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
237
'http://bugs.example.com/{project}/{id}')
238
branch = self.make_branch('some_branch')
239
self.assertIs(tracker, tracker.get('xxx', branch))
241
def test_returns_none_if_abbreviation_doesnt_match(self):
242
"""The get() method should return None if the given abbreviated name
243
doesn't match the tracker's abbreviation.
245
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
246
'http://bugs.example.com/{project}/{id}')
247
branch = self.make_branch('some_branch')
248
self.assertIs(None, tracker.get('yyy', branch))
250
def test_doesnt_consult_branch(self):
251
"""Shouldn't consult the branch for tracker information.
253
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
254
'http://bugs.example.com/{project}/{id}')
255
self.assertIs(tracker, tracker.get('xxx', None))
256
self.assertIs(None, tracker.get('yyy', None))
258
def test_check_bug_id_only_accepts_project_integers(self):
259
"""Accepts integers as bug IDs."""
260
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
261
'http://bugs.example.com/{project}/{id}')
262
tracker.check_bug_id('project/1234')
264
def test_check_bug_id_doesnt_accept_non_project_integers(self):
265
"""Rejects non-integers as bug IDs."""
266
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
267
'http://bugs.example.com/{project}/{id}')
269
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
271
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, '1234')
184
274
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
185
275
"""Tests for URLParametrizedBugTracker."""
247
338
def test_encoding_two(self):
248
339
self.assertEqual(
249
340
'http://example.com/bugs/1 fixed\n'
250
'http://example.com/bugs/2 fixed',
341
'http://example.com/bugs/2 related',
251
342
bugtracker.encode_fixes_bug_urls(
252
['http://example.com/bugs/1', 'http://example.com/bugs/2']))
343
[('http://example.com/bugs/1', 'fixed'),
344
('http://example.com/bugs/2', 'related')]))
346
def test_encoding_with_space(self):
348
bugtracker.InvalidBugUrl,
349
bugtracker.encode_fixes_bug_urls,
350
[('http://example.com/bugs/ 1', 'fixed')])
353
class TestPropertyDecoding(TestCase):
354
"""Tests for parsing bug revision properties."""
356
def test_decoding_one(self):
358
[('http://example.com/bugs/1', 'fixed')],
359
list(bugtracker.decode_bug_urls(
360
'http://example.com/bugs/1 fixed')))
362
def test_decoding_zero(self):
363
self.assertEqual([], list(bugtracker.decode_bug_urls('')))
365
def test_decoding_two(self):
367
[('http://example.com/bugs/1', 'fixed'),
368
('http://example.com/bugs/2', 'related')],
369
list(bugtracker.decode_bug_urls(
370
'http://example.com/bugs/1 fixed\n'
371
'http://example.com/bugs/2 related')))
373
def test_decoding_invalid(self):
375
bugtracker.InvalidLineInBugsProperty,
377
bugtracker.decode_bug_urls('http://example.com/bugs/ 1 fixed\n'))