Esempio n. 1
0
 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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_connection_reset(self):
        class SysCallError(Exception):
            pass

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

        with self.assertRaises(ConnectionReset):
            _translate_errors(fcn)
Esempio n. 4
0
    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)
Esempio n. 5
0
    def test_unknown_error(self):
        def fcn():
            raise Exception('a message')

        with self.assertRaises(UnknownError):
            _translate_errors(fcn)
Esempio n. 6
0
    def test_connection_error(self):
        def fcn():
            raise requests.ConnectionError('a message')

        with self.assertRaises(B2ConnectionError):
            _translate_errors(fcn)
Esempio n. 7
0
 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