def test_get_service_account_throws_error(self): """Test that error is rethrown for all unexpected http errors.""" mock_get = self.mock_service_client.return_value.get response = mock.Mock() response.status = 500 mock_get.return_value.execute.side_effect = errors.HttpError(response, b'') with self.assertRaises(cloud_auth.Error): cloud_auth.get_service_account(self.project_id, self.service_account_name)
def test_get_service_account(self): """Test that service account is returned for valid account name.""" expected_account = object() mock_get = self.mock_service_client.return_value.get mock_get.return_value.execute.return_value = expected_account actual_account = cloud_auth.get_service_account(self.project_id, self.service_account_name) self.assertEqual(expected_account, actual_account)
def test_get_service_account_returns_none_when_no_account_found(self): """Test that returned service account is none when account is not found.""" mock_get = self.mock_service_client.return_value.get response = mock.Mock() response.status = 404 mock_get.return_value.execute.side_effect = errors.HttpError(response, b'') account = cloud_auth.get_service_account(self.project_id, self.service_account_name) self.assertIsNone(account)