示例#1
0
 def test_raise_ioerror_on_503(self, mock_get):
     """:func:`.fulltext.retrieve` raises IOError when text unvailable."""
     response = mock.MagicMock()
     type(response).json = mock.MagicMock(return_value=None)
     response.status_code = 503
     mock_get.return_value = response
     with self.assertRaises(IOError):
         fulltext.retrieve('1234.5678v3')
示例#2
0
 def test_raise_ioerror_on_sslerror(self, mock_get):
     """:func:`.fulltext.retrieve` raises IOError when SSL fails."""
     from requests.exceptions import SSLError
     mock_get.side_effect = SSLError
     with self.assertRaises(IOError):
         try:
             fulltext.retrieve('1234.5678v3')
         except Exception as e:
             if type(e) is SSLError:
                 self.fail('Should not return dependency exception')
             raise
示例#3
0
    def test_response_is_not_json(self, mock_get):
        """:func:`.fulltext.retrieve` raises IOError when not valid JSON."""
        from json.decoder import JSONDecodeError
        response = mock.MagicMock()

        # Ideally we would pass the exception itself as a side_effect, but it
        #  doesn't have the expected signature.
        def raise_decodeerror(*args, **kwargs):
            raise JSONDecodeError('Nope', 'Nope', 0)

        type(response).json = mock.MagicMock(side_effect=raise_decodeerror)
        response.status_code = 200
        mock_get.return_value = response
        with self.assertRaises(IOError):
            fulltext.retrieve('1234.5678v3')