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)
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
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
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
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
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
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
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
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)