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):
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', 'http://bugs.example.com/{id}/view.html')
116
149
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
117
self.assertEqual('http://bugs.com/1234/view.html',
150
self.assertEqual('http://bugs.example.com/1234/view.html',
118
151
tracker.get_bug_url('1234'))
153
def test_generic_registered_non_integer(self):
154
branch = self.make_branch('some_branch')
155
config = branch.get_config()
156
config.set_user_option('bugtracker_foo_url', 'http://bugs.example.com/{id}/view.html')
157
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
158
self.assertEqual('http://bugs.example.com/ABC-1234/view.html',
159
tracker.get_bug_url('ABC-1234'))
120
161
def test_generic_incorrect_url(self):
121
162
branch = self.make_branch('some_branch')
122
163
config = branch.get_config()
123
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
164
config.set_user_option('bugtracker_foo_url', 'http://bugs.example.com/view.html')
124
165
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
125
self.assertRaises(errors.InvalidBugTrackerURL, tracker.get_bug_url, '1234')
166
self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
128
170
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
130
172
def test_appends_id_to_base_url(self):
131
173
"""The URL of a bug is the base URL joined to the identifier."""
132
174
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
133
'http://bugs.com/foo')
134
self.assertEqual('http://bugs.com/foo1234', tracker.get_bug_url('1234'))
175
'http://bugs.example.com/foo')
176
self.assertEqual('http://bugs.example.com/foo1234', tracker.get_bug_url('1234'))
136
178
def test_returns_tracker_if_abbreviation_matches(self):
137
179
"""The get() method should return an instance of the tracker if the
138
180
given abbreviation matches the tracker's abbreviated name.
140
182
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
183
'http://bugs.example.com/')
142
184
branch = self.make_branch('some_branch')
143
185
self.assertIs(tracker, tracker.get('xxx', branch))
158
200
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
201
'http://bugs.example.com/')
160
202
self.assertIs(tracker, tracker.get('xxx', None))
161
203
self.assertIs(None, tracker.get('yyy', None))
163
205
def test_check_bug_id_only_accepts_integers(self):
164
206
"""A UniqueIntegerBugTracker accepts integers as bug IDs."""
165
207
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
208
'http://bugs.example.com/')
167
209
tracker.check_bug_id('1234')
169
211
def test_check_bug_id_doesnt_accept_non_integers(self):
170
212
"""A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
171
213
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
174
errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
177
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
178
"""Tests for TracTracker."""
214
'http://bugs.example.com/')
216
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
219
class TestProjectIntegerBugTracker(TestCaseWithMemoryTransport):
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',
224
'http://bugs.example.com/{project}/{id}')
225
self.assertEqual('http://bugs.example.com/foo/1234', tracker.get_bug_url('foo/1234'))
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.
231
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
232
'http://bugs.example.com/{project}/{id}')
233
branch = self.make_branch('some_branch')
234
self.assertIs(tracker, tracker.get('xxx', branch))
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.
240
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
241
'http://bugs.example.com/{project}/{id}')
242
branch = self.make_branch('some_branch')
243
self.assertIs(None, tracker.get('yyy', branch))
245
def test_doesnt_consult_branch(self):
246
"""Shouldn't consult the branch for tracker information.
248
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
249
'http://bugs.example.com/{project}/{id}')
250
self.assertIs(tracker, tracker.get('xxx', None))
251
self.assertIs(None, tracker.get('yyy', None))
253
def test_check_bug_id_only_accepts_project_integers(self):
254
"""Accepts integers as bug IDs."""
255
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
256
'http://bugs.example.com/{project}/{id}')
257
tracker.check_bug_id('project/1234')
259
def test_check_bug_id_doesnt_accept_non_project_integers(self):
260
"""Rejects non-integers as bug IDs."""
261
tracker = bugtracker.ProjectIntegerBugTracker('xxx',
262
'http://bugs.example.com/{project}/{id}')
264
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
266
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, '1234')
269
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
270
"""Tests for URLParametrizedBugTracker."""
181
TestCaseWithMemoryTransport.setUp(self)
273
super(TestURLParametrizedBugTracker, self).setUp()
182
274
self.url = 'http://twistedmatrix.com/trac'
183
self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
275
self.tracker = bugtracker.URLParametrizedBugTracker('some', 'ticket/')
186
277
def test_get_with_unsupported_tag(self):
187
278
"""If asked for an unrecognized or unconfigured tag, return None."""
203
294
urlutils.join(self.url, 'ticket/') + '1234',
204
295
tracker.get_bug_url('1234'))
297
def test_get_bug_url_for_integer_id(self):
298
self.tracker.check_bug_id('1234')
300
def test_get_bug_url_for_non_integer_id(self):
301
self.tracker.check_bug_id('ABC-1234')
304
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
305
"""Tests for URLParametrizedIntegerBugTracker."""
308
super(TestURLParametrizedIntegerBugTracker, self).setUp()
309
self.url = 'http://twistedmatrix.com/trac'
310
self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
206
313
def test_get_bug_url_for_bad_bug(self):
207
314
"""When given a bug identifier that is invalid for Trac, get_bug_url
208
315
should raise an error.
210
317
self.assertRaises(
211
errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
318
bugtracker.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
214
321
class TestPropertyEncoding(TestCase):