File: test_decorators.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,024 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.
# ------------------------------------
import logging
from unittest.mock import patch

from azure.identity._internal.decorators import log_get_token
from azure.identity.aio._internal.decorators import log_get_token_async
import pytest


@log_get_token
def fake_method(*_, **__):
    return "token"


@log_get_token_async
async def fake_method_async(*_, **__):
    return "token"


def test_log_get_token():
    with patch("azure.identity._internal.decorators._LOGGER") as mock_logger:
        assert fake_method() == "token"
        mock_logger.log.assert_called_once_with(logging.INFO, "%s succeeded", "fake_method")


@pytest.mark.asyncio
async def test_log_get_token_async():
    with patch("azure.identity.aio._internal.decorators._LOGGER") as mock_logger:
        assert await fake_method_async() == "token"
        mock_logger.log.assert_called_once_with(logging.INFO, "%s succeeded", "fake_method_async")