@@ -25,6 +25,7 @@ def setUp(self):
25
25
26
26
self .mock_org = create_autospec (github3 .orgs .Organization )
27
27
self .mock_gh = create_autospec (github3 .GitHub )
28
+
28
29
self .mock_team = create_autospec (github3 .orgs .Team )
29
30
self .mock_team .name = PropertyMock ()
30
31
self .mock_team .name = 'mocked team'
@@ -343,3 +344,90 @@ def test_invite_me(self):
343
344
'Command \" hey\" / \" hey there\" not found.' )
344
345
with self .assertRaises (queue .Empty ):
345
346
testbot .pop_message ()
347
+
348
+ def test_migrate_issue (self ):
349
+ plugins .labhub .GitHub = create_autospec (IGitt .GitHub .GitHub .GitHub )
350
+ plugins .labhub .GitLab = create_autospec (IGitt .GitLab .GitLab .GitLab )
351
+ labhub , testbot = plugin_testbot (plugins .labhub .LabHub , logging .ERROR )
352
+ labhub .activate ()
353
+
354
+ labhub .REPOS = {
355
+ 'a' : self .mock_repo ,
356
+ 'b' : self .mock_repo
357
+ }
358
+
359
+ mock_maint_team = create_autospec (github3 .orgs .Team )
360
+ mock_maint_team .is_member .return_value = False
361
+
362
+ labhub .TEAMS = {
363
+ 'coala maintainers' : mock_maint_team ,
364
+ 'coala developers' : self .mock_team ,
365
+ 'coala newcomers' : self .mock_team
366
+ }
367
+ cmd = '!migrate https://github.com/{}/{}/issues/{} https://github.com/{}/{}/'
368
+
369
+ # Not a maintainer
370
+ testbot .assertCommand (cmd .format ('coala' , 'a' , '21' ,'coala' ,'b' ),
371
+ 'you are not a maintainer!' )
372
+ # Unknown first org
373
+ testbot .assertCommand (cmd .format ('coa' , 'a' , '23' ,'coala' ,'b' ),
374
+ 'First repository not owned by our org' )
375
+ # Unknown second org
376
+ testbot .assertCommand (cmd .format ('coala' , 'a' , '23' ,'coa' ,'b' ),
377
+ 'Second repository not owned by our org' )
378
+ # Repo does not exist
379
+ testbot .assertCommand (cmd .format ('coala' , 'c' , '23' ,'coala' ,'b' ),
380
+ 'Repository does not exist' )
381
+ # No issue exists
382
+ mock_maint_team .is_member .return_value = True
383
+ self .mock_repo .get_issue = Mock (side_effect = RuntimeError )
384
+ testbot .assertCommand (cmd .format ('coala' , 'a' , '21' ,'coala' ,'b' ),
385
+ 'Issue does not exist!' )
386
+ # Issue closed
387
+ mock_maint_team .is_member .return_value = True
388
+ mock_iss = create_autospec (IGitt .GitHub .GitHub .GitHubIssue )
389
+ self .mock_repo .get_issue = Mock (return_value = mock_iss )
390
+ mock_iss .labels = PropertyMock ()
391
+ mock_iss .state = PropertyMock ()
392
+ mock_iss .state = 'closed'
393
+ testbot .assertCommand (cmd .format ('coala' , 'a' , '21' ,'coala' ,'b' ),
394
+ 'has been closed already' )
395
+ # Migrate issue
396
+ mock_maint_team .is_member .return_value = True
397
+ mock_iss = create_autospec (IGitt .GitHub .GitHub .GitHubIssue )
398
+ issue2 = create_autospec (IGitt .GitHub .GitHub .GitHubIssue )
399
+
400
+ self .mock_repo .get_issue = Mock (return_value = mock_iss )
401
+ label_prop = PropertyMock (return_value = {'enhancement' ,'bug' })
402
+ type(mock_iss ).labels = label_prop
403
+ mock_iss .title = PropertyMock ()
404
+ mock_iss .labels = 'Issue title'
405
+ mock_iss .description = PropertyMock ()
406
+ mock_iss .description = 'Issue description'
407
+ mock_iss .state = PropertyMock ()
408
+ mock_iss .state = 'open'
409
+
410
+ self .mock_repo .create_issue = Mock (return_value = issue2 )
411
+ issue2 .labels = PropertyMock ()
412
+
413
+ mock_comment = create_autospec (IGitt .GitHub .GitHub .GitHubComment )
414
+ mock_comment2 = create_autospec (IGitt .GitHub .GitHub .GitHubComment )
415
+
416
+ mock_iss .comments = PropertyMock ()
417
+ mock_iss .comments = list ()
418
+ mock_iss .comments .append (mock_comment )
419
+ mock_comment .author = PropertyMock ()
420
+ mock_comment .author = 'random-access7'
421
+ mock_comment .body = PropertyMock ()
422
+ mock_comment .body = 'Comment bobdy'
423
+ mock_comment .number = PropertyMock ()
424
+ mock_comment .number = 1743
425
+ mock_comment .updated = PropertyMock ()
426
+ mock_comment .updated = '07/04/2018'
427
+
428
+ issue2 .add_comment = Mock (return_value = mock_comment2 )
429
+ mock_iss .add_comment = Mock (return_value = mock_comment2 )
430
+ mock_iss .close = Mock (return_value = True )
431
+
432
+ testbot .assertCommand (cmd .format ('coala' , 'a' , '21' ,'coala' ,'b' ),
433
+ 'issue created:' )
0 commit comments