1
# Copyright (C) 2007 Canonical Ltd
1
# Copyright (C) 2007-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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.com/')
44
("The URL for bug tracker \"foo\" doesn't contain {id}: "
22
49
class TestGetBugURL(TestCaseWithMemoryTransport):
37
64
return "http://bugs.com/%s" % bug_id
40
TestCaseWithMemoryTransport.setUp(self)
67
super(TestGetBugURL, self).setUp()
41
68
self.tracker_type = TestGetBugURL.TransientTracker
42
69
self.tracker_type.log = []
43
70
bugtracker.tracker_registry.register('transient', self.tracker_type)
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)
117
144
self.assertEqual('http://bugs.com/1234/view.html',
118
145
tracker.get_bug_url('1234'))
147
def test_generic_registered_non_integer(self):
148
branch = self.make_branch('some_branch')
149
config = branch.get_config()
150
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
151
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
152
self.assertEqual('http://bugs.com/ABC-1234/view.html',
153
tracker.get_bug_url('ABC-1234'))
120
155
def test_generic_incorrect_url(self):
121
156
branch = self.make_branch('some_branch')
122
157
config = branch.get_config()
123
158
config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
124
159
tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
125
self.assertRaises(errors.InvalidBugTrackerURL, tracker.get_bug_url, '1234')
160
self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
128
164
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
171
207
tracker = bugtracker.UniqueIntegerBugTracker('xxx',
172
208
'http://bugs.com/')
173
209
self.assertRaises(
174
errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
177
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
178
"""Tests for TracTracker."""
210
bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
212
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
213
"""Tests for URLParametrizedBugTracker."""
181
TestCaseWithMemoryTransport.setUp(self)
216
super(TestURLParametrizedBugTracker, self).setUp()
182
217
self.url = 'http://twistedmatrix.com/trac'
183
self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
218
self.tracker = bugtracker.URLParametrizedBugTracker('some', 'ticket/')
186
220
def test_get_with_unsupported_tag(self):
187
221
"""If asked for an unrecognized or unconfigured tag, return None."""
203
237
urlutils.join(self.url, 'ticket/') + '1234',
204
238
tracker.get_bug_url('1234'))
240
def test_get_bug_url_for_integer_id(self):
241
self.tracker.check_bug_id('1234')
243
def test_get_bug_url_for_non_integer_id(self):
244
self.tracker.check_bug_id('ABC-1234')
247
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
248
"""Tests for URLParametrizedIntegerBugTracker."""
251
super(TestURLParametrizedIntegerBugTracker, self).setUp()
252
self.url = 'http://twistedmatrix.com/trac'
253
self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
206
256
def test_get_bug_url_for_bad_bug(self):
207
257
"""When given a bug identifier that is invalid for Trac, get_bug_url
208
258
should raise an error.
210
260
self.assertRaises(
211
errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
261
bugtracker.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
214
264
class TestPropertyEncoding(TestCase):