@@ -450,6 +450,132 @@ def test6(self):
450
450
]
451
451
self .verify_mock_calls (calls , False )
452
452
453
+ class TestSetAssignee (TestNewPR ):
454
+ @classmethod
455
+ def setUpClass (cls ):
456
+ cls .assignee = 'assigneeUser'
457
+ cls .author = 'authorUser'
458
+ cls .owner = 'repo-owner'
459
+ cls .repo = 'repo-name'
460
+ cls .issue = 7
461
+ cls .user = 'integrationUser'
462
+ cls .token = 'credential'
463
+
464
+ def setUp (self ):
465
+ super (TestSetAssignee , self ).setUp ()
466
+
467
+ self .patchers = {
468
+ 'api_req' : mock .patch ('highfive.newpr.api_req' ),
469
+ 'get_irc_nick' : mock .patch ('highfive.newpr.get_irc_nick' ),
470
+ 'post_comment' : mock .patch ('highfive.newpr.post_comment' ),
471
+ 'IrcClient' : mock .patch ('highfive.irc.IrcClient' ),
472
+ }
473
+ self .mocks = {k : v .start () for k ,v in self .patchers .iteritems ()}
474
+ self .mocks ['client' ] = self .mocks ['IrcClient' ].return_value
475
+
476
+ def tearDown (self ):
477
+ super (TestSetAssignee , self ).tearDown ()
478
+
479
+ for patcher in self .patchers .itervalues ():
480
+ patcher .stop ()
481
+
482
+ def set_assignee (self , assignee = '' , to_mention = None ):
483
+ assignee = self .assignee if assignee == '' else assignee
484
+ return newpr .set_assignee (
485
+ assignee , self .owner , self .repo , self .issue , self .user , self .token ,
486
+ self .author , to_mention or []
487
+ )
488
+
489
+ def assert_api_req_call (self , assignee = '' ):
490
+ assignee = self .assignee if assignee == '' else assignee
491
+ self .mocks ['api_req' ].assert_called_once_with (
492
+ 'PATCH' ,
493
+ 'https://api.github.com/repos/%s/%s/issues/%s' % (
494
+ self .owner , self .repo , self .issue
495
+ ),
496
+ {"assignee" : assignee }, self .user , self .token
497
+ )
498
+
499
+ def test_api_req_good (self ):
500
+ self .mocks ['get_irc_nick' ].return_value = None
501
+ self .set_assignee ()
502
+
503
+ self .assert_api_req_call ()
504
+ self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
505
+ self .mocks ['IrcClient' ].assert_not_called ()
506
+ self .mocks ['client' ].send_then_quit .assert_not_called ()
507
+ self .mocks ['post_comment' ].assert_not_called ()
508
+
509
+ def test_api_req_201 (self ):
510
+ self .mocks ['api_req' ].side_effect = HTTPError (None , 201 , None , None , None )
511
+ self .mocks ['get_irc_nick' ].return_value = None
512
+ self .set_assignee ()
513
+
514
+ self .assert_api_req_call ()
515
+ self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
516
+ self .mocks ['IrcClient' ].assert_not_called ()
517
+ self .mocks ['client' ].send_then_quit .assert_not_called ()
518
+ self .mocks ['post_comment' ].assert_not_called ()
519
+
520
+ def test_api_req_error (self ):
521
+ self .mocks ['api_req' ].side_effect = HTTPError (None , 403 , None , None , None )
522
+ self .assertRaises (HTTPError , self .set_assignee )
523
+
524
+ self .assert_api_req_call ()
525
+ self .mocks ['get_irc_nick' ].assert_not_called ()
526
+ self .mocks ['IrcClient' ].assert_not_called ()
527
+ self .mocks ['client' ].send_then_quit .assert_not_called ()
528
+ self .mocks ['post_comment' ].assert_not_called ()
529
+
530
+ def test_has_nick (self ):
531
+ irc_nick = 'nick'
532
+ self .mocks ['get_irc_nick' ].return_value = irc_nick
533
+
534
+ self .set_assignee ()
535
+
536
+ self .assert_api_req_call ()
537
+ self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
538
+ self .mocks ['IrcClient' ].assert_called_once_with (target = '#rust-bots' )
539
+ self .mocks ['client' ].send_then_quit .assert_called_once_with (
540
+ "{}: ping to review issue https://www.github.com/{}/{}/pull/{} by {}." .format (
541
+ irc_nick , self .owner , self .repo , self .issue , self .author
542
+ )
543
+ )
544
+ self .mocks ['post_comment' ].assert_not_called ()
545
+
546
+ def test_has_to_mention (self ):
547
+ self .mocks ['get_irc_nick' ].return_value = None
548
+
549
+ to_mention = [
550
+ {
551
+ 'message' : 'This is important' ,
552
+ 'reviewers' : ['@userA' , '@userB' , 'integrationUser' , '@userC' ],
553
+ },
554
+ {
555
+ 'message' : 'Also important' ,
556
+ 'reviewers' : ['@userD' ],
557
+ },
558
+ ]
559
+ self .set_assignee (to_mention = to_mention )
560
+
561
+ self .assert_api_req_call ()
562
+ self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
563
+ self .mocks ['IrcClient' ].assert_not_called ()
564
+ self .mocks ['client' ].send_then_quit .assert_not_called ()
565
+ self .mocks ['post_comment' ].assert_called_once_with (
566
+ 'This is important\n \n cc @userA,@userB,@userC\n \n Also important\n \n cc @userD' ,
567
+ self .owner , self .repo , self .issue , self .user , self .token
568
+ )
569
+
570
+ def test_no_assignee (self ):
571
+ self .set_assignee (None )
572
+
573
+ self .assert_api_req_call (None )
574
+ self .mocks ['get_irc_nick' ].assert_not_called ()
575
+ self .mocks ['IrcClient' ].assert_not_called ()
576
+ self .mocks ['client' ].send_then_quit .assert_not_called ()
577
+ self .mocks ['post_comment' ].assert_not_called ()
578
+
453
579
class TestPostWarnings (TestNewPR ):
454
580
@classmethod
455
581
def setUpClass (cls ):
0 commit comments