"""Tests for utility functions"""

import pytest
from zsz_package.utils import hello, greet, fetch_url


class TestHello:
    """Test suite for hello function."""

    def test_hello_default(self):
        """Test hello with default name."""
        result = hello()
        assert result == "Hello, World!"

    def test_hello_custom_name(self, sample_name):
        """Test hello with custom name."""
        result = hello(sample_name)
        assert result == f"Hello, {sample_name}!"

    def test_hello_empty_string(self):
        """Test hello with empty string."""
        result = hello("")
        assert result == "Hello, !"


class TestGreet:
    """Test suite for greet function."""

    def test_greet_english(self, sample_name):
        """Test greeting in English."""
        result = greet(sample_name, "en")
        assert result == f"Hello, {sample_name}!"

    def test_greet_spanish(self, sample_name):
        """Test greeting in Spanish."""
        result = greet(sample_name, "es")
        assert result == f"Hola, {sample_name}!"

    def test_greet_french(self, sample_name):
        """Test greeting in French."""
        result = greet(sample_name, "fr")
        assert result == f"Bonjour, {sample_name}!"

    def test_greet_german(self, sample_name):
        """Test greeting in German."""
        result = greet(sample_name, "de")
        assert result == f"Hallo, {sample_name}!"

    def test_greet_chinese(self, sample_name):
        """Test greeting in Chinese."""
        result = greet(sample_name, "zh")
        assert result == f"你好, {sample_name}!"

    def test_greet_unknown_language(self, sample_name):
        """Test greeting with unknown language defaults to English."""
        result = greet(sample_name, "xx")
        assert result == f"Hello, {sample_name}!"

    def test_greet_default_language(self, sample_name):
        """Test greeting with default language."""
        result = greet(sample_name)
        assert result == f"Hello, {sample_name}!"


class TestFetchUrl:
    """Test suite for fetch_url function."""

    def test_fetch_url_success(self):
        """Test fetching a valid URL."""
        # Using a reliable test endpoint
        result = fetch_url("https://httpbin.org/status/200")
        assert result is not None

    def test_fetch_url_invalid(self):
        """Test fetching an invalid URL."""
        result = fetch_url("https://thisisnotavalidurl123456789.com")
        assert result is None

    def test_fetch_url_timeout(self):
        """Test URL fetch with very short timeout."""
        # This URL is known to delay responses
        result = fetch_url("https://httpbin.org/delay/10", timeout=1)
        assert result is None
