File: test_vscode_credential_async.py

package info (click to toggle)
python-azure 20250829%2Bgit-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 756,824 kB
  • sloc: python: 6,224,989; ansic: 804; javascript: 287; makefile: 198; sh: 195; xml: 109
file content (28 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from unittest.mock import patch

import pytest
from azure.identity._credentials.vscode import VisualStudioCodeCredential as SyncVisualStudioCodeCredential
from azure.identity.aio._credentials.vscode import VisualStudioCodeCredential
from azure.identity import CredentialUnavailableError


class TestVisualStudioCodeCredentialAsync:
    """Test cases for the asynchronous VisualStudioCodeCredential"""

    @pytest.mark.asyncio
    async def test_credential_uses_sync_credential(self):
        """Test that the async credential uses the sync version."""
        credential = VisualStudioCodeCredential()
        assert isinstance(credential._sync_credential, SyncVisualStudioCodeCredential)

    @pytest.mark.asyncio
    async def test_invalid_auth_record(self):
        """Test that an error is raised if the auth record is nonexistent."""
        # Test with a nonexistent file
        with patch("os.path.expanduser", return_value="nonexistent_file.json"):
            with pytest.raises(CredentialUnavailableError):
                await VisualStudioCodeCredential().get_token_info("https://management.azure.com/.default")