Skip to content

Commit cf8dfc7

Browse files
Resolve test cases error 3
1 parent cab11be commit cf8dfc7

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/ContentProcessorWorkflow/src/libs/base/application_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def run(self):
3535
import os
3636
from abc import ABC, abstractmethod
3737

38-
from azure.identity import DefaultAzureCredential
3938
from utils.credential_util import get_azure_credential
4039
from dotenv import load_dotenv
4140

src/tests/ContentProcessorWorkflow/utils/test_credential_util_extended.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Extended tests for credential_util.py to improve coverage"""
22
from unittest.mock import Mock, patch
3+
import pytest
34
from utils.credential_util import (
45
get_azure_credential,
56
get_async_azure_credential,
@@ -40,24 +41,27 @@ def test_get_azure_credential_app_service_environment(self, monkeypatch):
4041
assert credential == mock_instance
4142

4243
def test_get_azure_credential_all_cli_fail(self, monkeypatch):
43-
"""Test fallback when all CLI credentials fail"""
44-
for key in ["WEBSITE_SITE_NAME", "AZURE_CLIENT_ID", "MSI_ENDPOINT",
45-
"IDENTITY_ENDPOINT", "KUBERNETES_SERVICE_HOST", "CONTAINER_REGISTRY_LOGIN"]:
44+
"""Test RuntimeError when all credential options fail"""
45+
for key in [
46+
"WEBSITE_SITE_NAME",
47+
"AZURE_CLIENT_ID",
48+
"MSI_ENDPOINT",
49+
"IDENTITY_ENDPOINT",
50+
"KUBERNETES_SERVICE_HOST",
51+
"CONTAINER_REGISTRY_LOGIN",
52+
]:
4653
monkeypatch.delenv(key, raising=False)
4754

4855
with patch('utils.credential_util.AzureCliCredential') as mock_cli, \
49-
patch('utils.credential_util.AzureDeveloperCliCredential') as mock_azd, \
50-
patch('utils.credential_util.DefaultAzureCredential') as mock_default:
56+
patch('utils.credential_util.AzureDeveloperCliCredential') as mock_azd:
5157

5258
mock_cli.side_effect = Exception("AzureCLI not available")
5359
mock_azd.side_effect = Exception("AzureDeveloperCLI not available")
54-
mock_default_instance = Mock()
55-
mock_default.return_value = mock_default_instance
5660

57-
credential = get_azure_credential()
61+
with pytest.raises(RuntimeError) as exc:
62+
get_azure_credential()
5863

59-
assert credential == mock_default_instance
60-
mock_default.assert_called_once()
64+
assert "No Azure authentication available" in str(exc.value)
6165

6266
def test_get_azure_credential_cli_success(self, monkeypatch):
6367
"""Test successful Azure CLI credential"""

0 commit comments

Comments
 (0)