diff --git a/highfive/newpr.py b/highfive/newpr.py index 95c916a5..39a12e0e 100755 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -327,11 +327,15 @@ def get_irc_nick(gh_name): if the user does not exist on the rustacean database, or if the user has no `irc` field associated with their username """ - data = urllib2.urlopen(rustaceans_api_url.format(username=gh_name)) - if data.getcode() == 200: - rustacean_data = json.loads(data.read()) - if rustacean_data: - return rustacean_data[0].get("irc") + try: + data = urllib2.urlopen(rustaceans_api_url.format(username=gh_name)) + if data.getcode() == 200: + rustacean_data = json.loads(data.read()) + if rustacean_data: + return rustacean_data[0].get("irc") + except urllib2.HTTPError: + pass + return None def post_warnings(payload, config, diff, owner, repo, issue, token): diff --git a/highfive/tests/test_newpr.py b/highfive/tests/test_newpr.py index 500cd860..f68b628c 100644 --- a/highfive/tests/test_newpr.py +++ b/highfive/tests/test_newpr.py @@ -255,6 +255,12 @@ def test_find_reviewer(self): ) def setup_get_irc_nick_mocks(self, mock_urllib2, status_code, data=None): + if status_code != 200: + mock_urllib2.side_effect = HTTPError( + None, status_code, None, None, None + ) + return + mock_data = mock.Mock() mock_data.getcode.return_value = status_code mock_data.read.return_value = data @@ -263,14 +269,12 @@ def setup_get_irc_nick_mocks(self, mock_urllib2, status_code, data=None): @mock.patch('highfive.newpr.urllib2') def test_get_irc_nick_non_200(self, mock_urllib2): - mock_data = self.setup_get_irc_nick_mocks(mock_urllib2, 300) + self.setup_get_irc_nick_mocks(mock_urllib2, 503) self.assertIsNone(newpr.get_irc_nick('foo')) mock_urllib2.urlopen.assert_called_with( 'http://www.ncameron.org/rustaceans/user?username=foo' ) - mock_data.getcode.assert_called() - mock_data.read.assert_not_called() @mock.patch('highfive.newpr.urllib2') def test_get_irc_nick_no_data(self, mock_urllib2):