|
1 | 1 | """Extended tests for credential_util.py to improve coverage""" |
2 | 2 | from unittest.mock import Mock, patch |
| 3 | +import pytest |
3 | 4 | from utils.credential_util import ( |
4 | 5 | get_azure_credential, |
5 | 6 | get_async_azure_credential, |
@@ -40,24 +41,27 @@ def test_get_azure_credential_app_service_environment(self, monkeypatch): |
40 | 41 | assert credential == mock_instance |
41 | 42 |
|
42 | 43 | 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 | + ]: |
46 | 53 | monkeypatch.delenv(key, raising=False) |
47 | 54 |
|
48 | 55 | 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: |
51 | 57 |
|
52 | 58 | mock_cli.side_effect = Exception("AzureCLI not available") |
53 | 59 | mock_azd.side_effect = Exception("AzureDeveloperCLI not available") |
54 | | - mock_default_instance = Mock() |
55 | | - mock_default.return_value = mock_default_instance |
56 | 60 |
|
57 | | - credential = get_azure_credential() |
| 61 | + with pytest.raises(RuntimeError) as exc: |
| 62 | + get_azure_credential() |
58 | 63 |
|
59 | | - assert credential == mock_default_instance |
60 | | - mock_default.assert_called_once() |
| 64 | + assert "No Azure authentication available" in str(exc.value) |
61 | 65 |
|
62 | 66 | def test_get_azure_credential_cli_success(self, monkeypatch): |
63 | 67 | """Test successful Azure CLI credential""" |
|
0 commit comments