@@ -346,57 +346,6 @@ def test_find_reviewer(self):
346
346
assert handler .find_reviewer (msg ) is None , \
347
347
"expected '%s' to have no reviewer extracted" % msg
348
348
349
- def setup_get_irc_nick_mocks (self , mock_urllib , status_code , data = None ):
350
- if status_code != 200 :
351
- mock_urllib .side_effect = HTTPError (
352
- None , status_code , None , None , None
353
- )
354
- return
355
-
356
- mock_data = mock .Mock ()
357
- mock_data .getcode .return_value = status_code
358
- mock_data .read .return_value = data
359
- mock_urllib .request .urlopen .return_value = mock_data
360
- return mock_data
361
-
362
- @mock .patch ('highfive.newpr.urllib' )
363
- def test_get_irc_nick_non_200 (self , mock_urllib ):
364
- handler = HighfiveHandlerMock (Payload ({})).handler
365
- self .setup_get_irc_nick_mocks (mock_urllib , 503 )
366
- assert handler .get_irc_nick ('foo' ) is None
367
-
368
- mock_urllib .request .urlopen .assert_called_with (
369
- 'http://www.ncameron.org/rustaceans/user?username=foo'
370
- )
371
-
372
- @mock .patch ('highfive.newpr.urllib' )
373
- def test_get_irc_nick_no_data (self , mock_urllib ):
374
- handler = HighfiveHandlerMock (Payload ({})).handler
375
- mock_data = self .setup_get_irc_nick_mocks (mock_urllib , 200 , '[]' )
376
- assert handler .get_irc_nick ('foo' ) is None
377
-
378
- mock_urllib .request .urlopen .assert_called_with (
379
- 'http://www.ncameron.org/rustaceans/user?username=foo'
380
- )
381
- mock_data .getcode .assert_called ()
382
- mock_data .read .assert_called ()
383
-
384
- @mock .patch ('highfive.newpr.urllib' )
385
- def test_get_irc_nick_has_data (self , mock_urllib ):
386
- handler = HighfiveHandlerMock (Payload ({})).handler
387
- mock_data = self .setup_get_irc_nick_mocks (
388
- mock_urllib , 200 ,
389
- '[{"username":"nrc","name":"Nick Cameron","irc":"nrc","email":"[email protected] ","discourse":"nrc","reddit":"nick29581","twitter":"@nick_r_cameron","blog":"https://www.ncameron.org/blog","website":"https://www.ncameron.org","notes":"<p>I work on the Rust compiler, language design, and tooling. I lead the dev tools team and am part of the core team. I'm part of the research team at Mozilla.</p>\\ n","avatar":"https://avatars.githubusercontent.com/nrc","irc_channels":["rust-dev-tools","rust","rust-internals","rust-lang","rustc","servo"]}]'
390
- )
391
- assert handler .get_irc_nick ('nrc' ) == 'nrc'
392
-
393
- mock_urllib .request .urlopen .assert_called_with (
394
- 'http://www.ncameron.org/rustaceans/user?username=nrc'
395
- )
396
- mock_data .getcode .assert_called ()
397
- mock_data .read .assert_called ()
398
-
399
-
400
349
class TestApiReq (TestNewPR ):
401
350
@pytest .fixture (autouse = True )
402
351
def make_defaults (cls , patcherize ):
@@ -537,13 +486,9 @@ class TestSetAssignee(TestNewPR):
537
486
def make_defaults (cls , patcherize ):
538
487
cls .mocks = patcherize ((
539
488
('api_req' , 'highfive.newpr.HighfiveHandler.api_req' ),
540
- ('get_irc_nick' , 'highfive.newpr.HighfiveHandler.get_irc_nick' ),
541
489
('post_comment' , 'highfive.newpr.HighfiveHandler.post_comment' ),
542
- ('IrcClient' , 'highfive.irc.IrcClient' ),
543
490
))
544
491
545
- cls .mocks ['client' ] = cls .mocks ['IrcClient' ].return_value
546
-
547
492
cls .handler = HighfiveHandlerMock (Payload ({})).handler
548
493
cls .assignee = 'assigneeUser'
549
494
cls .author = 'authorUser'
@@ -570,24 +515,16 @@ def assert_api_req_call(self, assignee=''):
570
515
)
571
516
572
517
def test_api_req_good (self ):
573
- self .mocks ['get_irc_nick' ].return_value = None
574
518
self .set_assignee ()
575
519
576
520
self .assert_api_req_call ()
577
- self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
578
- self .mocks ['IrcClient' ].assert_not_called ()
579
- self .mocks ['client' ].send_then_quit .assert_not_called ()
580
521
self .mocks ['post_comment' ].assert_not_called ()
581
522
582
523
def test_api_req_201 (self ):
583
524
self .mocks ['api_req' ].side_effect = HTTPError (None , 201 , None , None , None )
584
- self .mocks ['get_irc_nick' ].return_value = None
585
525
self .set_assignee ()
586
526
587
527
self .assert_api_req_call ()
588
- self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
589
- self .mocks ['IrcClient' ].assert_not_called ()
590
- self .mocks ['client' ].send_then_quit .assert_not_called ()
591
528
self .mocks ['post_comment' ].assert_not_called ()
592
529
593
530
def test_api_req_error (self ):
@@ -596,30 +533,15 @@ def test_api_req_error(self):
596
533
self .set_assignee ()
597
534
598
535
self .assert_api_req_call ()
599
- self .mocks ['get_irc_nick' ].assert_not_called ()
600
- self .mocks ['IrcClient' ].assert_not_called ()
601
- self .mocks ['client' ].send_then_quit .assert_not_called ()
602
536
self .mocks ['post_comment' ].assert_not_called ()
603
537
604
538
def test_has_nick (self ):
605
- irc_nick = 'nick'
606
- self .mocks ['get_irc_nick' ].return_value = irc_nick
607
-
608
539
self .set_assignee ()
609
540
610
541
self .assert_api_req_call ()
611
- self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
612
- self .mocks ['IrcClient' ].assert_called_once_with (target = '#rust-bots' )
613
- self .mocks ['client' ].send_then_quit .assert_called_once_with (
614
- "{}: ping to review issue https://www.github.com/{}/{}/pull/{} by {}." .format (
615
- irc_nick , self .owner , self .repo , self .issue , self .author
616
- )
617
- )
618
542
self .mocks ['post_comment' ].assert_not_called ()
619
543
620
544
def test_has_to_mention (self ):
621
- self .mocks ['get_irc_nick' ].return_value = None
622
-
623
545
to_mention = [
624
546
{
625
547
'message' : 'This is important' ,
@@ -633,9 +555,6 @@ def test_has_to_mention(self):
633
555
self .set_assignee (to_mention = to_mention )
634
556
635
557
self .assert_api_req_call ()
636
- self .mocks ['get_irc_nick' ].assert_called_once_with (self .assignee )
637
- self .mocks ['IrcClient' ].assert_not_called ()
638
- self .mocks ['client' ].send_then_quit .assert_not_called ()
639
558
self .mocks ['post_comment' ].assert_called_once_with (
640
559
'This is important\n \n cc @userA,@userB,@userC\n \n Also important\n \n cc @userD' ,
641
560
self .owner , self .repo , self .issue
@@ -645,9 +564,6 @@ def test_no_assignee(self):
645
564
self .set_assignee (None )
646
565
647
566
self .assert_api_req_call (None )
648
- self .mocks ['get_irc_nick' ].assert_not_called ()
649
- self .mocks ['IrcClient' ].assert_not_called ()
650
- self .mocks ['client' ].send_then_quit .assert_not_called ()
651
567
self .mocks ['post_comment' ].assert_not_called ()
652
568
653
569
0 commit comments