/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: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
            str(error))
40
40
 
41
41
    def test_incorrect_url(self):
42
 
        err = bugtracker.InvalidBugTrackerURL('foo', 'http://bug.example.com/')
 
42
        err = bugtracker.InvalidBugTrackerURL('foo', 'http://bug.com/')
43
43
        self.assertEqual(
44
44
            ("The URL for bug tracker \"foo\" doesn't contain {id}: "
45
 
             "http://bug.example.com/"),
 
45
             "http://bug.com/"),
46
46
            str(err))
47
47
 
48
48
 
61
61
 
62
62
        def get_bug_url(self, bug_id):
63
63
            self.log.append(('get_bug_url', bug_id))
64
 
            return "http://bugs.example.com/%s" % bug_id
 
64
            return "http://bugs.com/%s" % bug_id
65
65
 
66
66
    def setUp(self):
67
67
        super(TestGetBugURL, self).setUp()
72
72
 
73
73
    def test_get_bug_url_for_transient_tracker(self):
74
74
        branch = self.make_branch('some_branch')
75
 
        self.assertEqual('http://bugs.example.com/1234',
 
75
        self.assertEqual('http://bugs.com/1234',
76
76
                         bugtracker.get_bug_url('transient', branch, '1234'))
77
77
        self.assertEqual(
78
78
            [('get', 'transient', branch), ('get_bug_url', '1234')],
119
119
        """
120
120
        branch = self.make_branch('some_branch')
121
121
        config = branch.get_config()
122
 
        config.set_user_option('trac_foo_url', 'http://bugs.example.com/trac')
 
122
        config.set_user_option('trac_foo_url', 'http://bugs.com/trac')
123
123
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
124
 
        self.assertEqual('http://bugs.example.com/trac/ticket/1234',
 
124
        self.assertEqual('http://bugs.com/trac/ticket/1234',
125
125
                         tracker.get_bug_url('1234'))
126
126
 
127
127
    def test_bugzilla_registered(self):
131
131
        """
132
132
        branch = self.make_branch('some_branch')
133
133
        config = branch.get_config()
134
 
        config.set_user_option('bugzilla_foo_url', 'http://bugs.example.com')
 
134
        config.set_user_option('bugzilla_foo_url', 'http://bugs.com')
135
135
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
136
 
        self.assertEqual('http://bugs.example.com/show_bug.cgi?id=1234',
 
136
        self.assertEqual('http://bugs.com/show_bug.cgi?id=1234',
137
137
                         tracker.get_bug_url('1234'))
138
138
 
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
139
    def test_generic_registered(self):
146
140
        branch = self.make_branch('some_branch')
147
141
        config = branch.get_config()
148
 
        config.set_user_option('bugtracker_foo_url',
149
 
                               'http://bugs.example.com/{id}/view.html')
 
142
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
150
143
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
151
 
        self.assertEqual('http://bugs.example.com/1234/view.html',
 
144
        self.assertEqual('http://bugs.com/1234/view.html',
152
145
                         tracker.get_bug_url('1234'))
153
146
 
154
147
    def test_generic_registered_non_integer(self):
155
148
        branch = self.make_branch('some_branch')
156
149
        config = branch.get_config()
157
 
        config.set_user_option('bugtracker_foo_url',
158
 
                               'http://bugs.example.com/{id}/view.html')
 
150
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/{id}/view.html')
159
151
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
160
 
        self.assertEqual('http://bugs.example.com/ABC-1234/view.html',
 
152
        self.assertEqual('http://bugs.com/ABC-1234/view.html',
161
153
                         tracker.get_bug_url('ABC-1234'))
162
154
 
163
155
    def test_generic_incorrect_url(self):
164
156
        branch = self.make_branch('some_branch')
165
157
        config = branch.get_config()
166
 
        config.set_user_option('bugtracker_foo_url',
167
 
                               'http://bugs.example.com/view.html')
 
158
        config.set_user_option('bugtracker_foo_url', 'http://bugs.com/view.html')
168
159
        tracker = bugtracker.tracker_registry.get_tracker('foo', branch)
169
160
        self.assertRaises(bugtracker.InvalidBugTrackerURL, tracker.get_bug_url,
170
 
                          '1234')
 
161
                '1234')
171
162
 
172
163
 
173
164
class TestUniqueIntegerBugTracker(TestCaseWithMemoryTransport):
175
166
    def test_appends_id_to_base_url(self):
176
167
        """The URL of a bug is the base URL joined to the identifier."""
177
168
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
178
 
                                                     'http://bugs.example.com/foo')
179
 
        self.assertEqual('http://bugs.example.com/foo1234',
180
 
                         tracker.get_bug_url('1234'))
 
169
                'http://bugs.com/foo')
 
170
        self.assertEqual('http://bugs.com/foo1234', tracker.get_bug_url('1234'))
181
171
 
182
172
    def test_returns_tracker_if_abbreviation_matches(self):
183
173
        """The get() method should return an instance of the tracker if the
184
174
        given abbreviation matches the tracker's abbreviated name.
185
175
        """
186
176
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
187
 
                                                     'http://bugs.example.com/')
 
177
                'http://bugs.com/')
188
178
        branch = self.make_branch('some_branch')
189
179
        self.assertIs(tracker, tracker.get('xxx', branch))
190
180
 
193
183
        doesn't match the tracker's abbreviation.
194
184
        """
195
185
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
196
 
                                                     'http://bugs.example.com/')
 
186
                'http://bugs.com/')
197
187
        branch = self.make_branch('some_branch')
198
188
        self.assertIs(None, tracker.get('yyy', branch))
199
189
 
202
192
        information.
203
193
        """
204
194
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
205
 
                                                     'http://bugs.example.com/')
 
195
                'http://bugs.com/')
206
196
        self.assertIs(tracker, tracker.get('xxx', None))
207
197
        self.assertIs(None, tracker.get('yyy', None))
208
198
 
209
199
    def test_check_bug_id_only_accepts_integers(self):
210
200
        """A UniqueIntegerBugTracker accepts integers as bug IDs."""
211
201
        tracker = bugtracker.UniqueIntegerBugTracker('xxx',
212
 
                                                     'http://bugs.example.com/')
 
202
                'http://bugs.com/')
213
203
        tracker.check_bug_id('1234')
214
204
 
215
205
    def test_check_bug_id_doesnt_accept_non_integers(self):
216
206
        """A UniqueIntegerBugTracker rejects non-integers as bug IDs."""
217
207
        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
 
 
 
208
                'http://bugs.com/')
 
209
        self.assertRaises(
 
210
            bugtracker.MalformedBugIdentifier, tracker.check_bug_id, 'red')
273
211
 
274
212
class TestURLParametrizedBugTracker(TestCaseWithMemoryTransport):
275
213
    """Tests for URLParametrizedBugTracker."""
329
267
    def test_encoding_one(self):
330
268
        self.assertEqual(
331
269
            'http://example.com/bugs/1 fixed',
332
 
            bugtracker.encode_fixes_bug_urls(
333
 
                [('http://example.com/bugs/1', 'fixed')]))
 
270
            bugtracker.encode_fixes_bug_urls(['http://example.com/bugs/1']))
334
271
 
335
272
    def test_encoding_zero(self):
336
273
        self.assertEqual('', bugtracker.encode_fixes_bug_urls([]))
338
275
    def test_encoding_two(self):
339
276
        self.assertEqual(
340
277
            'http://example.com/bugs/1 fixed\n'
341
 
            'http://example.com/bugs/2 related',
 
278
            'http://example.com/bugs/2 fixed',
342
279
            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'))
 
280
                ['http://example.com/bugs/1', 'http://example.com/bugs/2']))