/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_bugtracker.py

  • Committer: Jelmer Vernooij
  • Date: 2017-09-01 07:15:43 UTC
  • mfrom: (6770.3.2 py3_test_cleanup)
  • Revision ID: jelmer@jelmer.uk-20170901071543-1t83321xkog9qrxh
Merge lp:~gz/brz/py3_test_cleanup

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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
from bzrlib import bugtracker, errors, urlutils
19
 
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
 
18
from .. import bugtracker, urlutils
 
19
from . import TestCase, TestCaseWithMemoryTransport
 
20
 
 
21
 
 
22
class ErrorsTest(TestCaseWithMemoryTransport):
 
23
 
 
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)
 
28
        self.assertEqual(
 
29
            "Cannot find registered bug tracker called xxx on %s" % branch,
 
30
            str(error))
 
31
 
 
32
    def test_malformed_bug_identifier(self):
 
33
        """Test the formatting of MalformedBugIdentifier."""
 
34
        error = bugtracker.MalformedBugIdentifier(
 
35
            'bogus', 'reason for bogosity')
 
36
        self.assertEqual(
 
37
            'Did not understand bug identifier bogus: reason for bogosity. '
 
38
            'See "brz help bugs" for more information on this feature.',
 
39
            str(error))
 
40
 
 
41
    def test_incorrect_url(self):
 
42
        err = bugtracker.InvalidBugTrackerURL('foo', 'http://bug.com/')
 
43
        self.assertEqual(
 
44
            ("The URL for bug tracker \"foo\" doesn't contain {id}: "
 
45
             "http://bug.com/"),
 
46
            str(err))
20
47
 
21
48
 
22
49
class TestGetBugURL(TestCaseWithMemoryTransport):
37
64
            return "http://bugs.com/%s" % bug_id
38
65
 
39
66
    def setUp(self):
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)
60
87
 
117
144
        self.assertEqual('http://bugs.com/1234/view.html',
118
145
                         tracker.get_bug_url('1234'))
119
146
 
 
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'))
 
154
 
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,
 
161
                '1234')
126
162
 
127
163
 
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')
175
 
 
176
 
 
177
 
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
178
 
    """Tests for TracTracker."""
 
210
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
 
211
 
 
212
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
 
213
    """Tests for URLParametrizedBugTracker."""
179
214
 
180
215
    def setUp(self):
181
 
        TestCaseWithMemoryTransport.setUp(self)
 
216
        super(TestURLParametrizedBugTracker, self).setUp()
182
217
        self.url = 'http://twistedmatrix.com/trac'
183
 
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
184
 
                                                                   'ticket/')
 
218
        self.tracker = bugtracker.URLParametrizedBugTracker('some', 'ticket/')
185
219
 
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'))
205
239
 
 
240
    def test_get_bug_url_for_integer_id(self):
 
241
        self.tracker.check_bug_id('1234')
 
242
 
 
243
    def test_get_bug_url_for_non_integer_id(self):
 
244
        self.tracker.check_bug_id('ABC-1234')
 
245
 
 
246
 
 
247
class TestURLParametrizedIntegerBugTracker(TestCaseWithMemoryTransport):
 
248
    """Tests for URLParametrizedIntegerBugTracker."""
 
249
 
 
250
    def setUp(self):
 
251
        super(TestURLParametrizedIntegerBugTracker, self).setUp()
 
252
        self.url = 'http://twistedmatrix.com/trac'
 
253
        self.tracker = bugtracker.URLParametrizedIntegerBugTracker('some',
 
254
                                                                   'ticket/')
 
255
 
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.
209
259
        """
210
260
        self.assertRaises(
211
 
            errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
 
261
            bugtracker.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
212
262
 
213
263
 
214
264
class TestPropertyEncoding(TestCase):