File size: 1,590 Bytes
2aa2b79
 
 
2ed2bd7
2aa2b79
2ed2bd7
 
 
 
 
2aa2b79
 
 
 
2ed2bd7
2aa2b79
 
2ed2bd7
2aa2b79
 
2ed2bd7
2aa2b79
 
2ed2bd7
2aa2b79
 
2ed2bd7
2aa2b79
 
 
 
 
2ed2bd7
2aa2b79
 
 
 
 
2ed2bd7
 
2aa2b79
 
 
 
2ed2bd7
2aa2b79
2ed2bd7
2aa2b79
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Tests for logging configuration.
"""

import logging
from unittest.mock import Mock, patch

import pytest

from app.core.logging import get_logger, setup_logging


class TestLoggingSetup:
    """Test logging setup functionality."""

    def test_setup_logging_default_level(self):
        """Test logging setup with default level."""
        with patch("app.core.logging.logging.basicConfig") as mock_basic_config:
            setup_logging()
            mock_basic_config.assert_called_once()

    def test_setup_logging_custom_level(self):
        """Test logging setup with custom level."""
        with patch("app.core.logging.logging.basicConfig") as mock_basic_config:
            setup_logging()
            mock_basic_config.assert_called_once()

    def test_get_logger(self):
        """Test get_logger function."""
        logger = get_logger("test_module")
        assert isinstance(logger, logging.Logger)
        assert logger.name == "test_module"

    def test_get_logger_with_request_id(self):
        """Test get_logger function (no request_id parameter)."""
        logger = get_logger("test_module")
        assert isinstance(logger, logging.Logger)
        assert logger.name == "test_module"

    @patch("app.core.logging.logging.getLogger")
    def test_logger_creation(self, mock_get_logger):
        """Test logger creation process."""
        mock_logger = Mock()
        mock_get_logger.return_value = mock_logger

        logger = get_logger("test_module")

        mock_get_logger.assert_called_once_with("test_module")
        assert logger == mock_logger