2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
2376.4.42
by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to |
18 |
from bzrlib import bugtracker, errors, urlutils |
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
19 |
from bzrlib.tests import TestCaseWithMemoryTransport |
20 |
||
21 |
||
2376.4.7
by jml at canonical
- Add docstrings to tests. |
22 |
class TestGetBugURL(TestCaseWithMemoryTransport): |
23 |
"""Tests for bugtracker.get_bug_url"""
|
|
24 |
||
2376.4.28
by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation |
25 |
class TransientTracker(object): |
26 |
"""An transient tracker used for testing."""
|
|
27 |
||
28 |
@classmethod
|
|
29 |
def get(klass, abbreviation, branch): |
|
30 |
klass.log.append(('get', abbreviation, branch)) |
|
31 |
if abbreviation != 'transient': |
|
32 |
return None |
|
33 |
return klass() |
|
34 |
||
35 |
def get_bug_url(self, bug_id): |
|
36 |
self.log.append(('get_bug_url', bug_id)) |
|
37 |
return "http://bugs.com/%s" % bug_id |
|
38 |
||
39 |
def setUp(self): |
|
40 |
TestCaseWithMemoryTransport.setUp(self) |
|
41 |
self.tracker_type = TestGetBugURL.TransientTracker |
|
42 |
self.tracker_type.log = [] |
|
43 |
bugtracker.tracker_registry.register('transient', self.tracker_type) |
|
44 |
self.addCleanup(lambda: |
|
45 |
bugtracker.tracker_registry.remove('transient')) |
|
46 |
||
47 |
def test_get_bug_url_for_transient_tracker(self): |
|
2376.4.7
by jml at canonical
- Add docstrings to tests. |
48 |
branch = self.make_branch('some_branch') |
2376.4.28
by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation |
49 |
self.assertEqual('http://bugs.com/1234', |
50 |
bugtracker.get_bug_url('transient', branch, '1234')) |
|
2376.4.7
by jml at canonical
- Add docstrings to tests. |
51 |
self.assertEqual( |
2376.4.28
by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation |
52 |
[('get', 'transient', branch), ('get_bug_url', '1234')], |
53 |
self.tracker_type.log) |
|
54 |
||
55 |
def test_unrecognized_abbreviation_raises_error(self): |
|
56 |
"""If the abbreviation is unrecognized, then raise an error."""
|
|
2376.4.7
by jml at canonical
- Add docstrings to tests. |
57 |
branch = self.make_branch('some_branch') |
2376.4.26
by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation. |
58 |
self.assertRaises(errors.UnknownBugTrackerAbbreviation, |
2376.4.7
by jml at canonical
- Add docstrings to tests. |
59 |
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 |
60 |
self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log) |
2376.4.7
by jml at canonical
- Add docstrings to tests. |
61 |
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
62 |
|
2376.4.29
by Jonathan Lange
Tests for builtin trackers. |
63 |
class TestBuiltinTrackers(TestCaseWithMemoryTransport): |
64 |
"""Test that the builtin trackers are registered and return sane URLs."""
|
|
65 |
||
66 |
def test_launchpad_registered(self): |
|
67 |
"""The Launchpad bug tracker should be registered by default and
|
|
68 |
generate Launchpad bug page URLs.
|
|
69 |
"""
|
|
70 |
branch = self.make_branch('some_branch') |
|
71 |
tracker = bugtracker.tracker_registry.get_tracker('lp', branch) |
|
72 |
self.assertEqual('https://launchpad.net/bugs/1234', |
|
73 |
tracker.get_bug_url('1234')) |
|
74 |
||
75 |
def test_debian_registered(self): |
|
76 |
"""The Debian bug tracker should be registered by default and generate
|
|
77 |
bugs.debian.org bug page URLs.
|
|
78 |
"""
|
|
79 |
branch = self.make_branch('some_branch') |
|
80 |
tracker = bugtracker.tracker_registry.get_tracker('deb', branch) |
|
81 |
self.assertEqual('http://bugs.debian.org/1234', |
|
82 |
tracker.get_bug_url('1234')) |
|
83 |
||
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
84 |
def test_trac_registered(self): |
85 |
"""The Trac bug tracker should be registered by default and generate
|
|
86 |
Trac bug page URLs when the appropriate configuration is present.
|
|
87 |
"""
|
|
88 |
branch = self.make_branch('some_branch') |
|
89 |
config = branch.get_config() |
|
90 |
config.set_user_option('trac_foo_url', 'http://bugs.com/trac') |
|
91 |
tracker = bugtracker.tracker_registry.get_tracker('foo', branch) |
|
92 |
self.assertEqual('http://bugs.com/trac/ticket/1234', |
|
93 |
tracker.get_bug_url('1234')) |
|
94 |
||
95 |
def test_bugzilla_registered(self): |
|
96 |
"""The Bugzilla bug tracker should be registered by default and
|
|
97 |
generate Bugzilla bug page URLs when the appropriate configuration is
|
|
98 |
present.
|
|
99 |
"""
|
|
100 |
branch = self.make_branch('some_branch') |
|
101 |
config = branch.get_config() |
|
102 |
config.set_user_option('bugzilla_foo_url', 'http://bugs.com') |
|
103 |
tracker = bugtracker.tracker_registry.get_tracker('foo', branch) |
|
104 |
self.assertEqual('http://bugs.com/show_bug.cgi?id=1234', |
|
105 |
tracker.get_bug_url('1234')) |
|
106 |
||
107 |
||
108 |
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport): |
|
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
109 |
|
110 |
def test_joins_id_to_base_url(self): |
|
111 |
"""The URL of a bug is the base URL joined to the identifier."""
|
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
112 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
113 |
self.assertEqual('http://bugs.com/1234', tracker.get_bug_url('1234')) |
114 |
||
2376.4.23
by Jonathan Lange
Change 'tag' to 'abbreviated_tracker_name' |
115 |
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 |
116 |
"""The get() method should return an instance of the tracker if the
|
117 |
given abbreviation matches the tracker's abbreviated name.
|
|
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
118 |
"""
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
119 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
120 |
branch = self.make_branch('some_branch') |
2376.4.25
by Jonathan Lange
Make singleton bug tracker thing work via instances. |
121 |
self.assertIs(tracker, tracker.get('xxx', branch)) |
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
122 |
|
2376.4.23
by Jonathan Lange
Change 'tag' to 'abbreviated_tracker_name' |
123 |
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 |
124 |
"""The get() method should return None if the given abbreviated name
|
125 |
doesn't match the tracker's abbreviation.
|
|
2376.4.22
by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in |
126 |
"""
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
127 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
2376.4.22
by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in |
128 |
branch = self.make_branch('some_branch') |
2376.4.28
by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation |
129 |
self.assertIs(None, tracker.get('yyy', branch)) |
130 |
||
131 |
def test_doesnt_consult_branch(self): |
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
132 |
"""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 |
133 |
information.
|
134 |
"""
|
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
135 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
2376.4.28
by Jonathan Lange
Focus the tests better and clean up some dodgy bits in UnknownBugTrackerAbbreviation |
136 |
self.assertIs(tracker, tracker.get('xxx', None)) |
137 |
self.assertIs(None, tracker.get('yyy', None)) |
|
2376.4.22
by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in |
138 |
|
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
139 |
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 |
140 |
"""A UniqueIntegerBugTracker accepts integers as bug IDs."""
|
141 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
|
142 |
tracker.check_bug_id('1234') |
|
143 |
||
144 |
def test_check_bug_id_doesnt_accept_non_integers(self): |
|
145 |
"""A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
|
|
146 |
tracker = bugtracker.UniqueIntegerBugTracker('xxx', 'http://bugs.com') |
|
2376.4.26
by Jonathan Lange
Tests for MalformedBugIdentifier and new error UnknownBugTrackerAbbreviation. |
147 |
self.assertRaises( |
148 |
errors.MalformedBugIdentifier, tracker.check_bug_id, 'red') |
|
2376.4.20
by Jonathan Lange
Direct tests for UniqueBugTracker and UniqueIntegerBugTracker |
149 |
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
150 |
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
151 |
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport): |
2376.4.22
by Jonathan Lange
Variety of whitespace cleanups, tightening of tests and docstring changes in |
152 |
"""Tests for TracTracker."""
|
153 |
||
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
154 |
def setUp(self): |
155 |
TestCaseWithMemoryTransport.setUp(self) |
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
156 |
self.url = 'http://twistedmatrix.com/trac' |
2376.4.42
by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to |
157 |
self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some', |
158 |
'ticket/') |
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
159 |
|
160 |
def test_get_with_unsupported_tag(self): |
|
2376.4.7
by jml at canonical
- Add docstrings to tests. |
161 |
"""If asked for an unrecognized or unconfigured tag, return None."""
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
162 |
branch = self.make_branch('some_branch') |
2376.4.42
by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to |
163 |
self.assertEqual(None, self.tracker.get('lp', branch)) |
164 |
self.assertEqual(None, self.tracker.get('twisted', branch)) |
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
165 |
|
166 |
def test_get_with_supported_tag(self): |
|
2376.4.42
by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to |
167 |
"""If asked for a valid tag, return a tracker instance that can map bug
|
168 |
IDs to <base_url>/<bug_area> + <bug_id>."""
|
|
169 |
bugtracker.tracker_registry.register('some', self.tracker) |
|
170 |
self.addCleanup(lambda: bugtracker.tracker_registry.remove('some')) |
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
171 |
|
2376.4.4
by jml at canonical
Beginnings of generic bug-tracker plugin system. |
172 |
branch = self.make_branch('some_branch') |
173 |
config = branch.get_config() |
|
2376.4.40
by Jonathan Lange
Redo the hierarchy of bug trackers to reduce duplication. |
174 |
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 |
175 |
tracker = self.tracker.get('twisted', branch) |
176 |
self.assertEqual( |
|
177 |
urlutils.join(self.url, 'ticket/') + '1234', |
|
178 |
tracker.get_bug_url('1234')) |
|
2376.4.7
by jml at canonical
- Add docstrings to tests. |
179 |
|
2376.4.30
by Jonathan Lange
Support for Bugzilla bug trackers. |
180 |
def test_get_bug_url_for_bad_bug(self): |
181 |
"""When given a bug identifier that is invalid for Trac, get_bug_url
|
|
182 |
should raise an error.
|
|
183 |
"""
|
|
184 |
self.assertRaises( |
|
2376.4.42
by Jonathan Lange
Parametrize URLParametrizedIntegerBugTracker even further so we don't need to |
185 |
errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad') |