/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 brzlib/tests/test_bugtracker.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
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.example.com/')
43
 
        self.assertEqual(
44
 
            ("The URL for bug tracker \"foo\" doesn't contain {id}: "
45
 
             "http://bug.example.com/"),
46
 
            str(err))
 
18
from brzlib import bugtracker, errors, urlutils
 
19
from brzlib.tests import TestCase, TestCaseWithMemoryTransport
47
20
 
48
21
 
49
22
class TestGetBugURL(TestCaseWithMemoryTransport):
61
34
 
62
35
        def get_bug_url(self, bug_id):
63
36
            self.log.append(('get_bug_url', bug_id))
64
 
            return "http://bugs.example.com/%s" % bug_id
 
37
            return "http://bugs.com/%s" % bug_id
65
38
 
66
39
    def setUp(self):
67
40
        super(TestGetBugURL, self).setUp()
72
45
 
73
46
    def test_get_bug_url_for_transient_tracker(self):
74
47
        branch = self.make_branch('some_branch')
75
 
        self.assertEqual('http://bugs.example.com/1234',
 
48
        self.assertEqual('http://bugs.com/1234',
76
49
                         bugtracker.get_bug_url('transient', branch, '1234'))
77
50
        self.assertEqual(
78
51
            [('get', 'transient', branch), ('get_bug_url', '1234')],
81
54
    def test_unrecognized_abbreviation_raises_error(self):
82
55
        """If the abbreviation is unrecognized, then raise an error."""
83
56
        branch = self.make_branch('some_branch')
84
 
        self.assertRaises(bugtracker.UnknownBugTrackerAbbreviation,
 
57
        self.assertRaises(errors.UnknownBugTrackerAbbreviation,
85
58
                          bugtracker.get_bug_url, 'xxx', branch, '1234')
86
59
        self.assertEqual([('get', 'xxx', branch)], self.tracker_type.log)
87
60
 
119
92
        """
120
93
        branch = self.make_branch('some_branch')
121
94
        config = branch.get_config()
122
 
        config.set_user_option('trac_foo_url', 'http://bugs.example.com/trac')
 
95
        config.set_user_option('trac_foo_url', 'http://bugs.com/trac')
123
96
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
124
 
        self.assertEqual('http://bugs.example.com/trac/ticket/1234',
 
97
        self.assertEqual('http://bugs.com/trac/ticket/1234',
125
98
                         tracker.get_bug_url('1234'))
126
99
 
127
100
    def test_bugzilla_registered(self):
131
104
        """
132
105
        branch = self.make_branch('some_branch')
133
106
        config = branch.get_config()
134
 
        config.set_user_option('bugzilla_foo_url', 'http://bugs.example.com')
 
107
        config.set_user_option('bugzilla_foo_url', 'http://bugs.com')
135
108
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
136
 
        self.assertEqual('http://bugs.example.com/show_bug.cgi?id=1234',
 
109
        self.assertEqual('http://bugs.com/show_bug.cgi?id=1234',
137
110
                         tracker.get_bug_url('1234'))
138
111
 
139
 
    def test_github(self):
140
 
        branch = self.make_branch('some_branch')
141
 
        tracker = bugtracker.tracker_registry.get_tracker('github', branch)
142
 
        self.assertEqual('https://github.com/breezy-team/breezy/issues/1234',
143
 
                         tracker.get_bug_url('breezy-team/breezy/1234'))
144
 
 
145
112
    def test_generic_registered(self):
146
113
        branch = self.make_branch('some_branch')
147
114
        config = branch.get_config()
148
 
        config.set_user_option('bugtracker_foo_url',
149
 
                               'http://bugs.example.com/{id}/view.html')
 
115
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
150
116
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
151
 
        self.assertEqual('http://bugs.example.com/1234/view.html',
 
117
        self.assertEqual('http://bugs.com/1234/view.html',
152
118
                         tracker.get_bug_url('1234'))
153
119
 
154
120
    def test_generic_registered_non_integer(self):
155
121
        branch = self.make_branch('some_branch')
156
122
        config = branch.get_config()
157
 
        config.set_user_option('bugtracker_foo_url',
158
 
                               'http://bugs.example.com/{id}/view.html')
 
123
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
159
124
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
160
 
        self.assertEqual('http://bugs.example.com/ABC-1234/view.html',
 
125
        self.assertEqual('http://bugs.com/ABC-1234/view.html',
161
126
                         tracker.get_bug_url('ABC-1234'))
162
127
 
163
128
    def test_generic_incorrect_url(self):
164
129
        branch = self.make_branch('some_branch')
165
130
        config = branch.get_config()
166
 
        config.set_user_option('bugtracker_foo_url',
167
 
                               'http://bugs.example.com/view.html')
 
131
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
168
132
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
169
 
        self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
170
 
                          '1234')
 
133
        self.assertRaises(errors.InvalidBugTrackerURL, tracker.get_bug_url, '1234')
171
134
 
172
135
 
173
136
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
175
138
    def test_appends_id_to_base_url(self):
176
139
        """The URL of a bug is the base URL joined to the identifier."""
177
140
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
178
 
                                                     'http://bugs.example.com/foo')
179
 
        self.assertEqual('http://bugs.example.com/foo1234',
180
 
                         tracker.get_bug_url('1234'))
 
141
                'http://bugs.com/foo')
 
142
        self.assertEqual('http://bugs.com/foo1234', tracker.get_bug_url('1234'))
181
143
 
182
144
    def test_returns_tracker_if_abbreviation_matches(self):
183
145
        """The get() method should return an instance of the tracker if the
184
146
        given abbreviation matches the tracker's abbreviated name.
185
147
        """
186
148
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
187
 
                                                     'http://bugs.example.com/')
 
149
                'http://bugs.com/')
188
150
        branch = self.make_branch('some_branch')
189
151
        self.assertIs(tracker, tracker.get('xxx', branch))
190
152
 
193
155
        doesn't match the tracker's abbreviation.
194
156
        """
195
157
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
196
 
                                                     'http://bugs.example.com/')
 
158
                'http://bugs.com/')
197
159
        branch = self.make_branch('some_branch')
198
160
        self.assertIs(None, tracker.get('yyy', branch))
199
161
 
202
164
        information.
203
165
        """
204
166
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
205
 
                                                     'http://bugs.example.com/')
 
167
                'http://bugs.com/')
206
168
        self.assertIs(tracker, tracker.get('xxx', None))
207
169
        self.assertIs(None, tracker.get('yyy', None))
208
170
 
209
171
    def test_check_bug_id_only_accepts_integers(self):
210
172
        """A UniqueIntegerBugTracker accepts integers as bug IDs."""
211
173
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
212
 
                                                     'http://bugs.example.com/')
 
174
                'http://bugs.com/')
213
175
        tracker.check_bug_id('1234')
214
176
 
215
177
    def test_check_bug_id_doesnt_accept_non_integers(self):
216
178
        """A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
217
179
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
218
 
                                                     'http://bugs.example.com/')
219
 
        self.assertRaises(
220
 
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
221
 
 
222
 
 
223
 
class TestProjectIntegerBugTracker(TestCaseWithMemoryTransport):
224
 
 
225
 
    def test_appends_id_to_base_url(self):
226
 
        """The URL of a bug is the base URL joined to the identifier."""
227
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
228
 
                                                      'http://bugs.example.com/{project}/{id}')
229
 
        self.assertEqual('http://bugs.example.com/foo/1234',
230
 
                         tracker.get_bug_url('foo/1234'))
231
 
 
232
 
    def test_returns_tracker_if_abbreviation_matches(self):
233
 
        """The get() method should return an instance of the tracker if the
234
 
        given abbreviation matches the tracker's abbreviated name.
235
 
        """
236
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
237
 
                                                      'http://bugs.example.com/{project}/{id}')
238
 
        branch = self.make_branch('some_branch')
239
 
        self.assertIs(tracker, tracker.get('xxx', branch))
240
 
 
241
 
    def test_returns_none_if_abbreviation_doesnt_match(self):
242
 
        """The get() method should return None if the given abbreviated name
243
 
        doesn't match the tracker's abbreviation.
244
 
        """
245
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
246
 
                                                      'http://bugs.example.com/{project}/{id}')
247
 
        branch = self.make_branch('some_branch')
248
 
        self.assertIs(None, tracker.get('yyy', branch))
249
 
 
250
 
    def test_doesnt_consult_branch(self):
251
 
        """Shouldn't consult the branch for tracker information.
252
 
        """
253
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
254
 
                                                      'http://bugs.example.com/{project}/{id}')
255
 
        self.assertIs(tracker, tracker.get('xxx', None))
256
 
        self.assertIs(None, tracker.get('yyy', None))
257
 
 
258
 
    def test_check_bug_id_only_accepts_project_integers(self):
259
 
        """Accepts integers as bug IDs."""
260
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
261
 
                                                      'http://bugs.example.com/{project}/{id}')
262
 
        tracker.check_bug_id('project/1234')
263
 
 
264
 
    def test_check_bug_id_doesnt_accept_non_project_integers(self):
265
 
        """Rejects non-integers as bug IDs."""
266
 
        tracker = bugtracker.ProjectIntegerBugTracker('xxx',
267
 
                                                      'http://bugs.example.com/{project}/{id}')
268
 
        self.assertRaises(
269
 
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
270
 
        self.assertRaises(
271
 
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, '1234')
272
 
 
 
180
                'http://bugs.com/')
 
181
        self.assertRaises(
 
182
            errors.MalformedBugIdentifier, tracker.check_bug_id, 'red')
273
183
 
274
184
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
275
185
    """Tests for URLParametrizedBugTracker."""
320
230
        should raise an error.
321
231
        """
322
232
        self.assertRaises(
323
 
            bugtracker.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
 
233
            errors.MalformedBugIdentifier, self.tracker.get_bug_url, 'bad')
324
234
 
325
235
 
326
236
class TestPropertyEncoding(TestCase):
329
239
    def test_encoding_one(self):
330
240
        self.assertEqual(
331
241
            'http://example.com/bugs/1 fixed',
332
 
            bugtracker.encode_fixes_bug_urls(
333
 
                [('http://example.com/bugs/1', 'fixed')]))
 
242
            bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
334
243
 
335
244
    def test_encoding_zero(self):
336
245
        self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
338
247
    def test_encoding_two(self):
339
248
        self.assertEqual(
340
249
            'http://example.com/bugs/1 fixed\n'
341
 
            'http://example.com/bugs/2 related',
 
250
            'http://example.com/bugs/2 fixed',
342
251
            bugtracker.encode_fixes_bug_urls(
343
 
                [('http://example.com/bugs/1', 'fixed'),
344
 
                 ('http://example.com/bugs/2', 'related')]))
345
 
 
346
 
    def test_encoding_with_space(self):
347
 
        self.assertRaises(
348
 
            bugtracker.InvalidBugUrl,
349
 
            bugtracker.encode_fixes_bug_urls,
350
 
            [('http://example.com/bugs/ 1', 'fixed')])
351
 
 
352
 
 
353
 
class TestPropertyDecoding(TestCase):
354
 
    """Tests for parsing bug revision properties."""
355
 
 
356
 
    def test_decoding_one(self):
357
 
        self.assertEqual(
358
 
            [('http://example.com/bugs/1', 'fixed')],
359
 
            list(bugtracker.decode_bug_urls(
360
 
                'http://example.com/bugs/1 fixed')))
361
 
 
362
 
    def test_decoding_zero(self):
363
 
        self.assertEqual([], list(bugtracker.decode_bug_urls('')))
364
 
 
365
 
    def test_decoding_two(self):
366
 
        self.assertEqual(
367
 
            [('http://example.com/bugs/1', 'fixed'),
368
 
             ('http://example.com/bugs/2', 'related')],
369
 
            list(bugtracker.decode_bug_urls(
370
 
                'http://example.com/bugs/1 fixed\n'
371
 
                'http://example.com/bugs/2 related')))
372
 
 
373
 
    def test_decoding_invalid(self):
374
 
        self.assertRaises(
375
 
            bugtracker.InvalidLineInBugsProperty,
376
 
            list,
377
 
            bugtracker.decode_bug_urls('http://example.com/bugs/ 1 fixed\n'))
 
252
                ['http://example.com/bugs/1', 'http://example.com/bugs/2']))