@@ -346,57 +346,6 @@ def test_find_reviewer(self):
346346 assert handler .find_reviewer (msg ) is None , \
347347 "expected '%s' to have no reviewer extracted" % msg
348348
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":"nrc@ncameron.org","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-
400349class TestApiReq (TestNewPR ):
401350 @pytest .fixture (autouse = True )
402351 def make_defaults (cls , patcherize ):
@@ -537,13 +486,9 @@ class TestSetAssignee(TestNewPR):
537486 def make_defaults (cls , patcherize ):
538487 cls .mocks = patcherize ((
539488 ('api_req' , 'highfive.newpr.HighfiveHandler.api_req' ),
540- ('get_irc_nick' , 'highfive.newpr.HighfiveHandler.get_irc_nick' ),
541489 ('post_comment' , 'highfive.newpr.HighfiveHandler.post_comment' ),
542- ('IrcClient' , 'highfive.irc.IrcClient' ),
543490 ))
544491
545- cls .mocks ['client' ] = cls .mocks ['IrcClient' ].return_value
546-
547492 cls .handler = HighfiveHandlerMock (Payload ({})).handler
548493 cls .assignee = 'assigneeUser'
549494 cls .author = 'authorUser'
@@ -570,24 +515,16 @@ def assert_api_req_call(self, assignee=''):
570515 )
571516
572517 def test_api_req_good (self ):
573- self .mocks ['get_irc_nick' ].return_value = None
574518 self .set_assignee ()
575519
576520 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 ()
580521 self .mocks ['post_comment' ].assert_not_called ()
581522
582523 def test_api_req_201 (self ):
583524 self .mocks ['api_req' ].side_effect = HTTPError (None , 201 , None , None , None )
584- self .mocks ['get_irc_nick' ].return_value = None
585525 self .set_assignee ()
586526
587527 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 ()
591528 self .mocks ['post_comment' ].assert_not_called ()
592529
593530 def test_api_req_error (self ):
@@ -596,30 +533,15 @@ def test_api_req_error(self):
596533 self .set_assignee ()
597534
598535 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 ()
602536 self .mocks ['post_comment' ].assert_not_called ()
603537
604538 def test_has_nick (self ):
605- irc_nick = 'nick'
606- self .mocks ['get_irc_nick' ].return_value = irc_nick
607-
608539 self .set_assignee ()
609540
610541 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- )
618542 self .mocks ['post_comment' ].assert_not_called ()
619543
620544 def test_has_to_mention (self ):
621- self .mocks ['get_irc_nick' ].return_value = None
622-
623545 to_mention = [
624546 {
625547 'message' : 'This is important' ,
@@ -633,9 +555,6 @@ def test_has_to_mention(self):
633555 self .set_assignee (to_mention = to_mention )
634556
635557 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 ()
639558 self .mocks ['post_comment' ].assert_called_once_with (
640559 'This is important\n \n cc @userA,@userB,@userC\n \n Also important\n \n cc @userD' ,
641560 self .owner , self .repo , self .issue
@@ -645,9 +564,6 @@ def test_no_assignee(self):
645564 self .set_assignee (None )
646565
647566 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 ()
651567 self .mocks ['post_comment' ].assert_not_called ()
652568
653569
0 commit comments