def it_handles_no_encoding(self): resp = mock_response( ' ', status_code=200, encoding=None, headers=None) resp.apparent_encoding = 'utf-8' with patch('requests.request') as mock_method: mock_method.return_value = resp Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
def it_handles_empty_responses(self): resp = mock_response('', status_code=202) with patch('requests.request') as mock_method: mock_method.return_value = resp Request.send_request_to_path('GET', 'events', ('x', 'y'), resp) resp = mock_response(' ', status_code=202) with patch('requests.request') as mock_method: mock_method.return_value = resp Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
def it_needs_encoding_or_apparent_encoding(self): payload = '{}' if not hasattr(payload, 'decode'): # python 3 payload = payload.encode('utf-8') resp = mock_response( payload, status_code=200, encoding=None, headers=None) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(TypeError): Request.send_request_to_path('GET', 'events', ('x', 'y'), resp)
def it_raises_service_unavailable_error(self): resp = mock_response('{}', status_code=503) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(intercom.ServiceUnavailableError): Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)
def it_raises_bad_gateway_error(self): resp = mock_response('{}', status_code=502) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(intercom.BadGatewayError): Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)
def it_raises_server_error(self): resp = Mock(encoding="utf-8", content='{}', status_code=500) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(intercom.ServerError): Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)
def it_raises_authentication_error_forbidden(self): resp = mock_response('{}', status_code=403) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(intercom.AuthenticationError): Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)
def it_raises_resource_not_found(self): resp = mock_response('{}', status_code=404) with patch('requests.request') as mock_method: mock_method.return_value = resp with assert_raises(intercom.ResourceNotFound): Request.send_request_to_path('GET', 'notes', ('x', 'y'), resp)