File: test_bearer_token_provider_async.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (33 lines) | stat: -rw-r--r-- 1,002 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
29
30
31
32
33
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

from azure.core.credentials import AccessToken, AccessTokenInfo
from azure.identity.aio import get_bearer_token_provider

import pytest


class MockCredential:
    async def get_token(self, *scopes, **kwargs):
        assert len(scopes) == 1
        assert scopes[0] == "scope"
        return AccessToken("mock_token", 42)


class MockCredentialTokenInfo:
    async def get_token_info(self, *scopes, **kwargs):
        assert len(scopes) == 1
        assert scopes[0] == "scope"
        return AccessTokenInfo("mock_token_2", 42)


@pytest.mark.asyncio
async def test_get_bearer_token_provider():

    func = get_bearer_token_provider(MockCredential(), "scope")  # type: ignore
    assert await func() == "mock_token"

    func = get_bearer_token_provider(MockCredentialTokenInfo(), "scope")  # type: ignore
    assert await func() == "mock_token_2"