How to use the b2sdk.b2http._translate_errors function in b2sdk

To help you get started, we’ve selected a few b2sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_b2_error(self):
        response = MagicMock()
        response.status_code = 503
        response.content = six.b('{"status": 503, "code": "server_busy", "message": "busy"}')
        with self.assertRaises(ServiceError):
            _translate_errors(lambda: response)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_broken_pipe(self):
        def fcn():
            raise requests.ConnectionError(
                requests.packages.urllib3.exceptions.ProtocolError(
                    "dummy", socket.error(20, 'Broken pipe')
                )
            )

        with self.assertRaises(BrokenPipe):
            _translate_errors(fcn)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_ok(self):
        response = MagicMock()
        response.status_code = 200
        actual = _translate_errors(lambda: response)
        self.assertTrue(response is actual)  # no assertIs until 2.7
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_connection_error(self):
        def fcn():
            raise requests.ConnectionError('a message')

        with self.assertRaises(B2ConnectionError):
            _translate_errors(fcn)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_unknown_error(self):
        def fcn():
            raise Exception('a message')

        with self.assertRaises(UnknownError):
            _translate_errors(fcn)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_connection_reset(self):
        class SysCallError(Exception):
            pass

        def fcn():
            raise SysCallError('(104, ECONNRESET)')

        with self.assertRaises(ConnectionReset):
            _translate_errors(fcn)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_too_many_requests(self):
        response = MagicMock()
        response.status_code = 429
        response.headers = {'retry-after': 1}
        response.content = six.b(
            '{"status": 429, "code": "Too Many requests", "message": "retry after some time"}'
        )
        with self.assertRaises(TooManyRequests):
            _translate_errors(lambda: response)
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_partial_content(self):
        response = MagicMock()
        response.status_code = 206
        actual = _translate_errors(lambda: response)
        self.assertTrue(response is actual)  # no assertIs until 2.7
github Backblaze / b2-sdk-python / test / test_b2http.py View on Github external
def test_unknown_host(self):
        def fcn():
            raise requests.ConnectionError(
                requests.packages.urllib3.exceptions.MaxRetryError(
                    'AAA nodename nor servname provided, or not known AAA', 'http://example.com'
                )
            )

        with self.assertRaises(UnknownHost):
            _translate_errors(fcn)