|
18 | 18 | class TestDatabaseSettings: |
19 | 19 | """Tests for DatabaseSettings.""" |
20 | 20 |
|
21 | | - def test_default_values(self) -> None: |
| 21 | + def test_default_values(self, monkeypatch: pytest.MonkeyPatch) -> None: |
22 | 22 | """Test default database settings.""" |
| 23 | + # Clear any env vars that might interfere |
| 24 | + monkeypatch.delenv("DATABASE_URL", raising=False) |
23 | 25 | settings = DatabaseSettings() |
24 | 26 | assert settings.url == "sqlite:///./data/text2sql.db" |
25 | 27 | assert settings.pool_size == 5 |
26 | 28 | assert settings.max_overflow == 10 |
27 | 29 | assert settings.pool_timeout == 30 |
28 | 30 |
|
29 | | - def test_valid_postgresql_url(self) -> None: |
| 31 | + def test_valid_postgresql_url(self, monkeypatch: pytest.MonkeyPatch) -> None: |
30 | 32 | """Test valid PostgreSQL URL.""" |
31 | | - settings = DatabaseSettings(url="postgresql://user:pass@localhost/db") |
| 33 | + monkeypatch.setenv("DATABASE_URL", "postgresql://user:pass@localhost/db") |
| 34 | + settings = DatabaseSettings() |
32 | 35 | assert settings.url.startswith("postgresql://") |
33 | 36 |
|
34 | | - def test_valid_mysql_url(self) -> None: |
| 37 | + def test_valid_mysql_url(self, monkeypatch: pytest.MonkeyPatch) -> None: |
35 | 38 | """Test valid MySQL URL.""" |
36 | | - settings = DatabaseSettings(url="mysql://user:pass@localhost/db") |
| 39 | + monkeypatch.setenv("DATABASE_URL", "mysql://user:pass@localhost/db") |
| 40 | + settings = DatabaseSettings() |
37 | 41 | assert settings.url.startswith("mysql://") |
38 | 42 |
|
39 | | - def test_valid_sqlite_url(self) -> None: |
| 43 | + def test_valid_sqlite_url(self, monkeypatch: pytest.MonkeyPatch) -> None: |
40 | 44 | """Test valid SQLite URL.""" |
41 | | - settings = DatabaseSettings(url="sqlite:///./test.db") |
| 45 | + monkeypatch.setenv("DATABASE_URL", "sqlite:///./test.db") |
| 46 | + settings = DatabaseSettings() |
42 | 47 | assert settings.url.startswith("sqlite:///") |
43 | 48 |
|
44 | | - def test_invalid_url_raises_error(self) -> None: |
| 49 | + def test_invalid_url_raises_error(self, monkeypatch: pytest.MonkeyPatch) -> None: |
45 | 50 | """Test that invalid URL raises ValidationError.""" |
| 51 | + monkeypatch.setenv("DATABASE_URL", "invalid://url") |
46 | 52 | with pytest.raises(ValidationError): |
47 | | - DatabaseSettings(url="invalid://url") |
| 53 | + DatabaseSettings() |
48 | 54 |
|
49 | 55 |
|
50 | 56 | class TestAgentSettings: |
@@ -87,21 +93,29 @@ def test_min_confidence_bounds(self) -> None: |
87 | 93 | class TestAPISettings: |
88 | 94 | """Tests for APISettings.""" |
89 | 95 |
|
90 | | - def test_cors_origins_list(self) -> None: |
| 96 | + def test_cors_origins_list(self, monkeypatch: pytest.MonkeyPatch) -> None: |
91 | 97 | """Test CORS origins parsing.""" |
92 | | - settings = APISettings(cors_origins="http://a.com, http://b.com") |
| 98 | + monkeypatch.setenv("API_CORS_ORIGINS", "http://a.com, http://b.com") |
| 99 | + settings = APISettings() |
93 | 100 | assert settings.cors_origins_list == ["http://a.com", "http://b.com"] |
94 | 101 |
|
95 | | - def test_port_bounds(self) -> None: |
| 102 | + def test_port_bounds(self, monkeypatch: pytest.MonkeyPatch) -> None: |
96 | 103 | """Test port boundary validation.""" |
97 | | - APISettings(port=1) |
98 | | - APISettings(port=65535) |
| 104 | + # Valid values |
| 105 | + monkeypatch.setenv("API_PORT", "1") |
| 106 | + APISettings() |
| 107 | + monkeypatch.setenv("API_PORT", "65535") |
| 108 | + APISettings() |
99 | 109 |
|
| 110 | + # Invalid values - port 0 |
| 111 | + monkeypatch.setenv("API_PORT", "0") |
100 | 112 | with pytest.raises(ValidationError): |
101 | | - APISettings(port=0) |
| 113 | + APISettings() |
102 | 114 |
|
| 115 | + # Invalid values - port 65536 |
| 116 | + monkeypatch.setenv("API_PORT", "65536") |
103 | 117 | with pytest.raises(ValidationError): |
104 | | - APISettings(port=65536) |
| 118 | + APISettings() |
105 | 119 |
|
106 | 120 |
|
107 | 121 | class TestGetSettings: |
|
0 commit comments