~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bugtracker.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
from bzrlib import bugtracker, errors, urlutils
19
 
from bzrlib.tests import TestCaseWithMemoryTransport
 
19
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
20
20
 
21
21
 
22
22
class TestGetBugURL(TestCaseWithMemoryTransport):
41
41
        self.tracker_type = TestGetBugURL.TransientTracker
42
42
        self.tracker_type.log = []
43
43
        bugtracker.tracker_registry.register('transient', self.tracker_type)
44
 
        self.addCleanup(lambda:
45
 
                        bugtracker.tracker_registry.remove('transient'))
 
44
        self.addCleanup(bugtracker.tracker_registry.remove, 'transient')
46
45
 
47
46
    def test_get_bug_url_for_transient_tracker(self):
48
47
        branch = self.make_branch('some_branch')
118
117
        self.assertEqual('http://bugs.com/1234/view.html',
119
118
                         tracker.get_bug_url('1234'))
120
119
 
 
120
    def test_generic_registered_non_integer(self):
 
121
        branch = self.make_branch('some_branch')
 
122
        config = branch.get_config()
 
123
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
 
124
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
 
125
        self.assertEqual('http://bugs.com/ABC-1234/view.html',
 
126
                         tracker.get_bug_url('ABC-1234'))
 
127
 
121
128
    def test_generic_incorrect_url(self):
122
129
        branch = self.make_branch('some_branch')
123
130
        config = branch.get_config()
174
181
        self.assertRaises(
175
182
            errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
176
183
 
177
 
 
178
 
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
179
 
    """Tests for TracTracker."""
 
184
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
 
185
    """Tests for URLParametrizedBugTracker."""
180
186
 
181
187
    def setUp(self):
182
188
        TestCaseWithMemoryTransport.setUp(self)
183
189
        self.url = 'http://twistedmatrix.com/trac'
184
 
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
185
 
                                                                   'ticket/')
 
190
        self.tracker = bugtracker.URLParametrizedBugTracker('some', 'ticket/')
186
191
 
187
192
    def test_get_with_unsupported_tag(self):
188
193
        """If asked for an unrecognized or unconfigured tag, return None."""
194
199
        """If asked for a valid tag, return a tracker instance that can map bug
195
200
        IDs to <base_url>/<bug_area> + <bug_id>."""
196
201
        bugtracker.tracker_registry.register('some', self.tracker)
197
 
        self.addCleanup(lambda: bugtracker.tracker_registry.remove('some'))
 
202
        self.addCleanup(bugtracker.tracker_registry.remove, 'some')
198
203
 
199
204
        branch = self.make_branch('some_branch')
200
205
        config = branch.get_config()
204
209
            urlutils.join(self.url, 'ticket/') + '1234',
205
210
            tracker.get_bug_url('1234'))
206
211
 
 
212
    def test_get_bug_url_for_integer_id(self):
 
213
        self.tracker.check_bug_id('1234')
 
214
 
 
215
    def test_get_bug_url_for_non_integer_id(self):
 
216
        self.tracker.check_bug_id('ABC-1234')
 
217
 
 
218
 
 
219
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
 
220
    """Tests for URLParametrizedIntegerBugTracker."""
 
221
 
 
222
    def setUp(self):
 
223
        TestCaseWithMemoryTransport.setUp(self)
 
224
        self.url = 'http://twistedmatrix.com/trac'
 
225
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
 
226
                                                                   'ticket/')
 
227
 
207
228
    def test_get_bug_url_for_bad_bug(self):
208
229
        """When given a bug identifier that is invalid for Trac, get_bug_url
209
230
        should raise an error.
210
231
        """
211
232
        self.assertRaises(
212
233
            errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
 
234
 
 
235
 
 
236
class TestPropertyEncoding(TestCase):
 
237
    """Tests for how the bug URLs are encoded as revision properties."""
 
238
 
 
239
    def test_encoding_one(self):
 
240
        self.assertEqual(
 
241
            'http://example.com/bugs/1 fixed',
 
242
            bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
 
243
 
 
244
    def test_encoding_zero(self):
 
245
        self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
 
246
 
 
247
    def test_encoding_two(self):
 
248
        self.assertEqual(
 
249
            'http://example.com/bugs/1 fixed\n'
 
250
            'http://example.com/bugs/2 fixed',
 
251
            bugtracker.encode_fixes_bug_urls(
 
252
                ['http://example.com/bugs/1', 'http://example.com/bugs/2']))