23
23
class TestGetBugURL(TestCaseWithMemoryTransport):
24
24
"""Tests for bugtracker.get_bug_url"""
26
def test_get_launchpad_url(self):
27
"""No matter the branch, lp:1234 should map to a Launchpad URL."""
26
class TransientTracker(object):
27
"""An transient tracker used for testing."""
30
def get(klass, abbreviation, branch):
31
klass.log.append(('get', abbreviation, branch))
32
if abbreviation != 'transient':
36
def get_bug_url(self, bug_id):
37
self.log.append(('get_bug_url', bug_id))
38
return "http://bugs.com/%s" % bug_id
41
TestCaseWithMemoryTransport.setUp(self)
42
self.tracker_type = TestGetBugURL.TransientTracker
43
self.tracker_type.log = []
44
bugtracker.tracker_registry.register('transient', self.tracker_type)
45
self.addCleanup(lambda:
46
bugtracker.tracker_registry.remove('transient'))
48
def test_get_bug_url_for_transient_tracker(self):
28
49
branch = self.make_branch('some_branch')
50
self.assertEqual('http://bugs.com/1234',
51
bugtracker.get_bug_url('transient', branch, '1234'))
30
'https://launchpad.net/bugs/1234',
31
bugtracker.get_bug_url('lp', branch, '1234'))
33
def test_get_trac_url(self):
34
trac_url = 'http://twistedmatrix.com/trac'
35
branch = self.make_branch('some_branch')
36
config = branch.get_config()
37
config.set_user_option('trac_twisted_url', trac_url)
38
self.assertEqual('%s/ticket/1234' % trac_url,
39
bugtracker.get_bug_url('twisted', branch, '1234'))
41
def test_unrecognized_abbreviation(self):
42
"""If the abbreviation is unrecognized, then raise a KeyError."""
53
[('get', 'transient', branch), ('get_bug_url', '1234')],
54
self.tracker_type.log)
56
def test_unrecognized_abbreviation_raises_error(self):
57
"""If the abbreviation is unrecognized, then raise an error."""
43
58
branch = self.make_branch('some_branch')
44
59
self.assertRaises(errors.UnknownBugTrackerAbbreviation,
45
60
bugtracker.get_bug_url, 'xxx', branch, '1234')
61
self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log)
48
64
class TestUniqueBugTracker(TestCaseWithMemoryTransport):
60
76
self.assertEqual('http://bugs.com/red', tracker.get_bug_url('red'))
62
78
def test_returns_tracker_if_abbreviation_matches(self):
63
"""The get() classmethod should return an instance of the tracker if
64
the given abbreviation matches the tracker's abbreviated name.
79
"""The get() method should return an instance of the tracker if the
80
given abbreviation matches the tracker's abbreviated name.
66
82
tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
67
83
branch = self.make_branch('some_branch')
68
84
self.assertIs(tracker, tracker.get('xxx', branch))
70
86
def test_returns_none_if_abbreviation_doesnt_match(self):
71
"""The get() classmethod should return None if the given abbreviated
72
name doesn't match the tracker's abbreviation.
87
"""The get() method should return None if the given abbreviated name
88
doesn't match the tracker's abbreviation.
74
90
tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
75
91
branch = self.make_branch('some_branch')
76
self.assertEqual(None, tracker.get('yyy', branch))
92
self.assertIs(None, tracker.get('yyy', branch))
94
def test_doesnt_consult_branch(self):
95
"""A UniqueBugTracker shouldn't consult the branch for tracker
98
tracker = bugtracker.UniqueBugTracker('xxx', 'http://bugs.com')
99
self.assertIs(tracker, tracker.get('xxx', None))
100
self.assertIs(None, tracker.get('yyy', None))
79
103
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
81
105
def test_check_bug_id_only_accepts_integers(self):
82
"""An UniqueIntegerBugTracker only accepts integers as bug IDs."""
83
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
84
self.assertEqual(None, tracker.check_bug_id('1234'))
106
"""A UniqueIntegerBugTracker accepts integers as bug IDs."""
107
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
108
tracker.check_bug_id('1234')
110
def test_check_bug_id_doesnt_accept_non_integers(self):
111
"""A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
112
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com')
85
113
self.assertRaises(
86
114
errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')