Exemplo n.º 1
0
 def test_handle_HTTP_403_Error(self):
     error = cb.praw.requests.HTTPError('403 Forbidden')
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions(max_attempts=2)(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         wrapped()
         # Should not attempt retry after 403 error
         self.assertFalse(mock_sleep.called)
Exemplo n.º 2
0
 def test_handle_HTTP_403_Error(self):
     error = cb.praw.requests.HTTPError('403 Forbidden')
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions(max_attempts=2)(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         wrapped()
         # Should not attempt retry after 403 error
         self.assertFalse(mock_sleep.called)
Exemplo n.º 3
0
 def test_handle_generic_HTTP_Error(self):
     error = cb.praw.errors.HTTPException('')
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.errors.HTTPException:
             self.fail("HTTPError not properly handled")
Exemplo n.º 4
0
 def test_handle_generic_HTTP_Error(self):
     error = cb.praw.requests.HTTPError('')
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.requests.HTTPError:
             self.fail("HTTPError not properly handled")
Exemplo n.º 5
0
 def test_handle_Socket_Error(self):
     error = socket.error('[Errno 104] Connection reset by peer')
     error.errno = errno.ECONNRESET
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.socket.SocketError:
             self.fail("SocketError not properly handled")
Exemplo n.º 6
0
 def test_handle_Socket_Error(self):
     error = socket.error('[Errno 104] Connection reset by peer')
     error.errno = errno.ECONNRESET
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.socket.SocketError:
             self.fail("SocketError not properly handled")
Exemplo n.º 7
0
 def test_handle_API_Exceptions(self):
     error = cb.praw.errors.APIException('', '', {})
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         wrapped()
         try:
             wrapped()
         except cb.praw.requests.HTTPError:
             self.fail("APIException not properly handled")
Exemplo n.º 8
0
 def test_handle_API_Exceptions(self):
     error = cb.praw.errors.APIException('', '', {})
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         wrapped()
         try:
             wrapped()
         except cb.praw.requests.HTTPError:
             self.fail("APIException not properly handled")
Exemplo n.º 9
0
 def test_handle_rate_limit_exceeded(self):
     error = cb.praw.errors.RateLimitExceeded('', '',
                                              response = {'ratelimit': 9})
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.errors.RateLimitExceeded:
             self.fail("RateLimitExceeded not properly handled")
     mock_sleep.assert_called_once_with(9)
Exemplo n.º 10
0
 def test_handle_rate_limit_exceeded(self):
     error = cb.praw.errors.RateLimitExceeded('',
                                              '',
                                              response={'ratelimit': 9})
     mock = Mock(side_effect=error)
     mock.__name__ = str('mock')
     wrapped = cb.handle_api_exceptions()(mock)
     with patch('{}.cb.time.sleep'.format(__name__)) as mock_sleep:
         try:
             wrapped()
         except cb.praw.errors.RateLimitExceeded:
             self.fail("RateLimitExceeded not properly handled")
     mock_sleep.assert_called_once_with(9)
Exemplo n.º 11
0
    def test_generic_exceptions_propogate(self):
        mock = Mock(side_effect=RuntimeError())
        mock.__name__ = str('mock')

        wrapped = cb.handle_api_exceptions()(mock)
        self.assertRaises(RuntimeError, wrapped)
Exemplo n.º 12
0
    def test_generic_exceptions_propogate(self):
        mock = Mock(side_effect=RuntimeError())
        mock.__name__ = str('mock')

        wrapped = cb.handle_api_exceptions()(mock)
        self.assertRaises(RuntimeError, wrapped)