File: test_utility_edge_cases.py

package info (click to toggle)
python-bsblan 3.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,028 kB
  • sloc: python: 4,453; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,515 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
34
35
36
37
38
39
40
41
42
43
44
45
"""Test utility module edge cases."""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING
from unittest.mock import MagicMock

from bsblan.constants import API_V3
from bsblan.utility import APIValidator

if TYPE_CHECKING:
    import pytest


def test_validate_section_unknown_section(caplog: pytest.LogCaptureFixture) -> None:
    """Test validation of an unknown section logs warning and returns."""
    api_validator = APIValidator(API_V3)

    # Mock the api_config to not have the section we're testing
    api_validator.api_config = MagicMock()
    api_validator.api_config.__contains__ = MagicMock(return_value=False)

    with caplog.at_level(logging.WARNING):
        api_validator.validate_section("unknown_section", {})

    # Should log a warning
    assert "Unknown section 'unknown_section' in API configuration" in caplog.text

    # Section should not be added to validated_sections
    assert "unknown_section" not in api_validator.validated_sections


def test_validate_section_already_validated(caplog: pytest.LogCaptureFixture) -> None:
    """Test validation of an already validated section logs debug and returns."""
    api_validator = APIValidator(API_V3)

    # Add section to validated_sections first
    api_validator.validated_sections.add("hot_water")

    with caplog.at_level(logging.DEBUG):
        api_validator.validate_section("hot_water", {})

    # Should log a debug message
    assert "Section 'hot_water' was already validated" in caplog.text