def test_client_wrapper_raises_an_error_when_create_client_fails(self): # Act with patch.object(CloudShellClient, 'create_client', side_effect=FatalError('failure')): with self.assertRaises(FatalError) as context: create_cloudshell_client() # Assert self.assertEqual(context.exception.message, 'failure')
def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_regular_exception(self, api_mock): # Arrange api_mock.side_effect = [Exception(), Exception()] # Act with self.assertRaises(FatalError) as context: create_cloudshell_client(retries=2) # Assert self.assertEqual(context.exception.message, CloudShellClient.ConnectionFailureMessage)
def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries(self, api_mock): # Arrange api_mock.side_effect = [Exception(), api_mock] # Act with patch.object(CloudShellClient, 'create_client', side_effect=FatalError('failure')): with self.assertRaises(FatalError) as context: create_cloudshell_client(retries=2) # Assert self.assertEqual(context.exception.message, 'failure')
def test_client_wrapper_raises_an_error_when_create_client_fails_after_retries_http_error(self, api_mock): # Arrange error = HTTPError('url', 401, 'not found', None, None) api_mock.side_effect = [error, error] # Act with self.assertRaises(FatalError) as context: create_cloudshell_client(retries=2) # Assert self.assertEqual(context.exception.message, u'Login to CloudShell failed. Please verify the credentials in the config')
def test_client_wrapper_creates_client_successfully_after_initial_exception(self, api_mock): # Arrange api_mock.side_effect = [Exception(), api_mock] # Act cs_client = create_cloudshell_client(retries=2) # Assert self.assertEqual(cs_client, api_mock)
def test_client_wrapper_creates_client_successfully(self, api_mock): # Arrange api_mock.return_value = api_mock # Act cs_client = create_cloudshell_client() # Assert self.assertEqual(cs_client, api_mock)