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)
    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)
    def test_connection_reset(self):
        class SysCallError(Exception):
            pass

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

        with self.assertRaises(ConnectionReset):
            _translate_errors(fcn)
    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)
예제 #5
0
 def test_unknown_error(self):
     def fcn():
         raise Exception('a message')
     # no assertRaises until 2.7
     try:
         _translate_errors(fcn)
         self.fail('should have raised UnknownError')
     except UnknownError:
         pass
예제 #6
0
 def test_connection_error(self):
     def fcn():
         raise requests.ConnectionError('a message')
     # no assertRaises until 2.7
     try:
         _translate_errors(fcn)
         self.fail('should have raised ConnectionError')
     except ConnectionError:
         pass
예제 #7
0
 def test_b2_error(self):
     response = MagicMock()
     response.status_code = 503
     response.content = six.b('{"status": 503, "code": "server_busy", "message": "busy"}')
     # no assertRaises until 2.7
     try:
         _translate_errors(lambda: response)
         self.fail('should have raised ServiceError')
     except ServiceError:
         pass
예제 #8
0
 def test_b2_error(self):
     response = MagicMock()
     response.status_code = 503
     response.content = six.b('{"status": 503, "code": "server_busy", "message": "busy"}')
     # no assertRaises until 2.7
     try:
         _translate_errors(lambda: response)
         self.fail('should have raised ServiceError')
     except ServiceError:
         pass
예제 #9
0
    def test_broken_pipe(self):
        def fcn():
            raise requests.ConnectionError(
                requests.packages.urllib3.exceptions.ProtocolError(
                    "dummy", socket.error(20, 'Broken pipe')))

        # no assertRaises until 2.7
        try:
            _translate_errors(fcn)
            self.fail('should have raised BrokenPipe')
        except BrokenPipe:
            pass
예제 #10
0
    def test_broken_pipe(self):
        def fcn():
            raise requests.ConnectionError(
                requests.packages.urllib3.exceptions.
                ProtocolError("dummy", socket.error(20, 'Broken pipe'))
            )

        # no assertRaises until 2.7
        try:
            _translate_errors(fcn)
            self.fail('should have raised BrokenPipe')
        except BrokenPipe:
            pass
예제 #11
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'))

        # no assertRaises until 2.7
        try:
            _translate_errors(fcn)
            self.fail('should have raised UnknownHost')
        except UnknownHost:
            pass
예제 #12
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'
             )
         )
     # no assertRaises until 2.7
     try:
         _translate_errors(fcn)
         self.fail('should have raised UnknownHost')
     except UnknownHost:
         pass
예제 #13
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
예제 #14
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
    def test_unknown_error(self):
        def fcn():
            raise Exception('a message')

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

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