Skip to main content
Glama

Hostaway MCP Server

test_config.py6.86 kB
"""Unit tests for HostawayConfig model. Tests environment variable loading, validation, and default values. """ import os from unittest.mock import patch import pytest from pydantic import ValidationError from src.mcp.config import HostawayConfig class TestHostawayConfig: """Test suite for HostawayConfig model.""" def test_config_loads_required_env_vars(self) -> None: """Test that config loads required environment variables.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() assert config.account_id == "test_account_123" assert config.secret_key.get_secret_value() == "test_secret_key_abc" def test_config_uses_default_api_base_url(self) -> None: """Test that config uses default API base URL when not provided.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() assert config.api_base_url == "https://api.hostaway.com/v1" def test_config_uses_custom_api_base_url(self) -> None: """Test that config uses custom API base URL when provided.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", "HOSTAWAY_API_BASE_URL": "https://custom.api.com/v1", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() assert config.api_base_url == "https://custom.api.com/v1" def test_config_uses_default_rate_limits(self) -> None: """Test that config uses default rate limit values.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() assert config.rate_limit_ip == 15 assert config.rate_limit_account == 20 assert config.max_concurrent_requests == 10 assert config.token_refresh_threshold_days == 7 def test_config_uses_custom_rate_limits(self) -> None: """Test that config uses custom rate limit values when provided.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", "RATE_LIMIT_IP": "10", "RATE_LIMIT_ACCOUNT": "15", "MAX_CONCURRENT_REQUESTS": "20", "TOKEN_REFRESH_THRESHOLD_DAYS": "14", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() assert config.rate_limit_ip == 10 assert config.rate_limit_account == 15 assert config.max_concurrent_requests == 20 assert config.token_refresh_threshold_days == 14 @pytest.mark.skip(reason="pydantic-settings reads from .env file, making this test unreliable") def test_config_fails_without_account_id(self) -> None: """Test that config fails when HOSTAWAY_ACCOUNT_ID is missing.""" env_vars = { "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", } with patch.dict(os.environ, env_vars, clear=True): with pytest.raises(ValidationError) as exc_info: HostawayConfig() assert "HOSTAWAY_ACCOUNT_ID" in str(exc_info.value) @pytest.mark.skip(reason="pydantic-settings reads from .env file, making this test unreliable") def test_config_fails_without_secret_key(self) -> None: """Test that config fails when HOSTAWAY_SECRET_KEY is missing.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", } with patch.dict(os.environ, env_vars, clear=True): with pytest.raises(ValidationError) as exc_info: HostawayConfig() assert "HOSTAWAY_SECRET_KEY" in str(exc_info.value) def test_config_validates_rate_limit_ip_range(self) -> None: """Test that rate_limit_ip must be between 1 and 15.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", "RATE_LIMIT_IP": "20", } with patch.dict(os.environ, env_vars, clear=True): with pytest.raises(ValidationError) as exc_info: HostawayConfig() assert "RATE_LIMIT_IP" in str(exc_info.value) or "rate_limit_ip" in str( exc_info.value ) def test_config_validates_rate_limit_account_range(self) -> None: """Test that rate_limit_account must be between 1 and 20.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", "RATE_LIMIT_ACCOUNT": "25", } with patch.dict(os.environ, env_vars, clear=True): with pytest.raises(ValidationError) as exc_info: HostawayConfig() assert "RATE_LIMIT_ACCOUNT" in str(exc_info.value) or "rate_limit_account" in str( exc_info.value ) def test_config_validates_max_concurrent_requests_range(self) -> None: """Test that max_concurrent_requests must be between 1 and 50.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", "MAX_CONCURRENT_REQUESTS": "100", } with patch.dict(os.environ, env_vars, clear=True): with pytest.raises(ValidationError) as exc_info: HostawayConfig() assert ( "MAX_CONCURRENT_REQUESTS" in str(exc_info.value) or "max_concurrent_requests" in str(exc_info.value) ) def test_config_secret_key_is_protected(self) -> None: """Test that secret_key is a SecretStr and doesn't leak in repr.""" env_vars = { "HOSTAWAY_ACCOUNT_ID": "test_account_123", "HOSTAWAY_SECRET_KEY": "test_secret_key_abc", } with patch.dict(os.environ, env_vars, clear=True): config = HostawayConfig() # Secret should not appear in string representation config_str = str(config) assert "test_secret_key_abc" not in config_str assert "**********" in config_str or "SecretStr" in config_str # But should be accessible via get_secret_value() assert config.secret_key.get_secret_value() == "test_secret_key_abc"

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/darrentmorgan/hostaway-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server