Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tests/test_config_util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for the configuration utility."""

import os
import re
import pytest
from unittest.mock import patch
from urllib.parse import urlparse
from weather_cli.config_util import ConfigUtil
from weather_cli.exceptions import ConfigException

Expand Down Expand Up @@ -95,9 +97,17 @@ def test_custom_url_logged(self, caplog):
with caplog.at_level("DEBUG"):
ConfigUtil.get_api_base_url()

# Check that the URL is mentioned in log messages
# Parse the expected URL to extract and validate hostname
parsed_url = urlparse("https://test.api.com")
expected_hostname = parsed_url.hostname

# Check that a URL with the expected hostname is mentioned in log messages
log_messages = [record.message for record in caplog.records]
assert any("https://test.api.com" in msg for msg in log_messages)
assert any(
urlparse(url).hostname == expected_hostname
for msg in log_messages
for url in re.findall(r"https?://[^\s]+", msg)
)

def test_default_url_logged(self, caplog):
"""Test that default API URL is logged in debug messages."""
Expand Down