~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/externalbugtracker/tests/test_github.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2019-04-16 09:13:27 UTC
  • mfrom: (18926.1.1 github-use-issue-number)
  • Revision ID: launchpad@pqm.canonical.com-20190416091327-3mggdav2awe8giu4
[r=twom][bug=1824728] Expect the upstream bug ID in the "number"
 field of GitHub issue objects, not the "id" field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2016-2018 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2016-2019 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for the GitHub Issues BugTracker."""
138
138
        super(TestGitHub, self).setUp()
139
139
        self.addCleanup(getUtility(IGitHubRateLimit).clearCache)
140
140
        self.sample_bugs = [
141
 
            {"id": 1, "state": "open", "labels": []},
142
 
            {"id": 2, "state": "open", "labels": [{"name": "feature"}]},
143
 
            {"id": 3, "state": "open",
 
141
            {"id": 101, "number": 1, "state": "open", "labels": []},
 
142
            {"id": 102, "number": 2, "state": "open",
 
143
             "labels": [{"name": "feature"}]},
 
144
            {"id": 103, "number": 3, "state": "open",
144
145
             "labels": [{"name": "feature"}, {"name": "ui"}]},
145
 
            {"id": 4, "state": "closed", "labels": []},
146
 
            {"id": 5, "state": "closed", "labels": [{"name": "feature"}]},
 
146
            {"id": 104, "number": 4, "state": "closed", "labels": []},
 
147
            {"id": 105, "number": 5, "state": "closed",
 
148
             "labels": [{"name": "feature"}]},
147
149
            ]
148
150
 
149
151
    def test_implements_interface(self):
220
222
        self._addIssuesResponse()
221
223
        tracker = GitHub("https://github.com/user/repository/issues")
222
224
        self.assertEqual(
223
 
            {bug["id"]: bug for bug in self.sample_bugs[:2]},
 
225
            {bug["number"]: bug for bug in self.sample_bugs[:2]},
224
226
            tracker.getRemoteBugBatch(["1", "2"]))
225
227
        self.assertEqual(
226
228
            "https://api.github.com/repos/user/repository/issues?state=all",
233
235
        tracker = GitHub("https://github.com/user/repository/issues")
234
236
        since = datetime(2015, 1, 1, 12, 0, 0, tzinfo=pytz.UTC)
235
237
        self.assertEqual(
236
 
            {bug["id"]: bug for bug in self.sample_bugs[:2]},
 
238
            {bug["number"]: bug for bug in self.sample_bugs[:2]},
237
239
            tracker.getRemoteBugBatch(["1", "2"], last_accessed=since))
238
240
        self.assertEqual(
239
241
            "https://api.github.com/repos/user/repository/issues?"
246
248
        self._addIssuesResponse()
247
249
        tracker = GitHub("https://github.com/user/repository/issues")
248
250
        tracker.initializeRemoteBugDB(
249
 
            [str(bug["id"]) for bug in self.sample_bugs])
 
251
            [str(bug["number"]) for bug in self.sample_bugs])
250
252
        responses.reset()
251
253
        self.assertEqual(
252
 
            {bug["id"]: bug for bug in self.sample_bugs[:2]},
 
254
            {bug["number"]: bug for bug in self.sample_bugs[:2]},
253
255
            tracker.getRemoteBugBatch(["1", "2"]))
254
256
        self.assertEqual(0, len(responses.calls))
255
257
 
278
280
            callback=issues_callback, content_type="application/json")
279
281
        tracker = GitHub("https://github.com/user/repository/issues")
280
282
        self.assertEqual(
281
 
            {bug["id"]: bug for bug in self.sample_bugs},
 
283
            {bug["number"]: bug for bug in self.sample_bugs},
282
284
            tracker.getRemoteBugBatch(
283
 
                [str(bug["id"]) for bug in self.sample_bugs]))
 
285
                [str(bug["number"]) for bug in self.sample_bugs]))
284
286
        expected_urls = [
285
287
            "https://api.github.com/rate_limit",
286
288
            "https://api.github.com/repos/user/repository/issues?state=all",
293
295
    @responses.activate
294
296
    def test_status_open(self):
295
297
        self.sample_bugs = [
296
 
            {"id": 1, "state": "open", "labels": []},
 
298
            {"id": 101, "number": 1, "state": "open", "labels": []},
297
299
            # Labels do not affect status, even if names collide.
298
 
            {"id": 2, "state": "open",
 
300
            {"id": 102, "number": 2, "state": "open",
299
301
             "labels": [{"name": "feature"}, {"name": "closed"}]},
300
302
            ]
301
303
        _add_rate_limit_response("api.github.com")
314
316
    @responses.activate
315
317
    def test_status_closed(self):
316
318
        self.sample_bugs = [
317
 
            {"id": 1, "state": "closed", "labels": []},
 
319
            {"id": 101, "number": 1, "state": "closed", "labels": []},
318
320
            # Labels do not affect status, even if names collide.
319
 
            {"id": 2, "state": "closed",
 
321
            {"id": 102, "number": 2, "state": "closed",
320
322
             "labels": [{"name": "feature"}, {"name": "open"}]},
321
323
            ]
322
324
        _add_rate_limit_response("api.github.com")
339
341
 
340
342
    @responses.activate
341
343
    def test_process_one(self):
342
 
        remote_bug = {"id": 1234, "state": "open", "labels": []}
 
344
        remote_bug = {
 
345
            "id": 12345, "number": 1234, "state": "open", "labels": [],
 
346
            }
343
347
        _add_rate_limit_response("api.github.com")
344
348
        responses.add(
345
349
            "GET", "https://api.github.com/repos/user/repository/issues/1234",
371
375
    @responses.activate
372
376
    def test_process_many(self):
373
377
        remote_bugs = [
374
 
            {"id": bug_id,
 
378
            {"id": bug_id + 1, "number": bug_id,
375
379
             "state": "open" if (bug_id % 2) == 0 else "closed",
376
380
             "labels": []}
377
381
            for bug_id in range(1000, 1010)]
385
389
            bugtrackertype=BugTrackerType.GITHUB)
386
390
        for remote_bug in remote_bugs:
387
391
            bug.addWatch(
388
 
                bug_tracker, str(remote_bug["id"]),
 
392
                bug_tracker, str(remote_bug["number"]),
389
393
                getUtility(ILaunchpadCelebrities).janitor)
390
394
        transaction.commit()
391
395
        logger = BufferLogger()